Skip to content

Commit

Permalink
Compare body with gzipStrLevel in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmthrgd committed Dec 2, 2017
1 parent ab90073 commit 2284786
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gzip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestGzipHandlerContentLength(t *testing.T) {
handler := Gzip(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Length", strconv.Itoa(len(b)))
w.Write(b)
}))
}), CompressionLevel(DefaultCompression))

srv := httptest.NewServer(handler)
defer srv.Close()
Expand All @@ -150,7 +150,7 @@ func TestGzipHandlerContentLength(t *testing.T) {
require.NoError(t, err, "Unexpected error parsing Content-Length")
assert.Len(t, body, l)
assert.Equal(t, "gzip", res.Header.Get("Content-Encoding"))
assert.NotEqual(t, b, body)
assert.Equal(t, gzipStrLevel(testBody, DefaultCompression), body)
}

func TestGzipHandlerMinSize(t *testing.T) {
Expand Down Expand Up @@ -247,7 +247,8 @@ func TestFlushBeforeWrite(t *testing.T) {
rw.WriteHeader(http.StatusNotFound)
rw.(http.Flusher).Flush()
rw.Write(b)
}))
}), CompressionLevel(DefaultCompression))

r := httptest.NewRequest(http.MethodGet, "/", nil)
r.Header.Set("Accept-Encoding", "gzip")
w := httptest.NewRecorder()
Expand All @@ -256,7 +257,7 @@ func TestFlushBeforeWrite(t *testing.T) {
res := w.Result()
assert.Equal(t, http.StatusNotFound, res.StatusCode)
assert.Equal(t, "gzip", res.Header.Get("Content-Encoding"))
assert.NotEqual(t, b, w.Body.Bytes())
assert.Equal(t, gzipStrLevel(testBody, DefaultCompression), w.Body.Bytes())
}

func TestInferContentType(t *testing.T) {
Expand Down

0 comments on commit 2284786

Please sign in to comment.