diff --git a/g/encoding/gcompress/gcompress_test.go b/g/encoding/gcompress/gcompress_test.go index 17829f8af..df1bbb6f3 100644 --- a/g/encoding/gcompress/gcompress_test.go +++ b/g/encoding/gcompress/gcompress_test.go @@ -6,23 +6,37 @@ package gcompress_test import ( - "github.com/gogf/gf/g/util/grand" "github.com/gogf/gf/g/encoding/gcompress" "github.com/gogf/gf/g/test/gtest" "testing" ) -var times = 10 -var length = 2000 +func TestZlib(t *testing.T) { + gtest.Case(t, func() { + src := "hello, world\n" + dst := []byte{120, 156, 202, 72, 205, 201, 201, 215, 81, 40, 207, 47, 202, 73, 225, 2, 4, 0, 0, 255, 255, 33, 231, 4, 147} + gtest.Assert(gcompress.Zlib([]byte(src)), dst) -func TestCompress(t *testing.T) { - for i := 0; i < times; i++ { - src := grand.RandStr(length + i * 10) - zlibVal := gcompress.Zlib([]byte(src)) - dst := gcompress.UnZlib(zlibVal) - gtest.Assert(dst, []byte(src)) + gtest.Assert(gcompress.UnZlib(dst), []byte(src)) + }) - dst1 := gcompress.UnGzip(gcompress.Gzip([]byte(src))) - gtest.Assert(dst1, []byte(src)) - } +} + +func TestGzip(t *testing.T) { + src := "Hello World!!" + + gzip := []byte{ + 0x1f, 0x8b, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, + 0xf2, 0x48, 0xcd, 0xc9, 0xc9, + 0x57, 0x08, 0xcf, 0x2f, 0xca, + 0x49, 0x51, 0x54, 0x04, 0x04, + 0x00, 0x00, 0xff, 0xff, 0x9d, + 0x24, 0xa8, 0xd1, 0x0d, 0x00, + 0x00, 0x00, + } + + gtest.Assert(gcompress.Gzip([]byte(src)), gzip) + + gtest.Assert(gcompress.UnGzip(gzip), []byte(src)) }