-
Notifications
You must be signed in to change notification settings - Fork 55
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
FIXIT: refactor http testing functions to builder pattern. Fixes #426 #440
Conversation
packager/testing/testing.go
Outdated
func GetHH(t *testing.T, handler http.Handler, target string, host string, headers http.Header) *http.Response { | ||
return GetBHH(t, handler, target, host, nil, headers) | ||
// NewBody sets body related information for the request. | ||
func (r *Request) NewBody(body io.Reader) *Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto; rename SetBody
or Body
or AddBody
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
packager/testing/testing.go
Outdated
func GetH(t *testing.T, handler http.Handler, target string, headers http.Header) *http.Response { | ||
return GetBHH(t, handler, target, "", nil, headers) | ||
// NewHeader sets header related information for the request. | ||
func (r *Request) NewHeader(host string, header http.Header) *Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename SetHeaders
or Headers
. New
makes me think it returns the headers. And plural because it is all the headers; not meant to be called incrementally for each one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
packager/signer/signer_test.go
Outdated
@@ -90,17 +90,17 @@ func (this *SignerSuite) new(urlSets []util.URLSet) http.Handler { | |||
} | |||
|
|||
func (this *SignerSuite) get(t *testing.T, handler http.Handler, target string) *http.Response { | |||
return pkgt.GetH(t, handler, target, http.Header{ | |||
"AMP-Cache-Transform": {"google"}, "Accept": {"application/signed-exchange;v=" + accept.AcceptedSxgVersion}}) | |||
header := http.Header{"AMP-Cache-Transform": {"google"}, "Accept": {"application/signed-exchange;v=" + accept.AcceptedSxgVersion}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to get rid of these three cryptic get functions, too? Just make this header value a top-level var inside signer_test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (whew!)
packager/testing/testing.go
Outdated
} | ||
|
||
func GetHH(t *testing.T, handler http.Handler, target string, host string, headers http.Header) *http.Response { | ||
return GetBHH(t, handler, target, host, nil, headers) | ||
// NewBody sets body related information for the request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"NewBody sets the body for the request. May be nil for an empty body."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
packager/testing/testing.go
Outdated
} | ||
|
||
func GetH(t *testing.T, handler http.Handler, target string, headers http.Header) *http.Response { | ||
return GetBHH(t, handler, target, "", nil, headers) | ||
// NewHeader sets header related information for the request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"NewHeader sets the headers for the request. Host may be empty for the default."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
packager/testing/testing.go
Outdated
} | ||
|
||
func GetBHH(t *testing.T, handler http.Handler, target string, host string, body io.Reader, headers http.Header) *http.Response { | ||
// Get returns the completed test request object. | ||
func (r *Request) Get() *http.Response { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this "Do", since it may do a post instead of a get.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
packager/testing/testing.go
Outdated
method = "POST" | ||
headers.Set("Content-Type", "application/x-www-form-urlencoded") | ||
r.NewHeader(r.Host, headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this'll overwrite any preexisting headers. e.g. if I call:
pkgt.NewRequest(t, handler, "/foo").
NewHeader("", {{"foo": "bar"}}).
NewBody(strings.NewReader("blah")).
Get()
It won't send the foo
header. I think you just want r.Header.Set(...)
in the line above, and then you can get rid of the local headers
variable and this NewHeader
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
088a564
to
d68fca4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
packager/signer/signer_test.go
Outdated
func (this *SignerSuite) getB(t *testing.T, handler http.Handler, target string, body string) *http.Response { | ||
return pkgt.GetBHH(t, handler, target, "", strings.NewReader(body), http.Header{ | ||
"AMP-Cache-Transform": {"google"}, "Accept": {"application/signed-exchange;v=" + accept.AcceptedSxgVersion}}) | ||
func (this *SignerSuite) getX(t *testing.T, handler http.Handler, target string) *http.Response { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I think you accidentally left this unused getX behind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, removed.
d68fca4
to
bc6283b
Compare
Refactor http testing functions