MCPcopy Index your code
hub / github.com/coder/coder / TestRenderChart

Function TestRenderChart

helm/coder/tests/chart_test.go:180–232  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func TestRenderChart(t *testing.T) {
181 t.Parallel()
182 if *updateGoldenFiles {
183 t.Skip("Golden files are being updated. Skipping test.")
184 }
185 if testutil.InCI() {
186 switch runtime.GOOS {
187 case "windows", "darwin":
188 t.Skip("Skipping tests on Windows and macOS in CI")
189 }
190 }
191
192 // Ensure that Helm is available in $PATH
193 helmPath := lookupHelm(t)
194 err := updateHelmDependencies(t, helmPath, "..")
195 require.NoError(t, err, "failed to build Helm dependencies")
196
197 for _, tc := range testCases {
198 for _, ns := range namespaces {
199 tc.namespace = ns
200
201 t.Run(tc.namespace+"/"+tc.name, func(t *testing.T) {
202 t.Parallel()
203
204 // Ensure that the values file exists.
205 valuesFilePath := tc.valuesFilePath()
206 if _, err := os.Stat(valuesFilePath); os.IsNotExist(err) {
207 t.Fatalf("values file %q does not exist", valuesFilePath)
208 }
209
210 // Run helm template with the values file.
211 templateOutput, err := runHelmTemplate(t, helmPath, "..", valuesFilePath, tc.namespace)
212 if tc.expectedError != "" {
213 require.Error(t, err, "helm template should have failed")
214 require.Contains(t, templateOutput, tc.expectedError, "helm template output should contain expected error")
215 } else {
216 require.NoError(t, err, "helm template should not have failed")
217 require.NotEmpty(t, templateOutput, "helm template output should not be empty")
218 goldenFilePath := tc.goldenFilePath()
219 goldenBytes, err := os.ReadFile(goldenFilePath)
220 require.NoError(t, err, "failed to read golden file %q", goldenFilePath)
221
222 // Remove carriage returns to make tests pass on Windows.
223 goldenBytes = bytes.ReplaceAll(goldenBytes, []byte("\r"), []byte(""))
224 expected := string(goldenBytes)
225
226 require.NoError(t, err, "failed to load golden file %q")
227 require.Equal(t, expected, templateOutput)
228 }
229 })
230 }
231 }
232}
233
234func TestUpdateGoldenFiles(t *testing.T) {
235 t.Parallel()

Callers

nothing calls this directly

Calls 14

InCIFunction · 0.92
SkipMethod · 0.80
NotEmptyMethod · 0.80
lookupHelmFunction · 0.70
updateHelmDependenciesFunction · 0.70
runHelmTemplateFunction · 0.70
RunMethod · 0.65
ReadFileMethod · 0.65
valuesFilePathMethod · 0.45
FatalfMethod · 0.45
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected