gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/compressio/nocompressio_test.go (about) 1 // Copyright 2023 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package compressio 16 17 import ( 18 "bytes" 19 "fmt" 20 "io" 21 "math/rand" 22 "testing" 23 "time" 24 ) 25 26 func TestNoCompress(t *testing.T) { 27 rand.Seed(time.Now().Unix()) 28 29 var ( 30 data = initTest(t, 10*1024*1024) 31 data0 = data[:0] 32 data1 = data[:1] 33 data2 = data[:11] 34 data3 = data[:16] 35 data4 = data[:] 36 ) 37 38 for _, data := range [][]byte{data0, data1, data2, data3, data4} { 39 for _, blockSize := range []uint32{1, 4, 1024, 4 * 1024, 16 * 1024} { 40 // Skip annoying tests; they just take too long. 41 if blockSize <= 16 && len(data) > 16 { 42 continue 43 } 44 45 for _, key := range [][]byte{nil, hashKey} { 46 for _, corruptData := range []bool{false, true} { 47 if key == nil && corruptData { 48 // No need to test corrupt data 49 // case when not doing hashing. 50 continue 51 } 52 // Do the compress test. 53 doTest(t, testOpts{ 54 Name: fmt.Sprintf("len(data)=%d, blockSize=%d, key=%s, corruptData=%v", len(data), blockSize, string(key), corruptData), 55 Data: data, 56 NewWriter: func(b *bytes.Buffer) (io.Writer, error) { 57 return NewSimpleWriter(b, key) 58 }, 59 NewReader: func(b *bytes.Buffer) (io.Reader, error) { 60 return NewSimpleReader(b, key) 61 }, 62 CorruptData: corruptData, 63 }) 64 } 65 } 66 } 67 } 68 }