From 70a1b3b5133395b8e625fb3759c8f055ea8eac51 Mon Sep 17 00:00:00 2001 From: yxxhero <11087727+yxxhero@users.noreply.github.com> Date: Sat, 10 Dec 2022 10:54:03 +0800 Subject: [PATCH] Fix snapshot tests to pass regardless of helm version (#572) * Fix snapshot tests to pass regardless of helm version Signed-off-by: yxxhero --- pkg/helmexec/log.go | 4 +++- test/e2e/template/helmfile/snapshot_test.go | 8 ++++++- .../testdata/snapshot/pr_560/output.yaml | 23 +++++++++++-------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pkg/helmexec/log.go b/pkg/helmexec/log.go index 7b7b6f80..cf6dd5a9 100644 --- a/pkg/helmexec/log.go +++ b/pkg/helmexec/log.go @@ -23,6 +23,8 @@ type logWriter struct { } func (w *logWriter) Write(p []byte) (int, error) { - w.log.Debugf("%s%s", w.prefix, strings.TrimSpace(string(p))) + for _, line := range strings.Split(string(p), "\n") { + w.log.Debugf("%s%s", w.prefix, strings.TrimSpace(line)) + } return len(p), nil } diff --git a/test/e2e/template/helmfile/snapshot_test.go b/test/e2e/template/helmfile/snapshot_test.go index a38747a9..fa133799 100644 --- a/test/e2e/template/helmfile/snapshot_test.go +++ b/test/e2e/template/helmfile/snapshot_test.go @@ -23,6 +23,8 @@ import ( var ( // e.g. https_github_com_cloudposse_helmfiles_git.ref=0.xx.0 chartGitFullPathRegex = regexp.MustCompile(`chart=.*git\.ref=.*/charts/.*`) + // helm short version regex. e.g. v3.10.2+g50f003e + helmShortVersionRegex = regexp.MustCompile(`v\d+\.\d+\.\d+\+[a-z0-9]+`) ) type ociChart struct { @@ -188,10 +190,14 @@ func TestHelmfileTemplateWithBuildCommand(t *testing.T) { require.NoError(t, err, "Unable to run helmfile with args %v", args) gotStr := string(got) - gotStr = strings.ReplaceAll(gotStr, fmt.Sprintf("chart=%s", wd), "chart=$WD") + // Replace all random strings + + gotStr = strings.ReplaceAll(gotStr, fmt.Sprintf("chart=%s", wd), "chart=$WD") // Replace go-getter path with $GoGetterPath gotStr = chartGitFullPathRegex.ReplaceAllString(gotStr, `chart=$$GoGetterPath`) + // Replace helm version with $HelmVersion + gotStr = helmShortVersionRegex.ReplaceAllString(gotStr, `$$HelmVersion`) // OCI based helm charts are pulled and exported under temporary directory. // We are not sure the exact name of the temporary directory generated by helmfile, diff --git a/test/e2e/template/helmfile/testdata/snapshot/pr_560/output.yaml b/test/e2e/template/helmfile/testdata/snapshot/pr_560/output.yaml index 9441363e..ee75ffae 100644 --- a/test/e2e/template/helmfile/testdata/snapshot/pr_560/output.yaml +++ b/test/e2e/template/helmfile/testdata/snapshot/pr_560/output.yaml @@ -48,7 +48,8 @@ second-pass rendering result of "input.yaml.part.0": 17: merged environment: &{default map[] map[]} -helm> v3.10.2+g50f003e +helm> $HelmVersion +helm> Building dependency release=foo, chart=../../charts/raw-0.1.0 exec: helm dependency build ../../charts/raw-0.1.0 --skip-refresh 1 release(s) found in input.yaml @@ -83,16 +84,20 @@ skipping missing secrets file matching "git::https://github.com/helmfile/helmfil Templating release=foo, chart=../../charts/raw-0.1.0 exec: helm template foo ../../charts/raw-0.1.0 --values /tmp/helmfile/foo-values-79c7c784c9 --debug helm> install.go:192: [debug] Original chart version: "" +helm> helm> install.go:209: [debug] CHART PATH: /home/runner/work/helmfile/helmfile/test/e2e/template/helmfile/testdata/charts/raw-0.1.0 +helm> +helm> helm> --- -# Source: raw/templates/resources.yaml -apiVersion: v1 -kind: ConfigMap -metadata: - name: foo-1 - namespace: default -data: - foo: FOO +helm> # Source: raw/templates/resources.yaml +helm> apiVersion: v1 +helm> kind: ConfigMap +helm> metadata: +helm> name: foo-1 +helm> namespace: default +helm> data: +helm> foo: FOO +helm> --- # Source: raw/templates/resources.yaml apiVersion: v1