github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/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 "strings" 10 "testing" 11 12 "github.com/google/go-cmp/cmp" 13 ) 14 15 func TestCompress(t *testing.T) { 16 tests := []struct { 17 name string 18 plain string 19 level int 20 blocksize int 21 processes int 22 }{ 23 { 24 name: "Basic Compress", 25 plain: "Test Test Test", 26 level: 9, 27 blocksize: 128, 28 processes: 1, 29 }, 30 { 31 name: "Zeplainos", 32 plain: "000000000000000000000000000000000000000000000000000", 33 level: 9, 34 blocksize: 128, 35 processes: 1, 36 }, 37 { 38 name: "Empty stplaining", 39 plain: "", 40 level: 1, 41 blocksize: 128, 42 processes: 1, 43 }, 44 } 45 for _, tt := range tests { 46 t.Run(tt.name, func(t *testing.T) { 47 var ciphertext bytes.Buffer 48 if err := Compress(strings.NewReader(tt.plain), &ciphertext, tt.level, tt.blocksize, tt.processes); err != nil { 49 t.Fatalf("Compress() error = %v, want nil", err) 50 } 51 52 var plaintext strings.Builder 53 if err := Decompress(&ciphertext, &plaintext, tt.blocksize, tt.processes); err != nil { 54 t.Fatalf("Decompress() = %v, want nil", err) 55 } 56 57 got := plaintext.String() 58 if !cmp.Equal(got, tt.plain) { 59 t.Errorf("Compress() = %q, want %q -- diff\n%s", got, tt.plain, cmp.Diff(got, tt.plain)) 60 } 61 }) 62 } 63 }