Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces switches to using the common interface
Doer
instead of the concrete*http.Client
to be more flexible for consumers test construction.Prior to this PR,
genqlient
has not supported one of the three common testing techniques by consumers. See Let the Doer Do it for more details.Generally, there are three common ways to test HTTP client requests:
http.Transport
Transport specifies the mechanism by which individual HTTP requests are made. Instead of using the default http.Transport, we’ll replace it with our own implementation. To implement a transport, we’ll have to implement http.RoundTripper interface.
httptest.Server
:httptest.Server
allows us to create a local HTTP server and listen for any requests. When starting, the server chooses any available open port and uses that. So we need to get the URL of the test server and use it instead of the actual service URL.*http.Client
The
Doer
is a single-method interface, as is often the case in Go:Note: It does not really exist - it is not defined anywhere in the stdlib - but it is trivial to summon it from thin air in a package. Many people do as I did above, and because Go implicitly satisfies interfaces, any type that implements this method will be a valid Doer.