-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cli-61-filter-logs-by-clientid
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} |