MCPcopy Create free account
hub / github.com/Azure/draft / TestSubCharts

Function TestSubCharts

pkg/safeguards/preprocessing/preprocessing_test.go:77–117  ·  view source on GitHub ↗

Should successfully render a Helm chart with sub charts and be able to render subchart separately within a helm chart

(t *testing.T)

Source from the content-addressed store, hash-verified

75
76// Should successfully render a Helm chart with sub charts and be able to render subchart separately within a helm chart
77func TestSubCharts(t *testing.T) {
78 var opt chartutil.ReleaseOptions
79
80 manifestFiles, err := RenderHelmChart(false, consts.Subcharts, opt)
81 assert.Nil(t, err)
82
83 expectedFiles := make(map[string][]byte)
84 expectedFiles["maindeployment.yaml"] = getManifestAsBytes(t, "../tests/testmanifests/expected-mainchart.yaml")
85 expectedFiles["deployment1.yaml"] = getManifestAsBytes(t, "../tests/testmanifests/expected-subchart1.yaml")
86 expectedFiles["deployment2.yaml"] = getManifestAsBytes(t, "../tests/testmanifests/expected-subchart2.yaml")
87
88 for i, writtenManifestFile := range manifestFiles {
89 writtenFileName := manifestFiles[i].Name
90 expectedYaml := bytes.TrimSpace(expectedFiles[writtenFileName])
91 assert.Equal(t, bytes.TrimSpace(writtenManifestFile.ManifestContent), expectedYaml)
92 }
93
94 // Given a sub-chart dir, that specific sub chart only should be evaluated and rendered
95 _, err = RenderHelmChart(false, consts.SubchartDir, opt)
96 assert.Nil(t, err)
97
98 // Given a Chart.yaml in the main directory, main chart and subcharts should be evaluated
99 _, err = RenderHelmChart(true, consts.DirectPath_ToMainChartYaml, opt)
100 assert.Nil(t, err)
101
102 // Given path to a sub-Chart.yaml with a dependency on another subchart, should render both subcharts, but not the main chart
103 manifestFiles, err = RenderHelmChart(true, consts.DirectPath_ToSubchartYaml, opt)
104 assert.Nil(t, err)
105
106 expectedFiles = make(map[string][]byte)
107 expectedFiles["deployment1.yaml"] = getManifestAsBytes(t, "../tests/testmanifests/expected-subchart1.yaml")
108 expectedFiles["deployment2.yaml"] = getManifestAsBytes(t, "../tests/testmanifests/expected-subchart2.yaml")
109
110 assert.Equal(t, len(manifestFiles), 2)
111 for i, writtenManifestFile := range manifestFiles {
112 writtenFileName := manifestFiles[i].Name
113 expectedYaml := bytes.TrimSpace(expectedFiles[writtenFileName])
114 assert.Equal(t, bytes.TrimSpace(writtenManifestFile.ManifestContent), expectedYaml)
115 assert.NoFileExists(t, "maindeployment.yaml", "Unexpected file was created: maindeployment.yaml")
116 }
117}
118
119/**
120* Testing user errors

Callers

nothing calls this directly

Calls 2

RenderHelmChartFunction · 0.85
getManifestAsBytesFunction · 0.85

Tested by

no test coverage detected