forked from helmfile/vals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vals_onepassword_test.go
60 lines (52 loc) · 1.44 KB
/
vals_onepassword_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
package vals
import (
"fmt"
"os"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestValues_OnePassword_EvalTemplate(t *testing.T) {
// TODO
// 1. Create vault and item for testing and a service account
// op vault create vals-test
// op item create --vault vals-test --title=vals-test [email protected] password=secret --category=login
// op service-account create "Vals Test Service Account" --expires-in 24h --vault vals-test:read_items
// 2. Set up the new service account token as environment variable:
// export OP_SERVICE_ACCOUNT_TOKEN=ops_xxxxxxxxx
if os.Getenv("SKIP_TESTS") != "" {
t.Skip("Skipping tests")
}
type testcase struct {
template map[string]interface{}
expected map[string]interface{}
}
vaultName := "vals-test"
itemName := "vals-test"
testcases := []testcase{
{
template: map[string]interface{}{
"foo": "FOO",
"username": fmt.Sprintf("ref+op://%s/%s/username", vaultName, itemName),
"password": fmt.Sprintf("ref+op://%s/%s/password", vaultName, itemName),
},
expected: map[string]interface{}{
"foo": "FOO",
"username": "[email protected]",
"password": "secret",
},
},
}
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("unxpected diff: %s", diff)
}
})
}
}