|
|
@ -368,3 +368,134 @@ func TestHeaderREMatcher(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestResponseMatcher(t *testing.T) { |
|
|
|
for i, tc := range []struct { |
|
|
|
require ResponseMatcher |
|
|
|
status int |
|
|
|
hdr http.Header // make sure these are canonical cased (std lib will do that in a real request)
|
|
|
|
expect bool |
|
|
|
}{ |
|
|
|
{ |
|
|
|
require: ResponseMatcher{}, |
|
|
|
status: 200, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
StatusCode: []int{200}, |
|
|
|
}, |
|
|
|
status: 200, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
StatusCode: []int{2}, |
|
|
|
}, |
|
|
|
status: 200, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
StatusCode: []int{201}, |
|
|
|
}, |
|
|
|
status: 200, |
|
|
|
expect: false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
StatusCode: []int{2}, |
|
|
|
}, |
|
|
|
status: 301, |
|
|
|
expect: false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
StatusCode: []int{3}, |
|
|
|
}, |
|
|
|
status: 301, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
StatusCode: []int{3}, |
|
|
|
}, |
|
|
|
status: 399, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
StatusCode: []int{3}, |
|
|
|
}, |
|
|
|
status: 400, |
|
|
|
expect: false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
StatusCode: []int{3, 4}, |
|
|
|
}, |
|
|
|
status: 400, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
StatusCode: []int{3, 401}, |
|
|
|
}, |
|
|
|
status: 401, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
Headers: http.Header{ |
|
|
|
"Foo": []string{"bar"}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
hdr: http.Header{"Foo": []string{"bar"}}, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
Headers: http.Header{ |
|
|
|
"Foo2": []string{"bar"}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
hdr: http.Header{"Foo": []string{"bar"}}, |
|
|
|
expect: false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
Headers: http.Header{ |
|
|
|
"Foo": []string{"bar", "baz"}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
hdr: http.Header{"Foo": []string{"baz"}}, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
Headers: http.Header{ |
|
|
|
"Foo": []string{"bar"}, |
|
|
|
"Foo2": []string{"baz"}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
hdr: http.Header{"Foo": []string{"baz"}}, |
|
|
|
expect: false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
require: ResponseMatcher{ |
|
|
|
Headers: http.Header{ |
|
|
|
"Foo": []string{"bar"}, |
|
|
|
"Foo2": []string{"baz"}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
hdr: http.Header{"Foo": []string{"bar"}, "Foo2": []string{"baz"}}, |
|
|
|
expect: true, |
|
|
|
}, |
|
|
|
} { |
|
|
|
actual := tc.require.Match(tc.status, tc.hdr) |
|
|
|
if actual != tc.expect { |
|
|
|
t.Errorf("Test %d %v: Expected %t, got %t for HTTP %d %v", i, tc.require, tc.expect, actual, tc.status, tc.hdr) |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|