New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http/cookiejar: adding example #16884
Comments
Related to #16360 |
I prefer version 1. However, it seems bad to rely on the exact set of cookies that google.com (or golang.org for that matter) sets. Perhaps you can do a bit of both worlds and have the test run a simple HTTP server that sets a cookie, and then connect and fetch it? All that said, please also submit the example in the form of a pull request. Thanks! |
Don't rely on external services for tests. Use httptest.Server and hit its URL using a normal transport, but to localhost. |
Thanks @bradfitz @quentinmit, I've the change ready, just fighting my gerrit setup ATM, somehow I'm getting |
@ceocoder, none of us can upload to Gerrit right now. We suspect they're having some sort of outage. |
@bradfitz ah, that makes more sense. I'll lay off button smashing for a while. |
CL https://golang.org/cl/27993 mentions this issue. |
I've prepared two versions of examples for
net/http/cookiejar
,Version 1 makes actual HTTP requests to www.google.com and https://golang.org/doc/tos.html and prints out cookies.
Pro: It keeps example code small
Con: One needs internet access for this test to pass, it takes
0.59s
on my MacBook Pro. Time that adds up over many test runs.Version 2 uses a dummy transport that writes
COOKIE!
cookie to response.Pro: Tests run very quickly, about
0.00s
on same machine.Con: Example adds additional code, which looks rather out of place in context of an example. I've not see any other example creating a separate transport.
Any suggestions on how to proceed?
The text was updated successfully, but these errors were encountered: