diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2015-12-31 12:09:21 +0200 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2015-12-31 12:09:21 +0200 |
commit | 95456fa9d7097e92348c9aa58674a85d09208251 (patch) | |
tree | f844dc87711e033e88b67b4f29b108c0399646d2 /compress_test.go | |
parent | Do not read request body if both 'Content-Length' and 'Transfer-Encoding' hea... (diff) | |
download | fasthttp-95456fa9d7097e92348c9aa58674a85d09208251.tar.gz fasthttp-95456fa9d7097e92348c9aa58674a85d09208251.tar.bz2 fasthttp-95456fa9d7097e92348c9aa58674a85d09208251.zip |
Added AppendGzipBytes and AppendGunzipBytes for simplifying gzipping/gunzipping request/response bodies
Diffstat (limited to 'compress_test.go')
-rw-r--r-- | compress_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/compress_test.go b/compress_test.go index c42a408..6a61897 100644 --- a/compress_test.go +++ b/compress_test.go @@ -6,6 +6,32 @@ import ( "testing" ) +func TestGzipBytes(t *testing.T) { + testGzipBytes(t, "") + testGzipBytes(t, "foobar") + testGzipBytes(t, "выфаодлодл одлфываыв sd2 k34") +} + +func testGzipBytes(t *testing.T, s string) { + prefix := []byte("foobar") + gzippedS := AppendGzipBytes(prefix, []byte(s)) + if !bytes.Equal(gzippedS[:len(prefix)], prefix) { + t.Fatalf("unexpected prefix when compressing %q: %q. Expecting %q", s, gzippedS[:len(prefix)], prefix) + } + + gunzippedS, err := AppendGunzipBytes(prefix, gzippedS[len(prefix):]) + if err != nil { + t.Fatalf("unexpected error when uncompressing %q: %s", s, err) + } + if !bytes.Equal(gunzippedS[:len(prefix)], prefix) { + t.Fatalf("unexpected prefix when uncompressing %q: %q. Expecting %q", s, gunzippedS[:len(prefix)], prefix) + } + gunzippedS = gunzippedS[len(prefix):] + if string(gunzippedS) != s { + t.Fatalf("unexpected uncompressed string %q. Expecting %q", gunzippedS, s) + } +} + func TestGzipCompress(t *testing.T) { testGzipCompress(t, "") testGzipCompress(t, "foobar") |