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:
parent
93f084598e
commit
ee0aa18616
3 changed files with 332 additions and 349 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue