Skip to content
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

Closed
ceocoder opened this issue Aug 25, 2016 · 7 comments
Closed

net/http/cookiejar: adding example #16884

ceocoder opened this issue Aug 25, 2016 · 7 comments

Comments

@ceocoder
Copy link
Contributor

ceocoder commented Aug 25, 2016

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?

@ceocoder
Copy link
Contributor Author

Related to #16360

@quentinmit quentinmit added this to the Go1.8 milestone Aug 26, 2016
@quentinmit
Copy link
Contributor

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!

@bradfitz
Copy link
Contributor

Don't rely on external services for tests.

Use httptest.Server and hit its URL using a normal transport, but to localhost.

@ceocoder
Copy link
Contributor Author

Thanks @bradfitz @quentinmit, I've the change ready, just fighting my gerrit setup ATM, somehow I'm getting Invalid authentication credentials., despite having generated my password and ~/.gitcookies about 10 times.

@bradfitz
Copy link
Contributor

@ceocoder, none of us can upload to Gerrit right now. We suspect they're having some sort of outage.

@ceocoder
Copy link
Contributor Author

@bradfitz ah, that makes more sense. I'll lay off button smashing for a while.

@gopherbot
Copy link

CL https://golang.org/cl/27993 mentions this issue.

@golang golang locked and limited conversation to collaborators Sep 9, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants