Fix snapshot tests to pass regardless of helm version (#572)

* Fix snapshot tests to pass regardless of helm version

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2022-12-10 10:54:03 +08:00 committed by GitHub
parent 398c812e49
commit 70a1b3b513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 11 deletions

View File

@ -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
}

View File

@ -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,

View File

@ -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