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:
		
							parent
							
								
									398c812e49
								
							
						
					
					
						commit
						70a1b3b513
					
				|  | @ -23,6 +23,8 @@ type logWriter struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (w *logWriter) Write(p []byte) (int, error) { | 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 | 	return len(p), nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -23,6 +23,8 @@ import ( | ||||||
| var ( | var ( | ||||||
| 	// e.g. https_github_com_cloudposse_helmfiles_git.ref=0.xx.0
 | 	// e.g. https_github_com_cloudposse_helmfiles_git.ref=0.xx.0
 | ||||||
| 	chartGitFullPathRegex = regexp.MustCompile(`chart=.*git\.ref=.*/charts/.*`) | 	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 { | type ociChart struct { | ||||||
|  | @ -188,10 +190,14 @@ func TestHelmfileTemplateWithBuildCommand(t *testing.T) { | ||||||
| 			require.NoError(t, err, "Unable to run helmfile with args %v", args) | 			require.NoError(t, err, "Unable to run helmfile with args %v", args) | ||||||
| 
 | 
 | ||||||
| 			gotStr := string(got) | 			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
 | 			// Replace go-getter path with $GoGetterPath
 | ||||||
| 			gotStr = chartGitFullPathRegex.ReplaceAllString(gotStr, `chart=$$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.
 | 			// 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,
 | 			// We are not sure the exact name of the temporary directory generated by helmfile,
 | ||||||
|  |  | ||||||
|  | @ -48,7 +48,8 @@ second-pass rendering result of "input.yaml.part.0": | ||||||
| 17:  | 17:  | ||||||
| 
 | 
 | ||||||
| merged environment: &{default map[] map[]} | merged environment: &{default map[] map[]} | ||||||
| helm> v3.10.2+g50f003e | helm> $HelmVersion | ||||||
|  | helm>  | ||||||
| Building dependency release=foo, chart=../../charts/raw-0.1.0 | Building dependency release=foo, chart=../../charts/raw-0.1.0 | ||||||
| exec: helm dependency build ../../charts/raw-0.1.0 --skip-refresh | exec: helm dependency build ../../charts/raw-0.1.0 --skip-refresh | ||||||
| 1 release(s) found in input.yaml | 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 | 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 | 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> 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> install.go:209: [debug] CHART PATH: /home/runner/work/helmfile/helmfile/test/e2e/template/helmfile/testdata/charts/raw-0.1.0 | ||||||
|  | helm>  | ||||||
|  | helm>  | ||||||
| helm> --- | helm> --- | ||||||
| # Source: raw/templates/resources.yaml | helm> # Source: raw/templates/resources.yaml | ||||||
| apiVersion: v1 | helm> apiVersion: v1 | ||||||
| kind: ConfigMap | helm> kind: ConfigMap | ||||||
| metadata: | helm> metadata: | ||||||
|   name: foo-1 | helm> name: foo-1 | ||||||
|   namespace: default | helm> namespace: default | ||||||
| data: | helm> data: | ||||||
|   foo: FOO | helm> foo: FOO | ||||||
|  | helm>  | ||||||
| --- | --- | ||||||
| # Source: raw/templates/resources.yaml | # Source: raw/templates/resources.yaml | ||||||
| apiVersion: v1 | apiVersion: v1 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue