@@ -1500,6 +1500,20 @@ replicas: 1
15001500 require .NoError (t , err )
15011501 assert .NotEmpty (t , yaml )
15021502 assert .Equal (t , strings .TrimSpace (strings .ReplaceAll (expected , "\t " , " " )), strings .TrimSpace (string (yaml )))
1503+
1504+ // when image.spec.foo fields are missing in the target helm value file,
1505+ // they should be auto created without corrupting any other pre-existing elements.
1506+ originalData = []byte ("test-value1: one" )
1507+ expected = `
1508+ test-value1: one
1509+ image:
1510+ spec:
1511+ foo: nginx:v1.0.0
1512+ `
1513+ yaml , err = marshalParamsOverride (& app , originalData )
1514+ require .NoError (t , err )
1515+ assert .NotEmpty (t , yaml )
1516+ assert .Equal (t , strings .TrimSpace (strings .ReplaceAll (expected , "\t " , " " )), strings .TrimSpace (string (yaml )))
15031517 })
15041518
15051519 t .Run ("Valid Helm source with Helm values file with multiple images" , func (t * testing.T ) {
@@ -1588,6 +1602,25 @@ replicas: 1
15881602 require .NoError (t , err )
15891603 assert .NotEmpty (t , yaml )
15901604 assert .Equal (t , strings .TrimSpace (strings .ReplaceAll (expected , "\t " , " " )), strings .TrimSpace (string (yaml )))
1605+
1606+ // when nginx.* and redis.* fields are missing in the target helm value file,
1607+ // they should be auto created without corrupting any other pre-existing elements.
1608+ originalData = []byte ("test-value1: one" )
1609+ expected = `
1610+ test-value1: one
1611+ nginx:
1612+ image:
1613+ tag: v1.0.0
1614+ name: nginx
1615+ redis:
1616+ image:
1617+ tag: v1.0.0
1618+ name: redis
1619+ `
1620+ yaml , err = marshalParamsOverride (& app , originalData )
1621+ require .NoError (t , err )
1622+ assert .NotEmpty (t , yaml )
1623+ assert .Equal (t , strings .TrimSpace (strings .ReplaceAll (expected , "\t " , " " )), strings .TrimSpace (string (yaml )))
15911624 })
15921625
15931626 t .Run ("Valid Helm source with Helm values file with multiple aliases" , func (t * testing.T ) {
@@ -1695,6 +1728,7 @@ replicas: 1
16951728
16961729 t .Run ("Failed to setValue image parameter name" , func (t * testing.T ) {
16971730 expected := `
1731+ test-value1: one
16981732image:
16991733 name: nginx
17001734 tag: v1.0.0
@@ -1743,6 +1777,7 @@ replicas: 1
17431777 }
17441778
17451779 originalData := []byte (`
1780+ test-value1: one
17461781image:
17471782 name: nginx
17481783replicas: 1
0 commit comments