@@ -27,22 +27,48 @@ func Assert(t *testing.T, id string, a Assertable) {
2727
2828// AssertHTTPResponse asserts the value of an http.Response.
2929func AssertHTTPResponse (t * testing.T , id string , w * http.Response ) {
30- config , err := getConfig ( )
30+ body , err := httputil . DumpResponse ( w , true )
3131 if err != nil {
3232 t .Fatal (err )
3333 }
3434
35- body , err := httputil .DumpResponse (w , true )
35+ assertHTTP (t , id , body , contentTypeIsJSON (w .Header .Get ("Content-Type" )))
36+ }
37+
38+ // AssertHTTPRequestOut asserts the value of an http.Request.
39+ // Intended for use when testing outgoing client requests
40+ // See https://golang.org/pkg/net/http/httputil/#DumpRequestOut for more
41+ func AssertHTTPRequestOut (t * testing.T , id string , r * http.Request ) {
42+ body , err := httputil .DumpRequestOut (r , true )
3643 if err != nil {
3744 t .Fatal (err )
3845 }
3946
40- data := string (body )
47+ assertHTTP (t , id , body , contentTypeIsJSON (r .Header .Get ("Content-Type" )))
48+ }
4149
42- contentType := w .Header .Get ("Content-Type" )
50+ // AssertHTTPRequest asserts the value of an http.Request.
51+ // Intended for use when testing incoming client requests
52+ // See https://golang.org/pkg/net/http/httputil/#DumpRequest for more
53+ func AssertHTTPRequest (t * testing.T , id string , r * http.Request ) {
54+ body , err := httputil .DumpRequest (r , true )
55+ if err != nil {
56+ t .Fatal (err )
57+ }
58+
59+ assertHTTP (t , id , body , contentTypeIsJSON (r .Header .Get ("Content-Type" )))
60+ }
61+
62+ func assertHTTP (t * testing.T , id string , body []byte , isJSON bool ) {
63+ config , err := getConfig ()
64+ if err != nil {
65+ t .Fatal (err )
66+ }
67+
68+ data := string (body )
4369
4470 // If the response body is JSON, indent.
45- if contentTypeIsJSON ( contentType ) {
71+ if isJSON {
4672 lines := strings .Split (strings .TrimSpace (data ), "\n " )
4773 jsonStr := lines [len (lines )- 1 ]
4874
0 commit comments