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) {
testhelper.AssertResponseCode(t, response, 200)
testhelper.AssertResponseHeader(t, response,
testhelper.AssertResponseWriterHeader(t, response,
"Content-Type",
"text/plain; charset=utf-8")
testhelper.AssertResponseHeader(t, response,
testhelper.AssertResponseWriterHeader(t, response,
"Content-Disposition",
"attachment; filename=\"test.txt\"")
......
......@@ -63,9 +63,9 @@ func TestSetArchiveHeaders(t *testing.T) {
setArchiveHeaders(w, testCase.in, "filename")
testhelper.AssertResponseHeader(t, w, "Content-Type", testCase.out)
testhelper.AssertResponseHeader(t, w, "Content-Length")
testhelper.AssertResponseHeader(t, w, "Content-Disposition", `attachment; filename="filename"`)
testhelper.AssertResponseHeader(t, w, "Cache-Control", "private")
testhelper.AssertResponseWriterHeader(t, w, "Content-Type", testCase.out)
testhelper.AssertResponseWriterHeader(t, w, "Content-Length")
testhelper.AssertResponseWriterHeader(t, w, "Content-Disposition", `attachment; filename="filename"`)
testhelper.AssertResponseWriterHeader(t, w, "Cache-Control", "private")
}
}
......@@ -110,13 +110,13 @@ func testServingThePregzippedFile(t *testing.T, enableGzip bool) {
st.ServeExisting("/", CacheDisabled, nil).ServeHTTP(w, httpRequest)
testhelper.AssertResponseCode(t, w, 200)
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 {
t.Error("We should serve the pregzipped file")
}
} else {
testhelper.AssertResponseCode(t, w, 200)
testhelper.AssertResponseHeader(t, w, "Content-Encoding")
testhelper.AssertResponseWriterHeader(t, w, "Content-Encoding")
if w.Body.String() != fileContent {
t.Error("We should serve the file: ", w.Body.String())
}
......
......@@ -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)]
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) {
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