@@ -41,9 +41,13 @@ func TestHTTPSuccess(t *testing.T) {
41
41
assert .Equal (HTTPSuccess (mockT2 , httpRedirect , "GET" , "/" , nil ), false )
42
42
assert .True (mockT2 .Failed ())
43
43
44
- mockT3 := new (testing.T )
45
- assert .Equal (HTTPSuccess (mockT3 , httpError , "GET" , "/" , nil ), false )
44
+ mockT3 := new (mockTestingT )
45
+ assert .Equal (HTTPSuccess (
46
+ mockT3 , httpError , "GET" , "/" , nil ,
47
+ "was not expecting a failure here" ,
48
+ ), false )
46
49
assert .True (mockT3 .Failed ())
50
+ assert .Contains (mockT3 .errorString (), "was not expecting a failure here" )
47
51
48
52
mockT4 := new (testing.T )
49
53
assert .Equal (HTTPSuccess (mockT4 , httpStatusCode , "GET" , "/" , nil ), false )
@@ -57,9 +61,13 @@ func TestHTTPSuccess(t *testing.T) {
57
61
func TestHTTPRedirect (t * testing.T ) {
58
62
assert := New (t )
59
63
60
- mockT1 := new (testing.T )
61
- assert .Equal (HTTPRedirect (mockT1 , httpOK , "GET" , "/" , nil ), false )
64
+ mockT1 := new (mockTestingT )
65
+ assert .Equal (HTTPRedirect (
66
+ mockT1 , httpOK , "GET" , "/" , nil ,
67
+ "was expecting a 3xx status code. Got 200." ,
68
+ ), false )
62
69
assert .True (mockT1 .Failed ())
70
+ assert .Contains (mockT1 .errorString (), "was expecting a 3xx status code. Got 200." )
63
71
64
72
mockT2 := new (testing.T )
65
73
assert .Equal (HTTPRedirect (mockT2 , httpRedirect , "GET" , "/" , nil ), true )
@@ -81,9 +89,13 @@ func TestHTTPError(t *testing.T) {
81
89
assert .Equal (HTTPError (mockT1 , httpOK , "GET" , "/" , nil ), false )
82
90
assert .True (mockT1 .Failed ())
83
91
84
- mockT2 := new (testing.T )
85
- assert .Equal (HTTPError (mockT2 , httpRedirect , "GET" , "/" , nil ), false )
92
+ mockT2 := new (mockTestingT )
93
+ assert .Equal (HTTPError (
94
+ mockT2 , httpRedirect , "GET" , "/" , nil ,
95
+ "Expected this request to error out. But it didn't" ,
96
+ ), false )
86
97
assert .True (mockT2 .Failed ())
98
+ assert .Contains (mockT2 .errorString (), "Expected this request to error out. But it didn't" )
87
99
88
100
mockT3 := new (testing.T )
89
101
assert .Equal (HTTPError (mockT3 , httpError , "GET" , "/" , nil ), true )
@@ -105,9 +117,13 @@ func TestHTTPStatusCode(t *testing.T) {
105
117
assert .Equal (HTTPStatusCode (mockT2 , httpRedirect , "GET" , "/" , nil , http .StatusSwitchingProtocols ), false )
106
118
assert .True (mockT2 .Failed ())
107
119
108
- mockT3 := new (testing.T )
109
- assert .Equal (HTTPStatusCode (mockT3 , httpError , "GET" , "/" , nil , http .StatusSwitchingProtocols ), false )
120
+ mockT3 := new (mockTestingT )
121
+ assert .Equal (HTTPStatusCode (
122
+ mockT3 , httpError , "GET" , "/" , nil , http .StatusSwitchingProtocols ,
123
+ "Expected the status code to be %d" , http .StatusSwitchingProtocols ,
124
+ ), false )
110
125
assert .True (mockT3 .Failed ())
126
+ assert .Contains (mockT3 .errorString (), "Expected the status code to be 101" )
111
127
112
128
mockT4 := new (testing.T )
113
129
assert .Equal (HTTPStatusCode (mockT4 , httpStatusCode , "GET" , "/" , nil , http .StatusSwitchingProtocols ), true )
@@ -167,15 +183,19 @@ func TestHTTPRequestWithParams(t *testing.T) {
167
183
168
184
func TestHttpBody (t * testing.T ) {
169
185
assert := New (t )
170
- mockT := new (testing. T )
186
+ mockT := new (mockTestingT )
171
187
172
188
assert .True (HTTPBodyContains (mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "Hello, World!" ))
173
189
assert .True (HTTPBodyContains (mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "World" ))
174
190
assert .False (HTTPBodyContains (mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "world" ))
175
191
176
192
assert .False (HTTPBodyNotContains (mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "Hello, World!" ))
177
- assert .False (HTTPBodyNotContains (mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "World" ))
193
+ assert .False (HTTPBodyNotContains (
194
+ mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "World" ,
195
+ "Expected the request body to not contain 'World'. But it did." ,
196
+ ))
178
197
assert .True (HTTPBodyNotContains (mockT , httpHelloName , "GET" , "/" , url.Values {"name" : []string {"World" }}, "world" ))
198
+ assert .Contains (mockT .errorString (), "Expected the request body to not contain 'World'. But it did." )
179
199
180
200
assert .True (HTTPBodyContains (mockT , httpReadBody , "GET" , "/" , nil , "hello" ))
181
201
}
0 commit comments