refactor(httpx): use mocks to implement tests (#650)

* refactor(httpx): use mocks to implement tests

While there, make sure no test depends on external services by
replacing such tests with httptest.

See https://github.com/ooni/probe/issues/1951.

* fix(httpx): ensure we honour the context
This commit is contained in:
Simone Basso 2022-01-05 16:13:42 +01:00 committed by GitHub
commit ee0aa18616
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 332 additions and 349 deletions

View file

@ -137,7 +137,7 @@ func (c *apiClient) newRequest(ctx context.Context, method, resourcePath string,
if query != nil {
URL.RawQuery = query.Encode()
}
request, err := http.NewRequest(method, URL.String(), body)
request, err := http.NewRequestWithContext(ctx, method, URL.String(), body)
if err != nil {
return nil, err
}
@ -149,7 +149,7 @@ func (c *apiClient) newRequest(ctx context.Context, method, resourcePath string,
request.Header.Set("Accept", c.Accept)
}
request.Header.Set("User-Agent", c.UserAgent)
return request.WithContext(ctx), nil
return request, nil
}
// ErrRequestFailed indicates that the server returned >= 400.