terraform/lang/funcs/encoding_test.go

49 lines
879 B
Go
Raw Normal View History

2018-05-23 01:29:45 +02:00
package funcs
import (
"fmt"
"testing"
"github.com/zclconf/go-cty/cty"
)
func TestBase64Decode(t *testing.T) {
tests := []struct {
String cty.Value
Want cty.Value
Err bool
}{
{
cty.StringVal("YWJjMTIzIT8kKiYoKSctPUB+"),
cty.StringVal("abc123!?$*&()'-=@~"),
false,
},
{ // Invalid base64 data decoding
cty.StringVal("this-is-an-invalid-base64-data"),
cty.UnknownVal(cty.String),
true,
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("base64decode(%#v)", test.String), func(t *testing.T) {
got, err := Base64Decode(test.String)
if test.Err {
if err == nil {
t.Fatal("succeeded; want error")
}
return
} else {
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
}
if !got.RawEquals(test.Want) {
t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, test.Want)
}
})
}
}