MCPcopy Index your code
hub / github.com/klauspost/compress / testDecoderFile

Function testDecoderFile

zstd/decoder_test.go:1028–1133  ·  view source on GitHub ↗
(t *testing.T, fn string, newDec func() (*Decoder, error))

Source from the content-addressed store, hash-verified

1026}
1027
1028func testDecoderFile(t *testing.T, fn string, newDec func() (*Decoder, error)) {
1029 zr := testCreateZipReader(fn, t)
1030 var want = make(map[string][]byte)
1031 for _, tt := range zr.File {
1032 if strings.HasSuffix(tt.Name, ".zst") {
1033 continue
1034 }
1035 r, err := tt.Open()
1036 if err != nil {
1037 t.Fatal(err)
1038 return
1039 }
1040 want[tt.Name+".zst"], _ = io.ReadAll(r)
1041 }
1042
1043 dec, err := newDec()
1044 if err != nil {
1045 t.Error(err)
1046 return
1047 }
1048 defer dec.Close()
1049 for i, tt := range zr.File {
1050 if !strings.HasSuffix(tt.Name, ".zst") || (testing.Short() && i > 20) {
1051 continue
1052 }
1053 t.Run("Reader-"+tt.Name, func(t *testing.T) {
1054 defer timeout(10 * time.Second)()
1055 r, err := tt.Open()
1056 if err != nil {
1057 t.Error(err)
1058 return
1059 }
1060 data, err := io.ReadAll(r)
1061 r.Close()
1062 if err != nil {
1063 t.Error(err)
1064 return
1065 }
1066 err = dec.Reset(io.NopCloser(bytes.NewBuffer(data)))
1067 if err != nil {
1068 t.Error(err)
1069 return
1070 }
1071 var got []byte
1072 var gotError error
1073 var wg sync.WaitGroup
1074 wg.Add(1)
1075 go func() {
1076 got, gotError = io.ReadAll(dec)
1077 wg.Done()
1078 }()
1079
1080 // This decode should not interfere with the stream...
1081 gotDecAll, err := dec.DecodeAll(data, nil)
1082 if err != nil {
1083 t.Error(err)
1084 if err != ErrCRCMismatch {
1085 wg.Wait()

Callers 4

TestNewDecoderFunction · 0.85
TestNewDecoderGoodFunction · 0.85
TestNewDecoderLargeFunction · 0.85
TestNewDecoderBigFunction · 0.85

Calls 9

testCreateZipReaderFunction · 0.85
timeoutFunction · 0.85
FatalMethod · 0.80
DecodeAllMethod · 0.80
CloseMethod · 0.65
ResetMethod · 0.65
OpenMethod · 0.45
ErrorMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…