Skip to content

Commit

Permalink
test: keychain abstraction (#149)
Browse files Browse the repository at this point in the history
* test: keychain abstraction (secrets)

* check error on test

* fix typo
  • Loading branch information
jfatta authored Mar 12, 2021
1 parent 575654a commit 2e15176
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions internal/auth/secrets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package auth

import (
"testing"

"github.com/zalando/go-keyring"
)

func TestSecrets(t *testing.T) {
t.Run("fail: not found", func(t *testing.T) {
// init underlying keychain manager
keyring.MockInit()

kr := &Keyring{}
_, err := kr.Get("mynamespace", "foo")

if got, want := err, keyring.ErrNotFound; got != want {
t.Fatalf("wanted error: %v, got: %v", want, got)
}
})

t.Run("succeed: get secret", func(t *testing.T) {
// init underlying keychain manager
keyring.MockInit()

// set with the underlying manager:
err := keyring.Set("mynamespace", "foo", "bar")
if err != nil {
t.Fatal(err)
}

kr := &Keyring{}
v, err := kr.Get("mynamespace", "foo")
if err != nil {
t.Fatal(err)
}

if got, want := v, "bar"; got != want {
t.Fatalf("wanted error: %v, got: %v", want, got)
}
})

t.Run("succeed: set secret", func(t *testing.T) {
// init underlying keychain manager
keyring.MockInit()

kr := &Keyring{}
err := kr.Set("mynamespace", "foo", "bar")
if err != nil {
t.Fatal(err)
}

// get with the underlying manager:
v, err := keyring.Get("mynamespace", "foo")
if err != nil {
t.Fatal(err)
}

if got, want := v, "bar"; got != want {
t.Fatalf("wanted secret: %v, got: %v", want, got)
}
})
}

0 comments on commit 2e15176

Please sign in to comment.