-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient_test.go
64 lines (60 loc) · 1.51 KB
/
client_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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package kubesecrets
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
rbacv1 "k8s.io/api/rbac/v1"
)
func Test_makeRules(t *testing.T) {
testCases := map[string]struct {
rules string
expected []rbacv1.PolicyRule
wantErr error
}{
"good YAML": {
rules: goodYAMLRules,
expected: []rbacv1.PolicyRule{
{
APIGroups: []string{"admissionregistration.k8s.io"},
Resources: []string{"mutatingwebhookconfigurations"},
Verbs: []string{"get", "list", "watch", "patch"},
},
},
wantErr: nil,
},
"good JSON": {
rules: goodJSONRules,
expected: []rbacv1.PolicyRule{
{
APIGroups: []string{"admissionregistration.k8s.io"},
Resources: []string{"mutatingwebhookconfigurations"},
Verbs: []string{"get", "list", "watch", "patch"},
},
},
wantErr: nil,
},
"bad YAML": {
rules: badYAMLRules,
expected: nil,
wantErr: fmt.Errorf("error converting YAML to JSON: yaml: line 3: found character that cannot start any token"),
},
"bad JSON": {
rules: badJSONRules,
expected: nil,
wantErr: fmt.Errorf("error converting YAML to JSON: yaml: line 4: did not find expected ',' or '}'"),
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
result, err := makeRules(tc.rules)
if tc.wantErr != nil {
assert.EqualError(t, err, tc.wantErr.Error())
} else {
assert.NoError(t, err)
}
assert.Equal(t, tc.expected, result)
})
}
}