forked from helmfile/vals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vals_gkms_test.go
66 lines (58 loc) · 1.56 KB
/
vals_gkms_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package vals
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestValues_GKMS(t *testing.T) {
// TODO
// create gkms and encrypt test value
// gcloud kms keyrings create "test" --location "global"
// gcloud kms keys create "default" --location "global" --keyring "test" --purpose "encryption"
// echo -n "test_value" \
// | gcloud kms encrypt \
// --location "global" \
// --keyring "test" \
// --key "default" \
// --plaintext-file - \
// --ciphertext-file - \
// | base64 -w0 \
// | tr '/+' '_-'
//
// run with:
//
// go test -run '^(TestValues_GKMS)$'
type testcase struct {
template map[string]interface{}
expected map[string]interface{}
}
plain_value := "test_value"
encrypted_value := "CiQAmPqoGAKT97oUK0DdiI_cLDm3j6iPDK4-TJ3yQII-snFHCckSMwAkTpnEoD5wOeRaZrt3eC1ewFMuw617fqqjTStrsar9ciGERzk5t6uMgA0HKzSxGMdjHQ=="
project := "test-project"
location := "global"
keyring := "test"
crypto_key := "default"
testcases := []testcase{
{
template: map[string]interface{}{
"test_key": fmt.Sprintf("ref+gkms://%s?project=%s&location=%s&keyring=%s&crypto_key=%s", encrypted_value, project, location, keyring, crypto_key),
},
expected: map[string]interface{}{
"test_key": plain_value,
},
},
}
for i := range testcases {
tc := testcases[i]
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
vals, err := Eval(tc.template)
if err != nil {
t.Fatalf("%v", err)
}
diff := cmp.Diff(tc.expected, vals)
if diff != "" {
t.Errorf("unexpected diff: %s", diff)
}
})
}
}