@@ -1812,7 +1812,6 @@ func TestAppReleaseManager_ExtractInstallableHelmCharts(t *testing.T) {
1812
1812
expectError bool
1813
1813
errorContains string
1814
1814
expected []types.InstallableHelmChart
1815
- validateCharts func (t * testing.T , charts []types.InstallableHelmChart , testHelmChartCRs [][]byte , testChartArchives [][]byte )
1816
1815
}{
1817
1816
{
1818
1817
name : "no helm charts returns empty slice" ,
@@ -1823,14 +1822,15 @@ func TestAppReleaseManager_ExtractInstallableHelmCharts(t *testing.T) {
1823
1822
expected : nil ,
1824
1823
},
1825
1824
{
1826
- name : "single chart with basic values " ,
1825
+ name : "single chart with basic configuration " ,
1827
1826
helmChartCRs : [][]byte {
1828
1827
[]byte (`apiVersion: kots.io/v1beta2
1829
1828
kind: HelmChart
1830
1829
metadata:
1831
1830
name: nginx-chart
1832
- namespace: default
1833
1831
spec:
1832
+ namespace: repl{{ConfigOption "namespace"}}
1833
+ releaseName: repl{{ConfigOption "release_name"}}
1834
1834
chart:
1835
1835
name: nginx
1836
1836
chartVersion: "1.0.0"
@@ -1853,6 +1853,8 @@ spec:
1853
1853
createTestChartArchive (t , "nginx" , "1.0.0" ),
1854
1854
},
1855
1855
configValues : types.AppConfigValues {
1856
+ "namespace" : {Value : "custom-namespace" },
1857
+ "release_name" : {Value : "custom-release-name" },
1856
1858
"image_tag" : {Value : "1.20.0" },
1857
1859
"enable_ingress" : {Value : "true" },
1858
1860
"ingress_host" : {Value : "nginx.example.com" },
@@ -1880,8 +1882,9 @@ spec:
1880
1882
kind: HelmChart
1881
1883
metadata:
1882
1884
name: nginx-chart
1883
- namespace: default
1884
1885
spec:
1886
+ namespace: custom-namespace
1887
+ releaseName: custom-release-name
1885
1888
chart:
1886
1889
name: nginx
1887
1890
chartVersion: "1.0.0"
@@ -1937,22 +1940,27 @@ spec:
1937
1940
"skip_nginx" : {Value : "true" },
1938
1941
},
1939
1942
expectError : false ,
1940
- validateCharts : func (t * testing.T , charts []types.InstallableHelmChart , testHelmChartCRs [][]byte , testChartArchives [][]byte ) {
1941
- expectedValues := map [string ]any {
1942
- "persistence" : map [string ]any {
1943
- "enabled" : true ,
1944
- },
1945
- }
1946
-
1947
- expectedCharts := []types.InstallableHelmChart {
1948
- {
1949
- Archive : testChartArchives [1 ], // redis chart (index 1)
1950
- Values : expectedValues ,
1951
- CR : createHelmChartCRFromYAML (string (testHelmChartCRs [1 ])), // redis CR (index 1)
1943
+ expected : []types.InstallableHelmChart {
1944
+ {
1945
+ Archive : createTestChartArchive (t , "redis" , "2.0.0" ),
1946
+ Values : map [string ]any {
1947
+ "persistence" : map [string ]any {
1948
+ "enabled" : true ,
1949
+ },
1952
1950
},
1953
- }
1954
-
1955
- assert .Equal (t , expectedCharts , charts )
1951
+ CR : createHelmChartCRFromYAML (`apiVersion: kots.io/v1beta2
1952
+ kind: HelmChart
1953
+ metadata:
1954
+ name: included-chart
1955
+ spec:
1956
+ chart:
1957
+ name: redis
1958
+ chartVersion: "2.0.0"
1959
+ exclude: false
1960
+ values:
1961
+ persistence:
1962
+ enabled: true` ),
1963
+ },
1956
1964
},
1957
1965
},
1958
1966
{
@@ -2262,9 +2270,7 @@ spec:
2262
2270
chartArchives : [][]byte {},
2263
2271
configValues : types.AppConfigValues {},
2264
2272
expectError : false ,
2265
- validateCharts : func (t * testing.T , charts []types.InstallableHelmChart , testHelmChartCRs [][]byte , testChartArchives [][]byte ) {
2266
- assert .Empty (t , charts )
2267
- },
2273
+ expected : nil ,
2268
2274
},
2269
2275
{
2270
2276
name : "skip nil helm chart CR in collection" ,
@@ -2286,20 +2292,23 @@ spec:
2286
2292
},
2287
2293
configValues : types.AppConfigValues {},
2288
2294
expectError : false ,
2289
- validateCharts : func (t * testing.T , charts []types.InstallableHelmChart , testHelmChartCRs [][]byte , testChartArchives [][]byte ) {
2290
- expectedValues := map [string ]any {
2291
- "replicaCount" : "2" ,
2292
- }
2293
-
2294
- expectedCharts := []types.InstallableHelmChart {
2295
- {
2296
- Archive : testChartArchives [0 ],
2297
- Values : expectedValues ,
2298
- CR : createHelmChartCRFromYAML (string (testHelmChartCRs [1 ])), // Skip the nil CR at index 0
2295
+ expected : []types.InstallableHelmChart {
2296
+ {
2297
+ Archive : createTestChartArchive (t , "nginx" , "1.0.0" ),
2298
+ Values : map [string ]any {
2299
+ "replicaCount" : "2" ,
2299
2300
},
2300
- }
2301
-
2302
- assert .Equal (t , expectedCharts , charts )
2301
+ CR : createHelmChartCRFromYAML (`apiVersion: kots.io/v1beta2
2302
+ kind: HelmChart
2303
+ metadata:
2304
+ name: valid-chart
2305
+ spec:
2306
+ chart:
2307
+ name: nginx
2308
+ chartVersion: "1.0.0"
2309
+ values:
2310
+ replicaCount: "2"` ),
2311
+ },
2303
2312
},
2304
2313
},
2305
2314
{
@@ -2420,12 +2429,8 @@ spec:
2420
2429
2421
2430
require .NoError (t , err )
2422
2431
2423
- // Use expectedInstallableCharts if provided, otherwise use validateCharts
2424
- if tt .expected != nil {
2425
- assert .Equal (t , tt .expected , result )
2426
- } else if tt .validateCharts != nil {
2427
- tt .validateCharts (t , result , tt .helmChartCRs , tt .chartArchives )
2428
- }
2432
+ // Validate expected results
2433
+ assert .Equal (t , tt .expected , result )
2429
2434
})
2430
2435
}
2431
2436
}
@@ -2557,6 +2562,8 @@ func createTestConfig() kotsv1beta1.Config {
2557
2562
Name : "test_group" ,
2558
2563
Items : []kotsv1beta1.ConfigItem {
2559
2564
{Name : "chart_name" , Type : "text" , Value : multitype .FromString ("nginx" )},
2565
+ {Name : "namespace" , Type : "text" , Value : multitype .FromString ("default-namespace" )},
2566
+ {Name : "release_name" , Type : "text" , Value : multitype .FromString ("default-release-name" )},
2560
2567
{Name : "image_tag" , Type : "text" , Value : multitype .FromString ("1.20.0" )},
2561
2568
{Name : "app_name" , Type : "text" , Value : multitype .FromString ("myapp" )},
2562
2569
{Name : "chart1_name" , Type : "text" , Value : multitype .FromString ("nginx" )},
0 commit comments