This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
path_creds_create_test.go
144 lines (137 loc) · 3 KB
/
path_creds_create_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package splunk
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"testing"
"gotest.tools/v3/assert"
"github.com/splunk/vault-plugin-splunk/clients/splunk"
)
func Test_findNode(t *testing.T) {
nodes := make([]splunk.ServerInfoEntry, 0)
gp := filepath.Join("testdata", t.Name()+".json")
jsonResponseSearchDistributedPeers, err := ioutil.ReadFile(gp)
assert.NilError(t, err)
err = json.Unmarshal(jsonResponseSearchDistributedPeers, &nodes)
assert.NilError(t, err)
type args struct {
nodeFQDN string
hosts []splunk.ServerInfoEntry
roleConfig *roleConfig
}
tests := []struct {
name string
args args
want bool
wantErr bool
}{
{
name: "server entry first",
args: args{
nodeFQDN: "idm-i-074b0895939212e99.foo.example.com",
hosts: nodes,
roleConfig: &roleConfig{
AllowedServerRoles: []string{"*"},
},
},
want: true,
wantErr: false,
},
{
name: "server entry last",
args: args{
nodeFQDN: "sh-i-0a12fdd509c2a2954.foo.example.com",
hosts: nodes,
roleConfig: &roleConfig{
AllowedServerRoles: []string{"*"},
},
},
want: true,
wantErr: false,
},
{
name: "server entry case insensitive",
args: args{
nodeFQDN: "SH-I-0A12FDD509C2A2954.FOO.EXAMPLE.COM",
hosts: nodes,
roleConfig: &roleConfig{
AllowedServerRoles: []string{"*"},
},
},
want: true,
wantErr: false,
},
{
name: "server entry short name",
args: args{
nodeFQDN: "SH-I-0A12FDD509C2A2954",
hosts: nodes,
roleConfig: &roleConfig{
AllowedServerRoles: []string{"*"},
},
},
want: true,
wantErr: false,
},
{
name: "server entry not found",
args: args{
nodeFQDN: "unknown-host",
hosts: nodes,
roleConfig: &roleConfig{
AllowedServerRoles: []string{"*"},
},
},
want: false,
wantErr: true,
},
{
name: "role match mismatch",
args: args{
nodeFQDN: "sh-i-0a12fdd509c2a2954.foo.example.com",
hosts: nodes,
roleConfig: &roleConfig{
AllowedServerRoles: []string{"unknown-role"},
},
},
want: false,
wantErr: true,
},
{
name: "role match first",
args: args{
nodeFQDN: "sh-i-0a12fdd509c2a2954.foo.example.com",
hosts: nodes,
roleConfig: &roleConfig{
AllowedServerRoles: []string{"cluster_search_head"},
},
},
want: true,
wantErr: false,
},
{
name: "role match last",
args: args{
nodeFQDN: "sh-i-0a12fdd509c2a2954.foo.example.com",
hosts: nodes,
roleConfig: &roleConfig{
AllowedServerRoles: []string{"unknown_role", "kv_store"},
},
},
want: true,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := findNode(tt.args.nodeFQDN, tt.args.hosts, tt.args.roleConfig)
if (err != nil) != tt.wantErr {
t.Errorf("findNode() error = %v, wantErr %v", err, tt.wantErr)
return
}
if (got != nil) != tt.want {
t.Errorf("findNode() = %v, want %v", got, tt.want)
}
})
}
}