github.com/hashicorp/packer@v1.14.3/hcl2template/function/encoding_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package function 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/zclconf/go-cty/cty" 11 ) 12 13 func TestBase64Gzip(t *testing.T) { 14 tests := []struct { 15 String cty.Value 16 Want cty.Value 17 Err bool 18 }{ 19 { 20 cty.StringVal("test"), 21 cty.StringVal("H4sIAAAAAAAA/ypJLS4BAAAA//8BAAD//wx+f9gEAAAA"), 22 false, 23 }, 24 { 25 cty.StringVal("helloworld"), 26 cty.StringVal("H4sIAAAAAAAA/8pIzcnJL88vykkBAAAA//8BAAD//60g6/kKAAAA"), 27 false, 28 }, 29 } 30 31 for _, test := range tests { 32 t.Run(fmt.Sprintf("base64gzip(%#v)", test.String), func(t *testing.T) { 33 got, err := Base64Gzip(test.String) 34 35 if test.Err { 36 if err == nil { 37 t.Fatal("succeeded; want error") 38 } 39 return 40 } else if err != nil { 41 t.Fatalf("unexpected error: %s", err) 42 } 43 44 if !got.RawEquals(test.Want) { 45 t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, test.Want) 46 } 47 }) 48 } 49 }