-
Notifications
You must be signed in to change notification settings - Fork 25
/
keyring_test.go
46 lines (42 loc) · 979 Bytes
/
keyring_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
package keyring
import (
"testing"
)
func assertPasswordSticks(t *testing.T, user, password string) {
var (
pw string
err error
)
pw, err = Get("keyring-test", user)
if err != nil {
// ok on initial invokation
t.Logf("(expected) Initial Get() error for %s: %s", user, err)
}
err = Set("keyring-test", user, password)
if err != nil {
t.Errorf("Set() error for %s: %s", user, err)
}
pw, err = Get("keyring-test", user)
if err != nil {
t.Errorf("Get() error for %s: %s", user, err)
}
if pw != password {
t.Errorf("expected '%s' for %s, got '%s'", password, user, pw)
}
}
func TestBasicSetGet(t *testing.T) {
cases := []struct {
user string
password string
}{
{"jack", "foo"},
{"jill", "bar"},
{"alice", "cr4zyp!s\\%"},
{"punctuator", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"},
{"pierre", "bérets"},
{"unibomba", "I❤Unicode"},
}
for _, testCase := range cases {
assertPasswordSticks(t, testCase.user, testCase.password)
}
}