forked from simonmittag/j8a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgzip_test.go
34 lines (29 loc) · 983 Bytes
/
gzip_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package jabba
import (
"bytes"
"fmt"
"testing"
)
//test pool allocation of zipper
func TestGzipper(t *testing.T) {
//run small loop to ensure pool allocation works
for i:=0;i<=10;i++ {
json := []byte("{\"routes\": [{\n\t\t\t\"path\": \"/about\",\n\t\t\t\"resource\": \"aboutJabba\"\n\t\t},\n\t\t{\n\t\t\t\"path\": \"/customer\",\n\t\t\t\"resource\": \"customer\",\n\t\t\t\"policy\": \"ab\"\n\t\t}\n\t]}")
zipped := Gzip(json)
if c := bytes.Compare(zipped[0:2], gzipMagicBytes); c != 0 {
t.Errorf("gzip format not properly encoded, want %v, got %v", gzipMagicBytes, zipped[0:2])
}
var want = [2]int{100, 120}
if !(len(zipped) >= want[0] && len(zipped) <= want[1]) {
t.Errorf("gzip compression not working")
}
}
}
func TestGzipThenUnzip(t *testing.T) {
for i:=0;i<=100;i++ {
json := []byte(fmt.Sprintf(`{ "key":"value%d" }`, i))
if c := bytes.Compare(json, Gunzip(Gzip(json))); c != 0 {
t.Error("unzipped data is not equal to original")
}
}
}