Skip to content

Conversation

@tormath1
Copy link
Collaborator

In this PR, we remove the HTTPClient interface which was primary used for testing purposes. This comment: #1 (comment) made me discovered a better way to implement deeper mocking in the HTTP request.

By mocking transport, we can chain them (like with Basic Auth transport) and have a better control on the expected i/o of the round tripper.

Tests do not change a lot, we just mock the round tripper instead of the Do method .

this interface was used to fullfill testing purposes by mocking
`Do` method.

Test logic has been changed to mock the transport with mocked RoundTrip.

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
it allows a more granular precision to mock tests rather than directly
mocking the `Do` method.

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
@tormath1 tormath1 requested a review from invidian October 27, 2021 17:18
@tormath1 tormath1 self-assigned this Oct 27, 2021
},
} {
h := &httpClient{
h := http.DefaultClient
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DefaultClient is just &Client{}, so you can just initialize everything at one go as http.Client{Transport: ...}.

@tormath1 tormath1 closed this Oct 28, 2021
@tormath1 tormath1 deleted the tormath1/test-roundtripper branch October 28, 2021 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants