Ignore order of metadata in tests

This commit is contained in:
Marius 2015-11-26 16:25:34 +01:00
parent 3812aa7ca2
commit 9a943a4896
2 changed files with 14 additions and 6 deletions

View File

@ -44,7 +44,7 @@ type httpTest struct {
ResHeader map[string]string ResHeader map[string]string
} }
func (test *httpTest) Run(handler http.Handler, t *testing.T) { func (test *httpTest) Run(handler http.Handler, t *testing.T) *httptest.ResponseRecorder {
t.Log(test.Name) t.Log(test.Name)
req, _ := http.NewRequest(test.Method, test.URL, test.ReqBody) req, _ := http.NewRequest(test.Method, test.URL, test.ReqBody)
@ -77,6 +77,8 @@ func (test *httpTest) Run(handler http.Handler, t *testing.T) {
if test.ResBody != "" && string(w.Body.Bytes()) != test.ResBody { if test.ResBody != "" && string(w.Body.Bytes()) != test.ResBody {
t.Errorf("Expected '%s' as body (got '%s'", test.ResBody, string(w.Body.Bytes())) t.Errorf("Expected '%s' as body (got '%s'", test.ResBody, string(w.Body.Bytes()))
} }
return w
} }
type methodOverrideStore struct { type methodOverrideStore struct {

View File

@ -31,7 +31,7 @@ func TestHead(t *testing.T) {
DataStore: headStore{}, DataStore: headStore{},
}) })
(&httpTest{ res := (&httpTest{
Name: "Successful request", Name: "Successful request",
Method: "HEAD", Method: "HEAD",
URL: "yes", URL: "yes",
@ -40,13 +40,19 @@ func TestHead(t *testing.T) {
}, },
Code: http.StatusNoContent, Code: http.StatusNoContent,
ResHeader: map[string]string{ ResHeader: map[string]string{
"Upload-Offset": "11", "Upload-Offset": "11",
"Upload-Length": "44", "Upload-Length": "44",
"Upload-Metadata": "name bHVucmpzLnBuZw==,type aW1hZ2UvcG5n", "Cache-Control": "no-store",
"Cache-Control": "no-store",
}, },
}).Run(handler, t) }).Run(handler, t)
// Since the order of a map is not guaranteed in Go, we need to be prepared
// for the case, that the order of the metadata may have been changed
if v := res.Header().Get("Upload-Metadata"); v != "name bHVucmpzLnBuZw==,type aW1hZ2UvcG5n" &&
v != "type aW1hZ2UvcG5n,name bHVucmpzLnBuZw==" {
t.Errorf("Expected valid metadata (got '%s')", v)
}
(&httpTest{ (&httpTest{
Name: "Non-existing file", Name: "Non-existing file",
Method: "HEAD", Method: "HEAD",