diff --git a/src/test/common.go b/src/test/common.go index 34d877c659..c683db5807 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -130,11 +130,14 @@ func (e2e *ZarfE2ETest) GetZarfVersion(t *testing.T) string { return strings.Trim(stdOut, "\n") } -// StripANSICodes strips any ANSI color codes from a given string -func (e2e *ZarfE2ETest) StripANSICodes(input string) string { +// StripMessageFormatting strips any ANSI color codes from a given string +func (e2e *ZarfE2ETest) StripMessageFormatting(input string) string { // Regex to strip any color codes from the output - https://regex101.com/r/YFyIwC/2 ansiRegex := regexp.MustCompile(`\x1b\[(.*?)m`) - return ansiRegex.ReplaceAllString(input, "") + unAnsiInput := ansiRegex.ReplaceAllString(input, "") + // Regex to strip any more than two spaces or newline - https://regex101.com/r/wqQmys/1 + multiSpaceRegex := regexp.MustCompile(`\s{2,}|\n`) + return multiSpaceRegex.ReplaceAllString(unAnsiInput, " ") } // NormalizeYAMLFilenames normalizes YAML filenames / paths across Operating Systems (i.e Windows vs Linux) diff --git a/src/test/e2e/25_helm_test.go b/src/test/e2e/25_helm_test.go index 8bd117e013..b76e2644c6 100644 --- a/src/test/e2e/25_helm_test.go +++ b/src/test/e2e/25_helm_test.go @@ -46,15 +46,15 @@ func testHelmChartsExample(t *testing.T) { evilChartDepsPath := filepath.Join("src", "test", "packages", "25-evil-chart-deps") stdOut, stdErr, err = e2e.Zarf("package", "create", evilChartDepsPath, "--tmpdir", tmpdir, "--confirm") require.Error(t, err, stdOut, stdErr) - require.Contains(t, e2e.StripANSICodes(stdErr), "could not download\n https://charts.jetstack.io/charts/cert-manager-v1.11.1.tgz") + require.Contains(t, e2e.StripMessageFormatting(stdErr), "could not download https://charts.jetstack.io/charts/cert-manager-v1.11.1.tgz") require.FileExists(t, filepath.Join(evilChartDepsPath, "good-chart", "charts", "gitlab-runner-0.55.0.tgz")) // Create a package with a chart name that doesn't exist in a repo evilChartLookupPath := filepath.Join("src", "test", "packages", "25-evil-chart-lookup") stdOut, stdErr, err = e2e.Zarf("package", "create", evilChartLookupPath, "--tmpdir", tmpdir, "--confirm") require.Error(t, err, stdOut, stdErr) - require.Contains(t, e2e.StripANSICodes(stdErr), "chart \"asdf\" version \"6.4.0\" not found") - require.Contains(t, e2e.StripANSICodes(stdErr), "Available charts and versions from \"https://stefanprodan.github.io/podinfo\":") + require.Contains(t, e2e.StripMessageFormatting(stdErr), "chart \"asdf\" version \"6.4.0\" not found") + require.Contains(t, e2e.StripMessageFormatting(stdErr), "Available charts and versions from \"https://stefanprodan.github.io/podinfo\":") // Create the package with a registry override stdOut, stdErr, err = e2e.Zarf("package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io=docker.io", "--tmpdir", tmpdir, "--confirm") diff --git a/src/test/e2e/29_mismatched_checks_test.go b/src/test/e2e/29_mismatched_checks_test.go index 2ce08b44c0..0522f5c04f 100644 --- a/src/test/e2e/29_mismatched_checks_test.go +++ b/src/test/e2e/29_mismatched_checks_test.go @@ -35,7 +35,7 @@ func TestMismatchedArchitectures(t *testing.T) { // Ensure zarf package deploy returns an error because of the mismatched architectures. _, stdErr, err = e2e.Zarf("package", "deploy", mismatchedGamesPackage, "--confirm") require.Error(t, err, stdErr) - require.Contains(t, stdErr, expectedErrorMessage) + require.Contains(t, e2e.StripMessageFormatting(stdErr), expectedErrorMessage) } // TestMismatchedVersions ensures that zarf produces a warning