go-hep.org/x/hep@v0.38.1/groot/internal/rcompress/notcompressible_test.go (about) 1 // Copyright ©2018 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build !race 6 7 package rcompress 8 9 import ( 10 "os" 11 "testing" 12 ) 13 14 func TestNotCompressible(t *testing.T) { 15 t.Parallel() 16 17 dir, err := os.MkdirTemp("", "groot-rcompress-") 18 if err != nil { 19 t.Fatal(err) 20 } 21 defer os.RemoveAll(dir) 22 23 src, err := os.ReadFile("testdata/not-compressible.raw") 24 if err != nil { 25 t.Fatalf("could not read reference data: %+v", err) 26 } 27 28 srcsz := len(src) 29 tgtsz := len(src) + HeaderSize 30 31 for _, tc := range []struct { 32 name string 33 alg Kind 34 lvl int 35 want int 36 }{ 37 {name: "lz4", alg: LZ4, lvl: 1, want: srcsz}, 38 {name: "lzma", alg: LZMA, lvl: 1, want: srcsz}, 39 {name: "zlib", alg: ZLIB, lvl: 1, want: srcsz}, 40 {name: "zstd", alg: ZSTD, lvl: 1, want: srcsz}, 41 } { 42 t.Run(tc.name, func(t *testing.T) { 43 tgt := make([]byte, tgtsz) 44 n, err := compressBlock(tc.alg, tc.lvl, tgt, src) 45 if err != nil && err != errNoCompression { 46 t.Fatalf("could not compress block: %+v", err) 47 } 48 if got, want := n, tc.want; got != want { 49 t.Fatalf("invalid output size: got=%d, want=%d", got, want) 50 } 51 }) 52 } 53 }