-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
200 lines (186 loc) · 3.58 KB
/
utils_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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package azcfg
import (
"testing"
"github.com/KarlGW/azcfg/azure/cloud"
"github.com/google/go-cmp/cmp"
)
func TestSplitTrim(t *testing.T) {
var tests = []struct {
name string
input string
sep string
want []string
}{
{
name: "nosep",
input: "aaaa,bbbb, cccc, dddd",
want: []string{"aaaa", "bbbb", "cccc", "dddd"},
},
{
name: "comma",
input: "aaaa,bbbb, cccc, dddd",
sep: ",",
want: []string{"aaaa", "bbbb", "cccc", "dddd"},
},
{
name: "colon",
input: "aaaa:bbbb: cccc: dddd",
sep: ":",
want: []string{"aaaa", "bbbb", "cccc", "dddd"},
},
{
name: "no value",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := splitTrim(test.input, test.sep)
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("splitTrim(%q, %q) = unexpected result, (-want, +got)\n%s\n", test.input, test.sep, diff)
}
})
}
}
func TestParseBool(t *testing.T) {
var tests = []struct {
name string
input string
want bool
}{
{
name: "empty string",
want: false,
},
{
name: "true",
input: "true",
want: true,
},
{
name: "false",
input: "false",
want: false,
},
{
name: "invalid",
input: "invalid",
want: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := parseBool(test.input)
if test.want != got {
t.Errorf("parseBool() = unexpected result, want: %t, got: %t\n", test.want, got)
}
})
}
}
func TestParseLabels(t *testing.T) {
var tests = []struct {
name string
input string
want map[string]string
}{
{
name: "empty string",
want: nil,
},
{
name: "with comma-separated key-value pairs",
input: "setting1=prod,setting2=test",
want: map[string]string{
"setting1": "prod",
"setting2": "test",
},
},
{
name: "with comma-separated key-value pairs (spaces in string)",
input: "setting1 = prod, setting2 = test",
want: map[string]string{
"setting1": "prod",
"setting2": "test",
},
},
{
name: "with malformed label",
input: "setting1",
want: nil,
},
{
name: "with malformed second key-value pair",
input: "setting1=prod,setting2",
want: map[string]string{
"setting1": "prod",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := parseCSVKVP(test.input)
if diff := cmp.Diff(test.want, got); diff != "" {
t.Errorf("parseCSVKVP() = unexpected result (-want +got)\n%s\n", diff)
}
})
}
}
func TestParseCloud(t *testing.T) {
var tests = []struct {
name string
input string
want cloud.Cloud
}{
{
name: "empty string",
want: cloud.AzurePublic,
},
{
name: "Azure",
input: "Azure",
want: cloud.AzurePublic,
},
{
name: "AzurePublic",
input: "AzurePublic",
want: cloud.AzurePublic,
},
{
name: "Public",
input: "Public",
want: cloud.AzurePublic,
},
{
name: "AzureGovernment",
input: "AzureGovernment",
want: cloud.AzureGovernment,
},
{
name: "Government",
input: "Government",
want: cloud.AzureGovernment,
},
{
name: "AzureChina",
input: "AzureChina",
want: cloud.AzureChina,
},
{
name: "China",
input: "China",
want: cloud.AzureChina,
},
{
name: "non-existent cloud",
input: "NonExistent",
want: cloud.AzurePublic,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := parseCloud(test.input)
if test.want != got {
t.Errorf("parseCloud() = unexpected result, want: %s, got: %s\n", test.want, got)
}
})
}
}