forked from helmfile/vals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vals_onepasswordconnect_test.go
63 lines (54 loc) · 1.5 KB
/
vals_onepasswordconnect_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
package vals
import (
"fmt"
"os"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestValues_OnePasswordConnect_EvalTemplate(t *testing.T) {
// TODO
// create vault and item for testing
// op vault create vals-test
// op item create --vault vals-test --title=vals-test [email protected] password=secret --category=login
// Pre-requisite:
// Setup 1Password connect service with access to `vals-test` vault: https://developer.1password.com/docs/connect/
// set up service principal credentials in the environment:
// "OP_CONNECT_TOKEN": "...",
// "OP_CONNECT_HOST": "...",
if os.Getenv("SKIP_TESTS") != "" {
t.Skip("Skipping tests")
}
type testcase struct {
template map[string]interface{}
expected map[string]interface{}
}
vaultLabel := "vals-test"
itemLabel := "vals-test"
testcases := []testcase{
{
template: map[string]interface{}{
"foo": "FOO",
"username": fmt.Sprintf("ref+onepasswordconnect://%s/%s#/username", vaultLabel, itemLabel),
"password": fmt.Sprintf("ref+onepasswordconnect://%s/%s#/password", vaultLabel, itemLabel),
},
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)
}
})
}
}