(t *testing.T)
| 124 | } |
| 125 | |
| 126 | func 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 | |
| 180 | func TestUpdateGoldenFiles(t *testing.T) { |
| 181 | t.Parallel() |
nothing calls this directly
no test coverage detected