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

Function testDecoderDecodeAllError

zstd/decoder_test.go:1886–1933  ·  view source on GitHub ↗
(t *testing.T, fn string, dec *Decoder, errMap map[string]string)

Source from the content-addressed store, hash-verified

1884}
1885
1886func testDecoderDecodeAllError(t *testing.T, fn string, dec *Decoder, errMap map[string]string) {
1887 zr := testCreateZipReader(fn, t)
1888
1889 var wg sync.WaitGroup
1890 for _, tt := range zr.File {
1891 if !strings.HasSuffix(tt.Name, ".zst") {
1892 continue
1893 }
1894 wg.Add(1)
1895 t.Run(tt.Name, func(t *testing.T) {
1896 defer wg.Done()
1897 r, err := tt.Open()
1898 if err != nil {
1899 t.Fatal(err)
1900 }
1901 in, err := io.ReadAll(r)
1902 if err != nil {
1903 t.Fatal(err)
1904 }
1905 // make a buffer that is small.
1906 got, err := dec.DecodeAll(in, make([]byte, 0, 20))
1907 if err == nil {
1908 t.Error("Did not get expected error, got", len(got), "bytes")
1909 return
1910 }
1911 t.Log(err)
1912 if errMap[tt.Name] == "" {
1913 t.Error("cannot check error")
1914 } else {
1915 want := errMap[tt.Name]
1916 if want != err.Error() {
1917 if want == ErrFrameSizeMismatch.Error() && err == ErrDecoderSizeExceeded {
1918 return
1919 }
1920 if want == ErrWindowSizeExceeded.Error() && err == ErrDecoderSizeExceeded {
1921 return
1922 }
1923 t.Errorf("error mismatch, prev run got %s, now got %s", want, err.Error())
1924 }
1925 return
1926 }
1927 })
1928 }
1929 go func() {
1930 wg.Wait()
1931 dec.Close()
1932 }()
1933}
1934
1935// Test our predefined tables are correct.
1936// We don't predefine them, since this also tests our transformations.

Callers 1

TestNewDecoderBadFunction · 0.85

Calls 6

testCreateZipReaderFunction · 0.85
FatalMethod · 0.80
DecodeAllMethod · 0.80
CloseMethod · 0.65
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…