Commit c290616d authored by Ahmad Sherif's avatar Ahmad Sherif

Rename testhelper.{AssertResponseHeader => AssertResponseWriterHeader}

parent b4acd08e
...@@ -57,10 +57,10 @@ func TestDownloadingFromValidArchive(t *testing.T) { ...@@ -57,10 +57,10 @@ func TestDownloadingFromValidArchive(t *testing.T) {
testhelper.AssertResponseCode(t, response, 200) testhelper.AssertResponseCode(t, response, 200)
testhelper.AssertResponseHeader(t, response, testhelper.AssertResponseWriterHeader(t, response,
"Content-Type", "Content-Type",
"text/plain; charset=utf-8") "text/plain; charset=utf-8")
testhelper.AssertResponseHeader(t, response, testhelper.AssertResponseWriterHeader(t, response,
"Content-Disposition", "Content-Disposition",
"attachment; filename=\"test.txt\"") "attachment; filename=\"test.txt\"")
......
...@@ -63,9 +63,9 @@ func TestSetArchiveHeaders(t *testing.T) { ...@@ -63,9 +63,9 @@ func TestSetArchiveHeaders(t *testing.T) {
setArchiveHeaders(w, testCase.in, "filename") setArchiveHeaders(w, testCase.in, "filename")
testhelper.AssertResponseHeader(t, w, "Content-Type", testCase.out) testhelper.AssertResponseWriterHeader(t, w, "Content-Type", testCase.out)
testhelper.AssertResponseHeader(t, w, "Content-Length") testhelper.AssertResponseWriterHeader(t, w, "Content-Length")
testhelper.AssertResponseHeader(t, w, "Content-Disposition", `attachment; filename="filename"`) testhelper.AssertResponseWriterHeader(t, w, "Content-Disposition", `attachment; filename="filename"`)
testhelper.AssertResponseHeader(t, w, "Cache-Control", "private") testhelper.AssertResponseWriterHeader(t, w, "Cache-Control", "private")
} }
} }
...@@ -110,13 +110,13 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) { ...@@ -110,13 +110,13 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest) st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest)
testhelper.AssertResponseCode(t, w, 200) testhelper.AssertResponseCode(t, w, 200)
if enableGzip { if enableGzip {
testhelper.AssertResponseHeader(t, w, "Content-Encoding", "gzip") testhelper.AssertResponseWriterHeader(t, w, "Content-Encoding", "gzip")
if bytes.Compare(w.Body.Bytes(), fileGzipContent.Bytes()) != 0 { if bytes.Compare(w.Body.Bytes(), fileGzipContent.Bytes()) != 0 {
t.Error("We should serve the pregzipped file") t.Error("We should serve the pregzipped file")
} }
} else { } else {
testhelper.AssertResponseCode(t, w, 200) testhelper.AssertResponseCode(t, w, 200)
testhelper.AssertResponseHeader(t, w, "Content-Encoding") testhelper.AssertResponseWriterHeader(t, w, "Content-Encoding")
if w.Body.String() != fileContent { if w.Body.String() != fileContent {
t.Error("We should serve the file: ", w.Body.String()) t.Error("We should serve the file: ", w.Body.String())
} }
......
...@@ -71,9 +71,19 @@ func AssertResponseBodyRegexp(t *testing.T, response *httptest.ResponseRecorder, ...@@ -71,9 +71,19 @@ func AssertResponseBodyRegexp(t *testing.T, response *httptest.ResponseRecorder,
} }
} }
func AssertResponseHeader(t *testing.T, w http.ResponseWriter, header string, expected ...string) { func AssertResponseWriterHeader(t *testing.T, w http.ResponseWriter, header string, expected ...string) {
actual := w.Header()[http.CanonicalHeaderKey(header)] actual := w.Header()[http.CanonicalHeaderKey(header)]
assertHeaderExists(t, header, actual, expected)
}
func AssertResponseHeader(t *testing.T, w *http.Response, header string, expected ...string) {
actual := w.Header[http.CanonicalHeaderKey(header)]
assertHeaderExists(t, header, actual, expected)
}
func assertHeaderExists(t *testing.T, header string, actual, expected []string) {
if len(expected) != len(actual) { if len(expected) != len(actual) {
t.Fatalf("for HTTP request expected to receive the header %q with %+v, got %+v", header, expected, actual) t.Fatalf("for HTTP request expected to receive the header %q with %+v, got %+v", header, expected, actual)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment