Skip to content

Commit

Permalink
test: add basic integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Jucker <[email protected]>
  • Loading branch information
juckerf committed Sep 25, 2023
1 parent ab0d584 commit f08600b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions vals_onepasswordconnect_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package vals

import (
"fmt"
"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": "...",

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)
}
})
}
}

0 comments on commit f08600b

Please sign in to comment.