@@ -2,6 +2,7 @@ package assert
2
2
3
3
import (
4
4
"fmt"
5
+ "io"
5
6
"net/http"
6
7
"net/url"
7
8
"testing"
@@ -11,6 +12,12 @@ func httpOK(w http.ResponseWriter, r *http.Request) {
11
12
w .WriteHeader (http .StatusOK )
12
13
}
13
14
15
+ func httpReadBody (w http.ResponseWriter , r * http.Request ) {
16
+ _ , _ = io .Copy (io .Discard , r .Body )
17
+ w .WriteHeader (http .StatusOK )
18
+ _ , _ = w .Write ([]byte ("hello" ))
19
+ }
20
+
14
21
func httpRedirect (w http.ResponseWriter , r * http.Request ) {
15
22
w .WriteHeader (http .StatusTemporaryRedirect )
16
23
}
@@ -41,6 +48,10 @@ func TestHTTPSuccess(t *testing.T) {
41
48
mockT4 := new (testing.T )
42
49
assert .Equal (HTTPSuccess (mockT4 , httpStatusCode , "GET" , "/" , nil ), false )
43
50
assert .True (mockT4 .Failed ())
51
+
52
+ mockT5 := new (testing.T )
53
+ assert .Equal (HTTPSuccess (mockT5 , httpReadBody , "POST" , "/" , nil ), true )
54
+ assert .False (mockT5 .Failed ())
44
55
}
45
56
46
57
func TestHTTPRedirect (t * testing.T ) {
@@ -122,7 +133,7 @@ func TestHTTPStatusesWrapper(t *testing.T) {
122
133
123
134
func httpHelloName (w http.ResponseWriter , r * http.Request ) {
124
135
name := r .FormValue ("name" )
125
- _ , _ = w . Write ([] byte ( fmt .Sprintf ( "Hello, %s!" , name )) )
136
+ _ , _ = fmt .Fprintf ( w , "Hello, %s!" , name )
126
137
}
127
138
128
139
func TestHTTPRequestWithNoParams (t * testing.T ) {
@@ -165,6 +176,8 @@ func TestHttpBody(t *testing.T) {
165
176
assert .False (HTTPBodyNotContains (mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "Hello, World!" ))
166
177
assert .False (HTTPBodyNotContains (mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "World" ))
167
178
assert .True (HTTPBodyNotContains (mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "world" ))
179
+
180
+ assert .True (HTTPBodyContains (mockT , httpReadBody , "GET" , "/" , nil , "hello" ))
168
181
}
169
182
170
183
func TestHttpBodyWrappers (t * testing.T ) {
@@ -178,5 +191,4 @@ func TestHttpBodyWrappers(t *testing.T) {
178
191
assert .False (mockAssert .HTTPBodyNotContains (httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "Hello, World!" ))
179
192
assert .False (mockAssert .HTTPBodyNotContains (httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "World" ))
180
193
assert .True (mockAssert .HTTPBodyNotContains (httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "world" ))
181
-
182
194
}
0 commit comments