Skip to content

Commit cd019b9

Browse files
sgalsalehemosbaugh
authored andcommitted
Update milestone 7 proposal and improve some tests (#2748)
* Update milestone 7 proposal and improve some tests * fix namespace in test * fix release name in tests
1 parent 1290ed1 commit cd019b9

File tree

2 files changed

+605
-173
lines changed

2 files changed

+605
-173
lines changed

api/internal/managers/app/release/template_test.go

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,6 @@ func TestAppReleaseManager_ExtractInstallableHelmCharts(t *testing.T) {
18121812
expectError bool
18131813
errorContains string
18141814
expected []types.InstallableHelmChart
1815-
validateCharts func(t *testing.T, charts []types.InstallableHelmChart, testHelmChartCRs [][]byte, testChartArchives [][]byte)
18161815
}{
18171816
{
18181817
name: "no helm charts returns empty slice",
@@ -1823,14 +1822,15 @@ func TestAppReleaseManager_ExtractInstallableHelmCharts(t *testing.T) {
18231822
expected: nil,
18241823
},
18251824
{
1826-
name: "single chart with basic values",
1825+
name: "single chart with basic configuration",
18271826
helmChartCRs: [][]byte{
18281827
[]byte(`apiVersion: kots.io/v1beta2
18291828
kind: HelmChart
18301829
metadata:
18311830
name: nginx-chart
1832-
namespace: default
18331831
spec:
1832+
namespace: repl{{ConfigOption "namespace"}}
1833+
releaseName: repl{{ConfigOption "release_name"}}
18341834
chart:
18351835
name: nginx
18361836
chartVersion: "1.0.0"
@@ -1853,6 +1853,8 @@ spec:
18531853
createTestChartArchive(t, "nginx", "1.0.0"),
18541854
},
18551855
configValues: types.AppConfigValues{
1856+
"namespace": {Value: "custom-namespace"},
1857+
"release_name": {Value: "custom-release-name"},
18561858
"image_tag": {Value: "1.20.0"},
18571859
"enable_ingress": {Value: "true"},
18581860
"ingress_host": {Value: "nginx.example.com"},
@@ -1880,8 +1882,9 @@ spec:
18801882
kind: HelmChart
18811883
metadata:
18821884
name: nginx-chart
1883-
namespace: default
18841885
spec:
1886+
namespace: custom-namespace
1887+
releaseName: custom-release-name
18851888
chart:
18861889
name: nginx
18871890
chartVersion: "1.0.0"
@@ -1937,22 +1940,27 @@ spec:
19371940
"skip_nginx": {Value: "true"},
19381941
},
19391942
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+
},
19521950
},
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+
},
19561964
},
19571965
},
19581966
{
@@ -2262,9 +2270,7 @@ spec:
22622270
chartArchives: [][]byte{},
22632271
configValues: types.AppConfigValues{},
22642272
expectError: false,
2265-
validateCharts: func(t *testing.T, charts []types.InstallableHelmChart, testHelmChartCRs [][]byte, testChartArchives [][]byte) {
2266-
assert.Empty(t, charts)
2267-
},
2273+
expected: nil,
22682274
},
22692275
{
22702276
name: "skip nil helm chart CR in collection",
@@ -2286,20 +2292,23 @@ spec:
22862292
},
22872293
configValues: types.AppConfigValues{},
22882294
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",
22992300
},
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+
},
23032312
},
23042313
},
23052314
{
@@ -2420,12 +2429,8 @@ spec:
24202429

24212430
require.NoError(t, err)
24222431

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)
24292434
})
24302435
}
24312436
}
@@ -2557,6 +2562,8 @@ func createTestConfig() kotsv1beta1.Config {
25572562
Name: "test_group",
25582563
Items: []kotsv1beta1.ConfigItem{
25592564
{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")},
25602567
{Name: "image_tag", Type: "text", Value: multitype.FromString("1.20.0")},
25612568
{Name: "app_name", Type: "text", Value: multitype.FromString("myapp")},
25622569
{Name: "chart1_name", Type: "text", Value: multitype.FromString("nginx")},

0 commit comments

Comments
 (0)