-
Notifications
You must be signed in to change notification settings - Fork 0
/
keychain_test.go
111 lines (99 loc) · 2.12 KB
/
keychain_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package keychain
import (
"os/user"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
/**
*/
type TestService struct {
Label string
Group string
Key string
}
func (t *TestService) Set(s string) error { return nil }
func (t *TestService) Get() (string, error) { return "", nil }
func (t *TestService) Del() error { return nil }
func NewForTest(key, label, group string) Item {
return &TestService{
Group: group,
Label: label,
Key: key,
}
}
func init() {
keychains[runtime.GOOS] = NewForTest
supported = append(supported,
runtime.GOOS)
}
// --
func TestUser(t *testing.T) {
u, _ := user.Current()
type TestStruct struct {
description string
expected string
}
for _, ts := range []TestStruct{
TestStruct{
description: "it gives the user",
expected: u.Username,
},
} {
a := User()
assert.Equal(t, ts.expected, a,
ts.description)
}
}
func TestKtl(t *testing.T) {
s := New("tests.example.test", "tests.group.example.tests")
type TestStruct struct {
expected string
description string
actual string
}
for _, ts := range []TestStruct{
TestStruct{
actual: "Hello World",
description: "it works for Hello World",
expected: "Hello World",
},
TestStruct{
actual: "hello world",
description: "it works for hello world",
expected: "Hello World",
},
TestStruct{
actual: "hello-world",
description: "it works for hello-world",
expected: "Hello World",
},
} {
a := s.ktl(ts.actual)
assert.Equal(t, ts.expected, a,
ts.description)
}
}
func TestTok(t *testing.T) {
s := New("tests.example.test", "tests.group.example.tests")
type TestStruct struct {
expected string
description string
actual string
}
for _, ts := range []TestStruct{
TestStruct{
actual: "Hello World",
description: "it should error if it has a space",
expected: "Hello World.tests.example.test",
},
TestStruct{
description: "it should work",
expected: "hello-world.tests.example.test",
actual: "hello-world",
},
} {
a := s.tok(ts.actual)
assert.Equal(t, ts.expected, a)
}
}