@@ -96,9 +96,9 @@ func TestMockResponderWithFilters(t *testing.T) {
9696 return r .URL .Query ().Get ("id" ) == "2"
9797 })
9898
99- assertGetResults (t , mock .URL ()+ "/test?id=1" , "user 1" , http .StatusOK )
100- assertGetResults (t , mock .URL ()+ "/test?id=3" , "user not found" , http .StatusNotFound )
101- assertGetResults (t , mock .URL ()+ "/test?id=2" , "user 2" , http .StatusOK )
99+ assertBodyAndStatus (t , mock .URL ()+ "/test?id=1" , "user 1" , http .StatusOK )
100+ assertBodyAndStatus (t , mock .URL ()+ "/test?id=3" , "user not found" , http .StatusNotFound )
101+ assertBodyAndStatus (t , mock .URL ()+ "/test?id=2" , "user 2" , http .StatusOK )
102102 mock .AssertCallCount (t , http .MethodGet , "/test" , 3 )
103103 mock .AssertCallCountAsserted (t )
104104}
@@ -127,9 +127,9 @@ func TestMockResponderWithFiltersAsserts(t *testing.T) {
127127 w .Write ([]byte ("user not found" ))
128128 })
129129
130- assertGetResults (t , mock .URL ()+ "/test?id=1" , "user 1" , http .StatusOK )
131- assertGetResults (t , mock .URL ()+ "/test?id=3" , "user not found" , http .StatusNotFound )
132- assertGetResults (t , mock .URL ()+ "/test?id=2" , "user 2" , http .StatusOK )
130+ assertBodyAndStatus (t , mock .URL ()+ "/test?id=1" , "user 1" , http .StatusOK )
131+ assertBodyAndStatus (t , mock .URL ()+ "/test?id=3" , "user not found" , http .StatusNotFound )
132+ assertBodyAndStatus (t , mock .URL ()+ "/test?id=2" , "user 2" , http .StatusOK )
133133 mr1 .AssertCallCount (t , 1 )
134134 mr2 .AssertCallCount (t , 1 )
135135 mr3 .AssertCallCount (t , 1 )
@@ -143,9 +143,9 @@ func TestAllMocksLimits(t *testing.T) {
143143 mock .Mock ("/test" , "once" ).Once ()
144144 mock .Mock ("/test" , "times" ).Times (2 )
145145
146- assertGetResults (t , mock .URL ()+ "/test" , "once" , http .StatusOK )
147- assertGetResults (t , mock .URL ()+ "/test" , "times" , http .StatusOK )
148- assertGetResults (t , mock .URL ()+ "/test" , "times" , http .StatusOK )
146+ assertBodyAndStatus (t , mock .URL ()+ "/test" , "once" , http .StatusOK )
147+ assertBodyAndStatus (t , mock .URL ()+ "/test" , "times" , http .StatusOK )
148+ assertBodyAndStatus (t , mock .URL ()+ "/test" , "times" , http .StatusOK )
149149 mock .AssertCallCount (t , "GET" , "/test" , 3 )
150150 mock .AssertCallCountAsserted (t )
151151 mock .AssertNoMissingMocks (t )
@@ -192,18 +192,14 @@ func TestNotAssertNoMissingMocks(t *testing.T) {
192192 assert .True (t , newT .Failed ())
193193}
194194
195- func assertGetResults (t * testing.T , path , expBody string , expStatus int ) bool {
195+ func assertBodyAndStatus (t * testing.T , path , expBody string , expStatus int ) bool {
196196 resp , err := http .Get (path )
197197 assert .NoError (t , err )
198- if ! assert .Equal (t , expStatus , resp .StatusCode ) {
199- return assert .Fail (t , "Expected status %s but got %s" , expStatus , resp .StatusCode )
200- }
198+ assert .Equal (t , expStatus , resp .StatusCode , "Expected status %d but got %d" , expStatus , resp .StatusCode )
201199
202200 body , err := io .ReadAll (resp .Body )
203201 assert .NoError (t , err )
204- if ! assert .Equal (t , expBody , string (body )) {
205- return assert .Fail (t , "Expected body %s but got %s" , expBody , string (body ))
206- }
202+ assert .Equal (t , expBody , string (body ), "Expected body %s but got %s" , expBody , string (body ))
207203
208204 return true
209205}
0 commit comments