@@ -1472,6 +1472,13 @@ replicas: 1
1472
1472
})
1473
1473
1474
1474
t .Run ("Failed to setValue image parameter name" , func (t * testing.T ) {
1475
+ expected := `
1476
+ image:
1477
+ name: nginx
1478
+ tag: v1.0.0
1479
+ replicas: 1
1480
+ `
1481
+
1475
1482
app := v1alpha1.Application {
1476
1483
ObjectMeta : v1.ObjectMeta {
1477
1484
Name : "testapp" ,
@@ -1514,16 +1521,24 @@ replicas: 1
1514
1521
}
1515
1522
1516
1523
originalData := []byte (`
1517
- image_name: nginx
1518
- image.tag: v0.0.0
1524
+ image:
1525
+ name: nginx
1519
1526
replicas: 1
1520
1527
` )
1521
- _ , err := marshalParamsOverride (& app , originalData )
1522
- assert .Error (t , err )
1523
- assert .Equal (t , "failed to set image parameter name value: key image not found in the map" , err .Error ())
1528
+
1529
+ yaml , err := marshalParamsOverride (& app , originalData )
1530
+ require .NoError (t , err )
1531
+ assert .NotEmpty (t , yaml )
1532
+ assert .Equal (t , strings .TrimSpace (strings .ReplaceAll (expected , "\t " , " " )), strings .TrimSpace (string (yaml )))
1524
1533
})
1525
1534
1526
1535
t .Run ("Failed to setValue image parameter version" , func (t * testing.T ) {
1536
+ expected := `
1537
+ image:
1538
+ tag: v1.0.0
1539
+ name: nginx
1540
+ replicas: 1
1541
+ `
1527
1542
app := v1alpha1.Application {
1528
1543
ObjectMeta : v1.ObjectMeta {
1529
1544
Name : "testapp" ,
@@ -1566,13 +1581,15 @@ replicas: 1
1566
1581
}
1567
1582
1568
1583
originalData := []byte (`
1569
- image.name: nginx
1570
- image_tag : v0.0.0
1584
+ image:
1585
+ tag : v0.0.0
1571
1586
replicas: 1
1572
1587
` )
1573
- _ , err := marshalParamsOverride (& app , originalData )
1574
- assert .Error (t , err )
1575
- assert .Equal (t , "failed to set image parameter version value: key image not found in the map" , err .Error ())
1588
+
1589
+ yaml , err := marshalParamsOverride (& app , originalData )
1590
+ require .NoError (t , err )
1591
+ assert .NotEmpty (t , yaml )
1592
+ assert .Equal (t , strings .TrimSpace (strings .ReplaceAll (expected , "\t " , " " )), strings .TrimSpace (string (yaml )))
1576
1593
})
1577
1594
1578
1595
t .Run ("Missing annotation image-tag for helmvalues write-back-target" , func (t * testing.T ) {
@@ -1865,7 +1882,7 @@ func Test_SetHelmValue(t *testing.T) {
1865
1882
key := "image.attributes.tag"
1866
1883
value := "v2.0.0"
1867
1884
1868
- err := setHelmValue (input , key , value )
1885
+ err := setHelmValue (& input , key , value )
1869
1886
require .NoError (t , err )
1870
1887
assert .Equal (t , expected , input )
1871
1888
})
@@ -1881,23 +1898,72 @@ func Test_SetHelmValue(t *testing.T) {
1881
1898
key := "image.attributes.tag"
1882
1899
value := "v2.0.0"
1883
1900
1884
- err := setHelmValue (input , key , value )
1901
+ err := setHelmValue (& input , key , value )
1885
1902
require .NoError (t , err )
1886
1903
assert .Equal (t , expected , input )
1887
1904
})
1888
1905
1889
1906
t .Run ("Key not found" , func (t * testing.T ) {
1907
+ expected := yaml.MapSlice {
1908
+ {Key : "image" , Value : yaml.MapSlice {
1909
+ {Key : "attributes" , Value : yaml.MapSlice {
1910
+ {Key : "name" , Value : "repo-name" },
1911
+ {Key : "tag" , Value : "v2.0.0" },
1912
+ }},
1913
+ }},
1914
+ }
1915
+
1890
1916
input := yaml.MapSlice {
1891
1917
{Key : "image" , Value : yaml.MapSlice {
1892
- {Key : "tag" , Value : "v1.0.0" },
1918
+ {Key : "attributes" , Value : yaml.MapSlice {
1919
+ {Key : "name" , Value : "repo-name" },
1920
+ }},
1893
1921
}},
1894
1922
}
1923
+
1895
1924
key := "image.attributes.tag"
1896
1925
value := "v2.0.0"
1897
1926
1898
- err := setHelmValue (input , key , value )
1899
- assert .Error (t , err )
1900
- assert .Equal (t , "key attributes not found in the map" , err .Error ())
1927
+ err := setHelmValue (& input , key , value )
1928
+ require .NoError (t , err )
1929
+ assert .Equal (t , expected , input )
1930
+ })
1931
+
1932
+ t .Run ("Root key not found" , func (t * testing.T ) {
1933
+ expected := yaml.MapSlice {
1934
+ {Key : "name" , Value : "repo-name" },
1935
+ {Key : "tag" , Value : "v2.0.0" },
1936
+ }
1937
+
1938
+ input := yaml.MapSlice {
1939
+ {Key : "name" , Value : "repo-name" },
1940
+ }
1941
+
1942
+ key := "tag"
1943
+ value := "v2.0.0"
1944
+
1945
+ err := setHelmValue (& input , key , value )
1946
+ require .NoError (t , err )
1947
+ assert .Equal (t , expected , input )
1948
+ })
1949
+
1950
+ t .Run ("Empty values with deep key" , func (t * testing.T ) {
1951
+ expected := yaml.MapSlice {
1952
+ {Key : "image" , Value : yaml.MapSlice {
1953
+ {Key : "attributes" , Value : yaml.MapSlice {
1954
+ {Key : "tag" , Value : "v2.0.0" },
1955
+ }},
1956
+ }},
1957
+ }
1958
+
1959
+ input := yaml.MapSlice {}
1960
+
1961
+ key := "image.attributes.tag"
1962
+ value := "v2.0.0"
1963
+
1964
+ err := setHelmValue (& input , key , value )
1965
+ require .NoError (t , err )
1966
+ assert .Equal (t , expected , input )
1901
1967
})
1902
1968
1903
1969
t .Run ("Unexpected type for key" , func (t * testing.T ) {
@@ -1909,7 +1975,7 @@ func Test_SetHelmValue(t *testing.T) {
1909
1975
key := "image.attributes.tag"
1910
1976
value := "v2.0.0"
1911
1977
1912
- err := setHelmValue (input , key , value )
1978
+ err := setHelmValue (& input , key , value )
1913
1979
assert .Error (t , err )
1914
1980
assert .Equal (t , "unexpected type string for key attributes" , err .Error ())
1915
1981
})
0 commit comments