File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,18 @@ func (efrt *EnforceHostRoundTripper) RoundTrip(r *http.Request) (*http.Response,
164164//
165165// c := github.NewClient(mockedHTTPClient)
166166func NewMockedHTTPClient (options ... MockBackendOption ) * http.Client {
167+ _ , c := NewMockedHTTPClientAndServer (options ... )
168+
169+ return c
170+ }
171+
172+ // Same as the original `NewMockedHTTPClient` but returns a pointer to the internal
173+ // `*httptest.Server`, which let's you close it, avoiding GoRoutine leaks on your tests.
174+ //
175+ // This avoids creating a breaking change, for now.
176+ //
177+ // To close the server, use: `mockServer.Close()`.
178+ func NewMockedHTTPClientAndServer (options ... MockBackendOption ) (* httptest.Server , * http.Client ) {
167179 router := mux .NewRouter ()
168180
169181 router .NotFoundHandler = http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -187,5 +199,5 @@ func NewMockedHTTPClient(options ...MockBackendOption) *http.Client {
187199 UpstreamRoundTripper : mockServer .Client ().Transport ,
188200 }
189201
190- return c
202+ return mockServer , c
191203}
You can’t perform that action at this time.
0 commit comments