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

Function TestRenderChart

helm/provisioner/tests/chart_test.go:126–178  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestRenderChart(t *testing.T) {
127 t.Parallel()
128 if *updateGoldenFiles {
129 t.Skip("Golden files are being updated. Skipping test.")
130 }
131 if testutil.InCI() {
132 switch runtime.GOOS {
133 case "windows", "darwin":
134 t.Skip("Skipping tests on Windows and macOS in CI")
135 }
136 }
137
138 // Ensure that Helm is available in $PATH
139 helmPath := lookupHelm(t)
140 err := updateHelmDependencies(t, helmPath, "..")
141 require.NoError(t, err, "failed to build Helm dependencies")
142
143 for _, tc := range testCases {
144 for _, ns := range namespaces {
145 tc.namespace = ns
146
147 t.Run(tc.namespace+"/"+tc.name, func(t *testing.T) {
148 t.Parallel()
149
150 // Ensure that the values file exists.
151 valuesFilePath := tc.valuesFilePath()
152 if _, err := os.Stat(valuesFilePath); os.IsNotExist(err) {
153 t.Fatalf("values file %q does not exist", valuesFilePath)
154 }
155
156 // Run helm template with the values file.
157 templateOutput, err := runHelmTemplate(t, helmPath, "..", valuesFilePath, tc.namespace)
158 if tc.expectedError != "" {
159 require.Error(t, err, "helm template should have failed")
160 require.Contains(t, templateOutput, tc.expectedError, "helm template output should contain expected error")
161 } else {
162 require.NoError(t, err, "helm template should not have failed")
163 require.NotEmpty(t, templateOutput, "helm template output should not be empty")
164 goldenFilePath := tc.goldenFilePath()
165 goldenBytes, err := os.ReadFile(goldenFilePath)
166 require.NoError(t, err, "failed to read golden file %q", goldenFilePath)
167
168 // Remove carriage returns to make tests pass on Windows.
169 goldenBytes = bytes.ReplaceAll(goldenBytes, []byte("\r"), []byte(""))
170 expected := string(goldenBytes)
171
172 require.NoError(t, err, "failed to load golden file %q")
173 require.Equal(t, expected, templateOutput)
174 }
175 })
176 }
177 }
178}
179
180func TestUpdateGoldenFiles(t *testing.T) {
181 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