@@ -46,7 +46,7 @@ func TestMockTransport(t *testing.T) {
4646 if err == nil {
4747 t .Fatal ("An error should occur" )
4848 }
49- if ! strings .Contains (err .Error (), NoResponderFound .Error ()) {
49+ if ! strings .HasSuffix (err .Error (), NoResponderFound .Error ()) {
5050 t .Fatal (err )
5151 }
5252
@@ -60,7 +60,7 @@ func TestMockTransport(t *testing.T) {
6060 if err == nil {
6161 t .Fatal ("An error should occur" )
6262 }
63- if ! strings .Contains (err .Error (),
63+ if ! strings .HasSuffix (err .Error (),
6464 NoResponderFound .Error ()+ " for method Get, but one matches method GET" ) {
6565 t .Fatal (err )
6666 }
@@ -74,7 +74,7 @@ func TestMockTransport(t *testing.T) {
7474 if err == nil {
7575 t .Fatal ("An error should occur" )
7676 }
77- if ! strings .Contains (err .Error (),
77+ if ! strings .HasSuffix (err .Error (),
7878 NoResponderFound .Error ()+ " for method POST, but one matches method GET" ) {
7979 t .Fatal (err )
8080 }
@@ -88,7 +88,7 @@ func TestMockTransport(t *testing.T) {
8888 if err == nil {
8989 t .Fatal ("An error should occur" )
9090 }
91- if ! strings .Contains (err .Error (),
91+ if ! strings .HasSuffix (err .Error (),
9292 NoResponderFound .Error ()+ " for method POST, but one matches method GET" ) {
9393 t .Fatal (err )
9494 }
@@ -182,8 +182,27 @@ func TestMockTransportNoResponder(t *testing.T) {
182182 if err != nil {
183183 t .Fatal ("expected request to succeed" )
184184 }
185-
186185 assertBody (t , resp , "hello world" )
186+
187+ // Using NewNotFoundResponder()
188+ RegisterNoResponder (NewNotFoundResponder (nil ))
189+ _ , err = http .Get (testURL )
190+ if err == nil {
191+ t .Fatal ("an error should occur" )
192+ }
193+ if ! strings .HasSuffix (err .Error (), "Responder not found for GET http://www.example.com/" ) {
194+ t .Fatalf ("Unexpected error content: %s" , err )
195+ }
196+
197+ // Help the user in case a Responder exists for another method
198+ RegisterResponder ("POST" , testURL , NewStringResponder (200 , "hello world" ))
199+ _ , err = http .Get (testURL )
200+ if err == nil {
201+ t .Fatal ("an error should occur" )
202+ }
203+ if ! strings .HasSuffix (err .Error (), "Responder not found for GET http://www.example.com/, but one matches method POST" ) {
204+ t .Fatalf ("Unexpected error content: %s" , err )
205+ }
187206}
188207
189208func TestMockTransportQuerystringFallback (t * testing.T ) {
0 commit comments