From 9a943a48965eb31724ed85e4da5c31fc0825964d Mon Sep 17 00:00:00 2001 From: Marius Date: Thu, 26 Nov 2015 16:25:34 +0100 Subject: [PATCH] Ignore order of metadata in tests --- handler_test.go | 4 +++- head_test.go | 16 +++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/handler_test.go b/handler_test.go index c1cb07b..6119b1b 100644 --- a/handler_test.go +++ b/handler_test.go @@ -44,7 +44,7 @@ type httpTest struct { 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) 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 { t.Errorf("Expected '%s' as body (got '%s'", test.ResBody, string(w.Body.Bytes())) } + + return w } type methodOverrideStore struct { diff --git a/head_test.go b/head_test.go index 53cce69..b3d9026 100644 --- a/head_test.go +++ b/head_test.go @@ -31,7 +31,7 @@ func TestHead(t *testing.T) { DataStore: headStore{}, }) - (&httpTest{ + res := (&httpTest{ Name: "Successful request", Method: "HEAD", URL: "yes", @@ -40,13 +40,19 @@ func TestHead(t *testing.T) { }, Code: http.StatusNoContent, ResHeader: map[string]string{ - "Upload-Offset": "11", - "Upload-Length": "44", - "Upload-Metadata": "name bHVucmpzLnBuZw==,type aW1hZ2UvcG5n", - "Cache-Control": "no-store", + "Upload-Offset": "11", + "Upload-Length": "44", + "Cache-Control": "no-store", }, }).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{ Name: "Non-existing file", Method: "HEAD",