-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbrotli_test.go
103 lines (99 loc) · 2.7 KB
/
brotli_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package archives
import (
"bytes"
"context"
"testing"
)
func TestBrotli_Match_Stream(t *testing.T) {
testTxt := []byte("this is text, but it has to be long enough to match brotli which doesn't have a magic number")
type testcase struct {
name string
input []byte
matches bool
}
for _, tc := range []testcase{
{
name: "uncompressed yaml",
input: []byte("---\nthis-is-not-brotli: \"it is actually yaml\""),
matches: false,
},
{
name: "uncompressed text",
input: testTxt,
matches: false,
},
{
name: "text compressed with brotli quality 0",
input: compress(t, ".br", testTxt, Brotli{Quality: 0}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 1",
input: compress(t, ".br", testTxt, Brotli{Quality: 1}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 2",
input: compress(t, ".br", testTxt, Brotli{Quality: 2}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 3",
input: compress(t, ".br", testTxt, Brotli{Quality: 3}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 4",
input: compress(t, ".br", testTxt, Brotli{Quality: 4}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 5",
input: compress(t, ".br", testTxt, Brotli{Quality: 5}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 6",
input: compress(t, ".br", testTxt, Brotli{Quality: 6}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 7",
input: compress(t, ".br", testTxt, Brotli{Quality: 7}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 8",
input: compress(t, ".br", testTxt, Brotli{Quality: 8}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 9",
input: compress(t, ".br", testTxt, Brotli{Quality: 9}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 10",
input: compress(t, ".br", testTxt, Brotli{Quality: 10}.OpenWriter),
matches: true,
},
{
name: "text compressed with brotli quality 11",
input: compress(t, ".br", testTxt, Brotli{Quality: 11}.OpenWriter),
matches: true,
},
} {
t.Run(tc.name, func(t *testing.T) {
r := bytes.NewBuffer(tc.input)
mr, err := Brotli{}.Match(context.Background(), "", r)
if err != nil {
t.Errorf("Brotli.OpenReader() error = %v", err)
return
}
if mr.ByStream != tc.matches {
t.Logf("input: %s", tc.input)
t.Error("Brotli.Match() expected ByStream to be", tc.matches, "but got", mr.ByStream)
}
})
}
}