@@ -54,7 +54,7 @@ var testDeployConfig = &v1alpha2.HelmDeploy{
54
54
Name : "skaffold-helm" ,
55
55
ChartPath : "examples/test" ,
56
56
Values : map [string ]string {
57
- "image.tag " : "skaffold-helm" ,
57
+ "image" : "skaffold-helm" ,
58
58
},
59
59
Overrides : map [string ]interface {}{
60
60
"foo" : "bar" ,
@@ -66,13 +66,36 @@ var testDeployConfig = &v1alpha2.HelmDeploy{
66
66
},
67
67
}
68
68
69
+ var testDeployHelmStyleConfig = & v1alpha2.HelmDeploy {
70
+ Releases : []v1alpha2.HelmRelease {
71
+ {
72
+ Name : "skaffold-helm" ,
73
+ ChartPath : "examples/test" ,
74
+ Values : map [string ]string {
75
+ "image" : "skaffold-helm" ,
76
+ },
77
+ Overrides : map [string ]interface {}{
78
+ "foo" : "bar" ,
79
+ },
80
+ SetValues : map [string ]string {
81
+ "some.key" : "somevalue" ,
82
+ },
83
+ ImageStrategy : v1alpha2.HelmImageStrategy {
84
+ HelmImageConfig : v1alpha2.HelmImageConfig {
85
+ HelmConventionConfig : & v1alpha2.HelmConventionConfig {},
86
+ },
87
+ },
88
+ },
89
+ },
90
+ }
91
+
69
92
var testDeployConfigParameterUnmatched = & v1alpha2.HelmDeploy {
70
93
Releases : []v1alpha2.HelmRelease {
71
94
{
72
95
Name : "skaffold-helm" ,
73
96
ChartPath : "examples/test" ,
74
97
Values : map [string ]string {
75
- "image.tag " : "skaffold-helm-unmatched" ,
98
+ "image" : "skaffold-helm-unmatched" ,
76
99
},
77
100
},
78
101
},
@@ -84,7 +107,7 @@ var testDeployFooWithPackaged = &v1alpha2.HelmDeploy{
84
107
Name : "foo" ,
85
108
ChartPath : "testdata/foo" ,
86
109
Values : map [string ]string {
87
- "image.tag " : "foo" ,
110
+ "image" : "foo" ,
88
111
},
89
112
Packaged : & v1alpha2.HelmPackaged {
90
113
Version : "0.1.2" ,
@@ -222,13 +245,42 @@ func TestHelmDeploy(t *testing.T) {
222
245
{
223
246
description : "get failure should install not upgrade" ,
224
247
cmd : & MockHelm {
225
- t : t ,
226
- getResult : fmt .Errorf ("not found" ),
248
+ t : t ,
249
+ getResult : fmt .Errorf ("not found" ),
250
+ installMatcher : func (cmd * exec.Cmd ) bool {
251
+ expected := map [string ]bool {fmt .Sprintf ("image=%s" , testBuilds [0 ].Tag ): true }
252
+ for _ , arg := range cmd .Args {
253
+ if expected [arg ] {
254
+ return true
255
+ }
256
+ }
257
+ return false
258
+ },
227
259
upgradeResult : fmt .Errorf ("should not have called upgrade" ),
228
260
},
229
261
deployer : NewHelmDeployer (testDeployConfig , testKubeContext , testNamespace ),
230
262
builds : testBuilds ,
231
263
},
264
+ {
265
+ description : "get failure should install not upgrade with helm image strategy" ,
266
+ cmd : & MockHelm {
267
+ t : t ,
268
+ getResult : fmt .Errorf ("not found" ),
269
+ installMatcher : func (cmd * exec.Cmd ) bool {
270
+ builds := strings .Split (testBuilds [0 ].Tag , ":" )
271
+ expected := map [string ]bool {fmt .Sprintf ("image.repository=%s,image.tag=%s" , builds [0 ], builds [1 ]): true }
272
+ for _ , arg := range cmd .Args {
273
+ if expected [arg ] {
274
+ return true
275
+ }
276
+ }
277
+ return false
278
+ },
279
+ upgradeResult : fmt .Errorf ("should not have called upgrade" ),
280
+ },
281
+ deployer : NewHelmDeployer (testDeployHelmStyleConfig , testKubeContext , testNamespace ),
282
+ builds : testBuilds ,
283
+ },
232
284
{
233
285
description : "get success should upgrade not install" ,
234
286
cmd : & MockHelm {
@@ -305,13 +357,18 @@ func TestHelmDeploy(t *testing.T) {
305
357
}
306
358
}
307
359
360
+ type CommandMatcher func (* exec.Cmd ) bool
361
+
308
362
type MockHelm struct {
309
363
t * testing.T
310
364
311
- getResult error
312
- installResult error
313
- upgradeResult error
314
- depResult error
365
+ getResult error
366
+ getMatcher CommandMatcher
367
+ installResult error
368
+ installMatcher CommandMatcher
369
+ upgradeResult error
370
+ upgradeMatcher CommandMatcher
371
+ depResult error
315
372
316
373
packageOut io.Reader
317
374
packageResult error
@@ -339,10 +396,19 @@ func (m *MockHelm) RunCmd(c *exec.Cmd) error {
339
396
340
397
switch c .Args [3 ] {
341
398
case "get" :
399
+ if m .getMatcher != nil && ! m .getMatcher (c ) {
400
+ m .t .Errorf ("get matcher failed to match cmd" )
401
+ }
342
402
return m .getResult
343
403
case "install" :
404
+ if m .installMatcher != nil && ! m .installMatcher (c ) {
405
+ m .t .Errorf ("install matcher failed to match cmd" )
406
+ }
344
407
return m .installResult
345
408
case "upgrade" :
409
+ if m .upgradeMatcher != nil && ! m .upgradeMatcher (c ) {
410
+ m .t .Errorf ("upgrade matcher failed to match cmd" )
411
+ }
346
412
return m .upgradeResult
347
413
case "dep" :
348
414
return m .depResult
0 commit comments