github.com/jlowellwofford/u-root@v1.0.0/pkg/gzip/gzip_test.go (about) 1 // Copyright 2017-2018 the u-root 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 package gzip 6 7 import ( 8 "bytes" 9 "io" 10 "testing" 11 ) 12 13 func Test_Compress(t *testing.T) { 14 type args struct { 15 r io.Reader 16 level int 17 blocksize int 18 processes int 19 } 20 tests := []struct { 21 name string 22 args args 23 wantW []byte 24 wantErr bool 25 }{ 26 { 27 name: "Basic Compress", 28 args: args{ 29 r: bytes.NewReader([]byte("Test Test Test")), 30 level: 9, 31 blocksize: 128, 32 processes: 1, 33 }, 34 wantW: []byte("\x1f\x8b\b\x00\x00\tn\x88\x02\xff\nI-.Q\x80\x13\x00\x00\x00\x00\xff\xff\x01\x00\x00\xff\xffG?\xfc\xcc\x0e\x00\x00\x00"), 35 wantErr: false, 36 }, 37 { 38 name: "Zeros", 39 args: args{ 40 r: bytes.NewReader([]byte("000000000000000000000000000000000000000000000000000")), 41 level: 9, 42 blocksize: 128, 43 processes: 1, 44 }, 45 wantW: []byte("\x1f\x8b\b\x00\x00\tn\x88\x02\xff2 \x1d\x00\x00\x00\x00\xff\xff\x01\x00\x00\xff\xffR6\xe3\xeb3\x00\x00\x00"), 46 wantErr: false, 47 }, 48 { 49 name: "Nil", 50 args: args{ 51 r: bytes.NewReader([]byte(nil)), 52 level: 1, 53 blocksize: 128, 54 processes: 1, 55 }, 56 wantW: []byte("\x1f\x8b\b\x00\x00\tn\x88\x04\xff\x00\x00\x00\xff\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00"), 57 wantErr: false, 58 }, 59 } 60 for _, tt := range tests { 61 t.Run(tt.name, func(t *testing.T) { 62 w := bytes.Buffer{} 63 if err := Compress(tt.args.r, &w, tt.args.level, tt.args.blocksize, tt.args.processes); (err != nil) != tt.wantErr { 64 t.Errorf("Compress() error = %v, wantErr %v", err, tt.wantErr) 65 return 66 } 67 gotW := w.Bytes() 68 if !bytes.Equal(gotW, tt.wantW) { 69 t.Errorf("Compress() = %q, want %q", gotW, tt.wantW) 70 } 71 }) 72 } 73 }