(t *testing.T)
| 178 | } |
| 179 | |
| 180 | func 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 | |
| 234 | func TestUpdateGoldenFiles(t *testing.T) { |
| 235 | t.Parallel() |
nothing calls this directly
no test coverage detected