github.com/ratrocket/u-root@v0.0.0-20180201221235-1cf9f48ee2cf/pkg/gzip/gzip_test.go (about) 1 package gzip 2 3 import ( 4 "bytes" 5 "io" 6 "testing" 7 ) 8 9 func Test_Compress(t *testing.T) { 10 type args struct { 11 r io.Reader 12 level int 13 blocksize int 14 processes int 15 } 16 tests := []struct { 17 name string 18 args args 19 wantW []byte 20 wantErr bool 21 }{ 22 { 23 name: "Basic Compress", 24 args: args{ 25 r: bytes.NewReader([]byte("Test Test Test")), 26 level: 9, 27 blocksize: 128, 28 processes: 1, 29 }, 30 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"), 31 wantErr: false, 32 }, 33 { 34 name: "Zeros", 35 args: args{ 36 r: bytes.NewReader([]byte("000000000000000000000000000000000000000000000000000")), 37 level: 9, 38 blocksize: 128, 39 processes: 1, 40 }, 41 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"), 42 wantErr: false, 43 }, 44 { 45 name: "Nil", 46 args: args{ 47 r: bytes.NewReader([]byte(nil)), 48 level: 1, 49 blocksize: 128, 50 processes: 1, 51 }, 52 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"), 53 wantErr: false, 54 }, 55 } 56 for _, tt := range tests { 57 t.Run(tt.name, func(t *testing.T) { 58 w := bytes.Buffer{} 59 if err := Compress(tt.args.r, &w, tt.args.level, tt.args.blocksize, tt.args.processes); (err != nil) != tt.wantErr { 60 t.Errorf("Compress() error = %v, wantErr %v", err, tt.wantErr) 61 return 62 } 63 gotW := w.Bytes() 64 if !bytes.Equal(gotW, tt.wantW) { 65 t.Errorf("Compress() = %q, want %q", gotW, tt.wantW) 66 } 67 }) 68 } 69 }