github.com/simonswine/terraform@v0.9.0-beta2/builtin/providers/aws/utils_test.go (about) 1 package aws 2 3 import "testing" 4 5 var base64encodingTests = []struct { 6 in []byte 7 out string 8 }{ 9 // normal encoding case 10 {[]byte("data should be encoded"), "ZGF0YSBzaG91bGQgYmUgZW5jb2RlZA=="}, 11 // base64 encoded input should result in no change of output 12 {[]byte("ZGF0YSBzaG91bGQgYmUgZW5jb2RlZA=="), "ZGF0YSBzaG91bGQgYmUgZW5jb2RlZA=="}, 13 } 14 15 func TestBase64Encode(t *testing.T) { 16 for _, tt := range base64encodingTests { 17 out := base64Encode(tt.in) 18 if out != tt.out { 19 t.Errorf("base64Encode(%s) => %s, want %s", tt.in, out, tt.out) 20 } 21 } 22 } 23 24 func TestLooksLikeJsonString(t *testing.T) { 25 looksLikeJson := ` {"abc":"1"} ` 26 doesNotLookLikeJson := `abc: 1` 27 28 if !looksLikeJsonString(looksLikeJson) { 29 t.Errorf("Expected looksLikeJson to return true for %s", looksLikeJson) 30 } 31 if looksLikeJsonString(doesNotLookLikeJson) { 32 t.Errorf("Expected looksLikeJson to return false for %s", doesNotLookLikeJson) 33 } 34 }