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

Function testDecoderDecodeAll

zstd/decoder_test.go:1818–1884  ·  view source on GitHub ↗
(t *testing.T, fn string, dec *Decoder)

Source from the content-addressed store, hash-verified

1816}
1817
1818func testDecoderDecodeAll(t *testing.T, fn string, dec *Decoder) {
1819 zr := testCreateZipReader(fn, t)
1820 var want = make(map[string][]byte)
1821 for _, tt := range zr.File {
1822 if strings.HasSuffix(tt.Name, ".zst") {
1823 continue
1824 }
1825 r, err := tt.Open()
1826 if err != nil {
1827 t.Fatal(err)
1828 return
1829 }
1830 want[tt.Name+".zst"], _ = io.ReadAll(r)
1831 }
1832 var wg sync.WaitGroup
1833 for i, tt := range zr.File {
1834 if !strings.HasSuffix(tt.Name, ".zst") || (testing.Short() && i > 20) {
1835 continue
1836 }
1837 wg.Add(1)
1838 t.Run("DecodeAll-"+tt.Name, func(t *testing.T) {
1839 defer wg.Done()
1840 t.Parallel()
1841 r, err := tt.Open()
1842 if err != nil {
1843 t.Fatal(err)
1844 }
1845 in, err := io.ReadAll(r)
1846 if err != nil {
1847 t.Fatal(err)
1848 }
1849 wantB := want[tt.Name]
1850 // make a buffer that is too small.
1851 got, err := dec.DecodeAll(in, make([]byte, 10, 200))
1852 if err != nil {
1853 t.Error(err)
1854 }
1855 if len(got) < 10 {
1856 t.Fatal("didn't get input back")
1857 }
1858 got = got[10:]
1859 if !bytes.Equal(wantB, got) {
1860 if len(wantB)+len(got) < 1000 {
1861 t.Logf(" got: %v\nwant: %v", got, wantB)
1862 } else {
1863 fileName, _ := filepath.Abs(filepath.Join("testdata", t.Name()+"-want.bin"))
1864 _ = os.MkdirAll(filepath.Dir(fileName), os.ModePerm)
1865 err := os.WriteFile(fileName, wantB, os.ModePerm)
1866 t.Log("Wrote file", fileName, err)
1867
1868 fileName, _ = filepath.Abs(filepath.Join("testdata", t.Name()+"-got.bin"))
1869 _ = os.MkdirAll(filepath.Dir(fileName), os.ModePerm)
1870 err = os.WriteFile(fileName, got, os.ModePerm)
1871 t.Log("Wrote file", fileName, err)
1872 }
1873 t.Logf("Length, want: %d, got: %d", len(wantB), len(got))
1874 t.Error("Output mismatch")
1875 return

Callers 4

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

Calls 7

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