-
Notifications
You must be signed in to change notification settings - Fork 0
/
appsecret_test.go
60 lines (55 loc) · 1.22 KB
/
appsecret_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
package githubappsecret
import (
"reflect"
"testing"
corev1 "k8s.io/api/core/v1"
)
func TestPopulateSecret(t *testing.T) {
testToken := "a-token"
cases := []struct {
name string
secret *corev1.Secret
secretType string
wantData map[string]string
}{
{
name: "empty string data, git secret",
secret: &corev1.Secret{},
secretType: SecretGit,
wantData: map[string]string{
"username": AccessTokenUsername,
"password": testToken,
},
},
{
name: "plain secret",
secret: &corev1.Secret{},
secretType: SecretPlain,
wantData: map[string]string{
"token": testToken,
},
},
{
name: "overwrite existing data",
secret: &corev1.Secret{
StringData: map[string]string{
"username": "foo",
"password": "bar",
},
},
secretType: SecretGit,
wantData: map[string]string{
"username": AccessTokenUsername,
"password": testToken,
},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
populateSecret(tc.secret, tc.secretType, testToken)
if !reflect.DeepEqual(tc.secret.StringData, tc.wantData) {
t.Errorf("unexpected secret data:\n\tWNT: %v\n\tGOT: %v", tc.wantData, tc.secret.StringData)
}
})
}
}