MCPcopy
hub / github.com/klauspost/compress / TestEncodeTo

Function TestEncodeTo

zstd/simple_go124_test.go:17–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestEncodeTo(t *testing.T) {
18 // TODO: When we can remove the build tag, integrate this into the main test suite.
19 data, err := os.ReadFile("testdata/comp-crashers.zip")
20 if err != nil {
21 t.Fatal(err)
22 }
23
24 zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data)))
25 if err != nil {
26 t.Fatal(err)
27 }
28
29 for i, tt := range zr.File {
30 if testing.Short() && i > 10 {
31 break
32 }
33
34 t.Run(tt.Name, func(t *testing.T) {
35 r, err := tt.Open()
36 if err != nil {
37 t.Error(err)
38 return
39 }
40 in, err := io.ReadAll(r)
41 if err != nil {
42 t.Error(err)
43 }
44 encoded := EncodeTo(make([]byte, 0, len(in)/2), in)
45 got, err := DecodeTo(make([]byte, 0, len(in)/2), encoded)
46 if err != nil {
47 t.Logf("error: %v\nwant: %v\ngot: %v", err, len(in), len(got))
48 t.Fatal(err)
49 }
50 if !bytes.Equal(in, got) {
51 t.Errorf("decode mismatch for %s: want %d, got %d", tt.Name, len(in), len(got))
52 t.Logf("want: %x\ngot: %x", in, got)
53 }
54 })
55 }
56}

Callers

nothing calls this directly

Calls 6

NewReaderFunction · 0.92
EncodeToFunction · 0.85
DecodeToFunction · 0.85
FatalMethod · 0.80
OpenMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…