@@ -56,13 +56,109 @@ spec:
56
56
name: http
57
57
`
58
58
59
- var manifestWithNamespace = `apiVersion: apps/v1
59
+ var manifestWithBreak = `apiVersion: apps/v1
60
+ kind: Deployment
61
+ metadata:
62
+ labels:
63
+ app: leeroy-app
64
+ name: leeroy-app
65
+ spec:
66
+ replicas: 1
67
+ selector:
68
+ matchLabels:
69
+ app: leeroy-app
70
+ template:
71
+ metadata:
72
+ labels:
73
+ app: leeroy-app
74
+ spec:
75
+ containers:
76
+ - image: leeroy-app:1d38c165eada98acbbf9f8869b92bf32f4f9c4e80bdea23d20c7020db3ace2da
77
+ name: leeroy-app
78
+ ports:
79
+ - containerPort: 50051
80
+ name: http
81
+ ---
82
+ `
83
+
84
+ var manifests = `apiVersion: apps/v1
85
+ kind: Deployment
86
+ metadata:
87
+ labels:
88
+ app: leeroy-app
89
+ name: leeroy-app
90
+ spec:
91
+ replicas: 2
92
+ selector:
93
+ matchLabels:
94
+ app: leeroy-app
95
+ template:
96
+ metadata:
97
+ labels:
98
+ app: leeroy-app
99
+ spec:
100
+ containers:
101
+ - image: leeroy-app:1d38c165eada98acbbf9f8869b92bf32f4f9c4e80bdea23d20c7020db3ace2da
102
+ name: leeroy-app
103
+ ports:
104
+ - containerPort: 50051
105
+ name: http
106
+ ---
107
+ apiVersion: apps/v1
108
+ kind: Deployment
109
+ metadata:
110
+ labels:
111
+ app: leeroy-app
112
+ name: leeroy-app-canary
113
+ spec:
114
+ replicas: 1
115
+ selector:
116
+ matchLabels:
117
+ app: leeroy-app
118
+ template:
119
+ metadata:
120
+ labels:
121
+ app: leeroy-app
122
+ spec:
123
+ containers:
124
+ - image: leeroy-app2:1d38c165eada98acbbf9f8869b92bf32f4f9c4e80bdea23d20c7020db3ace2da
125
+ name: leeroy-app
126
+ ports:
127
+ - containerPort: 50051
128
+ name: http
129
+ `
130
+
131
+ var manifestsWithNamespace = `apiVersion: apps/v1
60
132
kind: Deployment
61
133
metadata:
62
134
labels:
63
135
app: leeroy-app
64
136
name: leeroy-app
65
137
namespace: manifest-namespace
138
+ spec:
139
+ replicas: 2
140
+ selector:
141
+ matchLabels:
142
+ app: leeroy-app
143
+ template:
144
+ metadata:
145
+ labels:
146
+ app: leeroy-app
147
+ spec:
148
+ containers:
149
+ - image: leeroy-app:1d38c165eada98acbbf9f8869b92bf32f4f9c4e80bdea23d20c7020db3ace2da
150
+ name: leeroy-app
151
+ ports:
152
+ - containerPort: 50051
153
+ name: http
154
+ ---
155
+ apiVersion: apps/v1
156
+ kind: Deployment
157
+ metadata:
158
+ labels:
159
+ app: leeroy-app
160
+ name: leeroy-app-canary
161
+ namespace: manifest-namespace
66
162
spec:
67
163
replicas: 1
68
164
selector:
@@ -80,6 +176,40 @@ spec:
80
176
- containerPort: 50051
81
177
name: http
82
178
`
179
+ var manifestWithNamespace = `apiVersion: apps/v1
180
+ kind: Deployment
181
+ metadata:
182
+ labels:
183
+ app: leeroy-app
184
+ name: leeroy-app---rel01
185
+ namespace: manifest-namespace
186
+ spec:
187
+ replicas: 1
188
+ selector:
189
+ matchLabels:
190
+ app: leeroy-app
191
+ template:
192
+ metadata:
193
+ labels:
194
+ app: leeroy-app
195
+ spec:
196
+ containers:
197
+ - image: leeroy-app:1d38c165eada98acbbf9f8869b92bf32f4f9c4e80bdea23d20c7020db3ace2da
198
+ name: leeroy-app
199
+ ports:
200
+ - containerPort: 50051
201
+ name: http
202
+ `
203
+
204
+ var emptyManifestWithBreak = `
205
+ ---
206
+ `
207
+
208
+ var emptyManifestWithTwoBreaks = `
209
+ ---
210
+
211
+ ---
212
+ `
83
213
84
214
func TestPrintTestsList (t * testing.T ) {
85
215
tests := []struct {
@@ -91,38 +221,87 @@ func TestPrintTestsList(t *testing.T) {
91
221
expected string
92
222
}{
93
223
{
94
- description : "print all deployment namespaces where no namespace is set in manifest(s) or deploy config" ,
224
+ description : "no namespace set in manifest or deploy config" ,
95
225
manifest : manifest ,
96
226
expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"default"}]}}` + "\n " ,
97
227
module : []string {"cfg-without-default-namespace" },
98
228
},
99
229
{
100
- description : "print all deployment namespaces where a namespace is set via the kubectl flag deploy config" ,
230
+ description : "no namespace set in manifest with break or deploy config" ,
231
+ manifest : manifestWithBreak ,
232
+ expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"default"}]}}` + "\n " ,
233
+ module : []string {"cfg-without-default-namespace" },
234
+ },
235
+ {
236
+ description : "no namespace is set in manifests or deploy config" ,
237
+ manifest : manifests ,
238
+ expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"default"},{"name":"leeroy-app-canary","namespace":"default"}]}}` + "\n " ,
239
+ module : []string {"cfg-without-default-namespace" },
240
+ },
241
+ {
242
+ description : "namespace set via kubectl flag deploy config for single manifest" ,
101
243
manifest : manifest ,
102
244
expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"foo-flag-ns"}]}}` + "\n " ,
103
245
profiles : []string {"foo-flag-ns" },
104
246
module : []string {"cfg-without-default-namespace" },
105
247
},
106
248
{
107
- description : "print all deployment namespaces where a default namespace is set via the kubectl defaultNamespace deploy config" ,
249
+ description : "namespace set via kubectl flag deploy config for multiple manifests" ,
250
+ manifest : manifests ,
251
+ expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"foo-flag-ns"},{"name":"leeroy-app-canary","namespace":"foo-flag-ns"}]}}` + "\n " ,
252
+ profiles : []string {"foo-flag-ns" },
253
+ module : []string {"cfg-without-default-namespace" },
254
+ },
255
+ {
256
+ description : "default namespace set via the kubectl defaultNamespace deploy config for single manifest" ,
108
257
manifest : manifest ,
109
258
expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"bar"}]}}` + "\n " ,
110
259
module : []string {"cfg-with-default-namespace" },
111
260
},
112
261
{
113
- description : "print all deployment namespaces where a default namespace and namespace is set via the kubectl deploy config" ,
262
+ description : "default namespace set via the kubectl defaultNamespace deploy config for multiple manifests" ,
263
+ manifest : manifests ,
264
+ expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"bar"},{"name":"leeroy-app-canary","namespace":"bar"}]}}` + "\n " ,
265
+ module : []string {"cfg-with-default-namespace" },
266
+ },
267
+ {
268
+ description : "default namespace and namespace set via the kubectl deploy config for single manifest" ,
114
269
manifest : manifest ,
115
270
expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"baz-flag-ns"}]}}` + "\n " ,
116
271
profiles : []string {"baz-flag-ns" },
117
272
module : []string {"cfg-with-default-namespace" },
118
273
},
119
274
{
120
- description : "print all deployment namespaces where the manifest has a namespace set but it is also set via the kubectl flag deploy config" ,
275
+ description : "default namespace and namespace set via the kubectl deploy config for multiple manifests" ,
276
+ manifest : manifests ,
277
+ expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"baz-flag-ns"},{"name":"leeroy-app-canary","namespace":"baz-flag-ns"}]}}` + "\n " ,
278
+ profiles : []string {"baz-flag-ns" },
279
+ module : []string {"cfg-with-default-namespace" },
280
+ },
281
+ {
282
+ description : "manifest has namespace set and namespace also set via kubectl flag deploy config" ,
121
283
manifest : manifestWithNamespace ,
122
- expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"manifest-namespace"}]}}` + "\n " ,
284
+ expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app---rel01 ","namespace":"manifest-namespace"}]}}` + "\n " ,
123
285
profiles : []string {"baz-flag-ns" },
124
286
module : []string {"cfg-with-default-namespace" },
125
287
},
288
+ {
289
+ description : "manifests have namespace set and namespace also set via the kubectl flag deploy config" ,
290
+ manifest : manifestsWithNamespace ,
291
+ expected : `{"resourceToInfoMap":{"apps/v1, Kind=Deployment":[{"name":"leeroy-app","namespace":"manifest-namespace"},{"name":"leeroy-app-canary","namespace":"manifest-namespace"}]}}` + "\n " ,
292
+ profiles : []string {"baz-flag-ns" },
293
+ module : []string {"cfg-with-default-namespace" },
294
+ },
295
+ {
296
+ description : "empty manifest with yaml page break notation returns empty resourceToInfoMap" ,
297
+ manifest : emptyManifestWithBreak ,
298
+ expected : `{"resourceToInfoMap":{}}` + "\n " ,
299
+ },
300
+ {
301
+ description : "empty manifest with more than one yaml page break notation returns empty resourceToInfoMap" ,
302
+ manifest : emptyManifestWithTwoBreaks ,
303
+ expected : `{"resourceToInfoMap":{}}` + "\n " ,
304
+ },
126
305
{
127
306
description : "actionable error" ,
128
307
manifest : manifest ,
0 commit comments