Use actual header values as expectations in CORS test

This commit is contained in:
Marius 2016-09-29 21:18:12 +02:00
parent 4df66415d6
commit d6ccb0fbb8
2 changed files with 5 additions and 9 deletions

View File

@ -22,9 +22,9 @@ func TestCORS(t *testing.T) {
}, },
Code: http.StatusOK, Code: http.StatusOK,
ResHeader: map[string]string{ ResHeader: map[string]string{
"Access-Control-Allow-Headers": "", "Access-Control-Allow-Headers": "Origin, X-Requested-With, Content-Type, Upload-Length, Upload-Offset, Tus-Resumable, Upload-Metadata",
"Access-Control-Allow-Methods": "", "Access-Control-Allow-Methods": "POST, GET, HEAD, PATCH, DELETE, OPTIONS",
"Access-Control-Max-Age": "", "Access-Control-Max-Age": "86400",
"Access-Control-Allow-Origin": "tus.io", "Access-Control-Allow-Origin": "tus.io",
}, },
}).Run(handler, t) }).Run(handler, t)
@ -37,7 +37,7 @@ func TestCORS(t *testing.T) {
}, },
Code: http.StatusMethodNotAllowed, Code: http.StatusMethodNotAllowed,
ResHeader: map[string]string{ ResHeader: map[string]string{
"Access-Control-Expose-Headers": "", "Access-Control-Expose-Headers": "Upload-Offset, Location, Upload-Length, Tus-Version, Tus-Resumable, Tus-Max-Size, Tus-Extension, Upload-Metadata",
"Access-Control-Allow-Origin": "tus.io", "Access-Control-Allow-Origin": "tus.io",
}, },
}).Run(handler, t) }).Run(handler, t)

View File

@ -61,11 +61,7 @@ func (test *httpTest) Run(handler http.Handler, t *testing.T) *httptest.Response
for key, value := range test.ResHeader { for key, value := range test.ResHeader {
header := w.HeaderMap.Get(key) header := w.HeaderMap.Get(key)
if value == "" && header == "" { if value != header {
t.Errorf("Expected '%s' in response", key)
}
if value != "" && value != header {
t.Errorf("Expected '%s' as '%s' (got '%s')", value, key, header) t.Errorf("Expected '%s' as '%s' (got '%s')", value, key, header)
} }
} }