MCPcopy
hub / github.com/grafana/dskit / TestSnappy

Function TestSnappy

grpcencoding/snappy/snappy_test.go:13–44  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestSnappy(t *testing.T) {
14 c := newCompressor()
15 assert.Equal(t, "snappy", c.Name())
16
17 tests := []struct {
18 test string
19 input string
20 }{
21 {"empty", ""},
22 {"short", "hello world"},
23 {"long", strings.Repeat("123456789", 1024)},
24 }
25 for _, test := range tests {
26 t.Run(test.test, func(t *testing.T) {
27 var buf bytes.Buffer
28 // Compress
29 w, err := c.Compress(&buf)
30 require.NoError(t, err)
31 n, err := w.Write([]byte(test.input))
32 require.NoError(t, err)
33 assert.Len(t, test.input, n)
34 err = w.Close()
35 require.NoError(t, err)
36 // Decompress
37 r, err := c.Decompress(&buf)
38 require.NoError(t, err)
39 out, err := io.ReadAll(r)
40 require.NoError(t, err)
41 assert.Equal(t, test.input, string(out))
42 })
43 }
44}
45
46func BenchmarkSnappyCompress(b *testing.B) {
47 data := []byte(strings.Repeat("123456789", 1024))

Callers

nothing calls this directly

Calls 9

newCompressorFunction · 0.85
RunMethod · 0.80
CompressMethod · 0.80
DecompressMethod · 0.80
NameMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.45
WriteMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected