Fix code formatting in create_test.go

Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-10-22 02:57:23 +00:00 committed by Zubair Haque
parent 6b6baa223c
commit d576f9f65a
1 changed files with 111 additions and 111 deletions

View File

@ -533,17 +533,17 @@ releaseContext:
// TestHelmBinaryInBases tests that helmBinary and kustomizeBinary settings // TestHelmBinaryInBases tests that helmBinary and kustomizeBinary settings
// from bases are properly merged with later values overriding earlier ones // from bases are properly merged with later values overriding earlier ones
func TestHelmBinaryInBases(t *testing.T) { func TestHelmBinaryInBases(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
files map[string]string files map[string]string
mainFile string mainFile string
expectedHelmBinary string expectedHelmBinary string
expectedKustomizeBinary string expectedKustomizeBinary string
}{ }{
{ {
name: "helmBinary in second base should be used", name: "helmBinary in second base should be used",
files: map[string]string{ files: map[string]string{
"/path/to/helmfile.yaml": `bases: "/path/to/helmfile.yaml": `bases:
- ./bases/env.yaml - ./bases/env.yaml
--- ---
bases: bases:
@ -552,29 +552,29 @@ bases:
bases: bases:
- ./bases/releases.yaml - ./bases/releases.yaml
`, `,
"/path/to/bases/env.yaml": `environments: "/path/to/bases/env.yaml": `environments:
default: default:
values: values:
- key: value1 - key: value1
`, `,
"/path/to/bases/repos.yaml": `repositories: "/path/to/bases/repos.yaml": `repositories:
- name: stable - name: stable
url: https://charts.helm.sh/stable url: https://charts.helm.sh/stable
helmBinary: /path/to/custom/helm helmBinary: /path/to/custom/helm
`, `,
"/path/to/bases/releases.yaml": `releases: "/path/to/bases/releases.yaml": `releases:
- name: myapp - name: myapp
chart: stable/nginx chart: stable/nginx
`, `,
}, },
mainFile: "/path/to/helmfile.yaml", mainFile: "/path/to/helmfile.yaml",
expectedHelmBinary: "/path/to/custom/helm", expectedHelmBinary: "/path/to/custom/helm",
expectedKustomizeBinary: DefaultKustomizeBinary, expectedKustomizeBinary: DefaultKustomizeBinary,
}, },
{ {
name: "helmBinary in main file after bases should override", name: "helmBinary in main file after bases should override",
files: map[string]string{ files: map[string]string{
"/path/to/helmfile.yaml": `bases: "/path/to/helmfile.yaml": `bases:
- ./bases/env.yaml - ./bases/env.yaml
--- ---
bases: bases:
@ -584,29 +584,29 @@ bases:
- ./bases/releases.yaml - ./bases/releases.yaml
helmBinary: /path/to/main/helm helmBinary: /path/to/main/helm
`, `,
"/path/to/bases/env.yaml": `environments: "/path/to/bases/env.yaml": `environments:
default: default:
values: values:
- key: value1 - key: value1
`, `,
"/path/to/bases/repos.yaml": `repositories: "/path/to/bases/repos.yaml": `repositories:
- name: stable - name: stable
url: https://charts.helm.sh/stable url: https://charts.helm.sh/stable
helmBinary: /path/to/base/helm helmBinary: /path/to/base/helm
`, `,
"/path/to/bases/releases.yaml": `releases: "/path/to/bases/releases.yaml": `releases:
- name: myapp - name: myapp
chart: stable/nginx chart: stable/nginx
`, `,
}, },
mainFile: "/path/to/helmfile.yaml", mainFile: "/path/to/helmfile.yaml",
expectedHelmBinary: "/path/to/main/helm", expectedHelmBinary: "/path/to/main/helm",
expectedKustomizeBinary: DefaultKustomizeBinary, expectedKustomizeBinary: DefaultKustomizeBinary,
}, },
{ {
name: "helmBinary in main file between bases should override earlier bases", name: "helmBinary in main file between bases should override earlier bases",
files: map[string]string{ files: map[string]string{
"/path/to/helmfile.yaml": `bases: "/path/to/helmfile.yaml": `bases:
- ./bases/env.yaml - ./bases/env.yaml
--- ---
bases: bases:
@ -616,118 +616,118 @@ helmBinary: /path/to/middle/helm
bases: bases:
- ./bases/releases.yaml - ./bases/releases.yaml
`, `,
"/path/to/bases/env.yaml": `environments: "/path/to/bases/env.yaml": `environments:
default: default:
values: values:
- key: value1 - key: value1
`, `,
"/path/to/bases/repos.yaml": `repositories: "/path/to/bases/repos.yaml": `repositories:
- name: stable - name: stable
url: https://charts.helm.sh/stable url: https://charts.helm.sh/stable
helmBinary: /path/to/base/helm helmBinary: /path/to/base/helm
`, `,
"/path/to/bases/releases.yaml": `releases: "/path/to/bases/releases.yaml": `releases:
- name: myapp - name: myapp
chart: stable/nginx chart: stable/nginx
`, `,
}, },
mainFile: "/path/to/helmfile.yaml", mainFile: "/path/to/helmfile.yaml",
expectedHelmBinary: "/path/to/middle/helm", expectedHelmBinary: "/path/to/middle/helm",
expectedKustomizeBinary: DefaultKustomizeBinary, expectedKustomizeBinary: DefaultKustomizeBinary,
}, },
{ {
name: "kustomizeBinary in base should be used", name: "kustomizeBinary in base should be used",
files: map[string]string{ files: map[string]string{
"/path/to/helmfile.yaml": `bases: "/path/to/helmfile.yaml": `bases:
- ./bases/base.yaml - ./bases/base.yaml
`, `,
"/path/to/bases/base.yaml": `kustomizeBinary: /path/to/custom/kustomize "/path/to/bases/base.yaml": `kustomizeBinary: /path/to/custom/kustomize
releases: releases:
- name: myapp - name: myapp
chart: mychart chart: mychart
`, `,
}, },
mainFile: "/path/to/helmfile.yaml", mainFile: "/path/to/helmfile.yaml",
expectedHelmBinary: DefaultHelmBinary, expectedHelmBinary: DefaultHelmBinary,
expectedKustomizeBinary: "/path/to/custom/kustomize", expectedKustomizeBinary: "/path/to/custom/kustomize",
}, },
{ {
name: "both helmBinary and kustomizeBinary in different bases", name: "both helmBinary and kustomizeBinary in different bases",
files: map[string]string{ files: map[string]string{
"/path/to/helmfile.yaml": `bases: "/path/to/helmfile.yaml": `bases:
- ./bases/helm.yaml - ./bases/helm.yaml
--- ---
bases: bases:
- ./bases/kustomize.yaml - ./bases/kustomize.yaml
`, `,
"/path/to/bases/helm.yaml": `helmBinary: /path/to/custom/helm "/path/to/bases/helm.yaml": `helmBinary: /path/to/custom/helm
`, `,
"/path/to/bases/kustomize.yaml": `kustomizeBinary: /path/to/custom/kustomize "/path/to/bases/kustomize.yaml": `kustomizeBinary: /path/to/custom/kustomize
`, `,
}, },
mainFile: "/path/to/helmfile.yaml", mainFile: "/path/to/helmfile.yaml",
expectedHelmBinary: "/path/to/custom/helm", expectedHelmBinary: "/path/to/custom/helm",
expectedKustomizeBinary: "/path/to/custom/kustomize", expectedKustomizeBinary: "/path/to/custom/kustomize",
}, },
{ {
name: "later base overrides earlier base for helmBinary", name: "later base overrides earlier base for helmBinary",
files: map[string]string{ files: map[string]string{
"/path/to/helmfile.yaml": `bases: "/path/to/helmfile.yaml": `bases:
- ./bases/first.yaml - ./bases/first.yaml
--- ---
bases: bases:
- ./bases/second.yaml - ./bases/second.yaml
`, `,
"/path/to/bases/first.yaml": `helmBinary: /path/to/first/helm "/path/to/bases/first.yaml": `helmBinary: /path/to/first/helm
`, `,
"/path/to/bases/second.yaml": `helmBinary: /path/to/second/helm "/path/to/bases/second.yaml": `helmBinary: /path/to/second/helm
`, `,
}, },
mainFile: "/path/to/helmfile.yaml", mainFile: "/path/to/helmfile.yaml",
expectedHelmBinary: "/path/to/second/helm", expectedHelmBinary: "/path/to/second/helm",
expectedKustomizeBinary: DefaultKustomizeBinary, expectedKustomizeBinary: DefaultKustomizeBinary,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
testFs := testhelper.NewTestFs(tt.files) testFs := testhelper.NewTestFs(tt.files)
if testFs.Cwd == "" { if testFs.Cwd == "" {
testFs.Cwd = "/" testFs.Cwd = "/"
} }
r := remote.NewRemote(logger, testFs.Cwd, testFs.ToFileSystem()) r := remote.NewRemote(logger, testFs.Cwd, testFs.ToFileSystem())
creator := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", "", r, false, "") creator := NewCreator(logger, testFs.ToFileSystem(), nil, nil, "", "", r, false, "")
// Set up LoadFile for recursive base loading // Set up LoadFile for recursive base loading
creator.LoadFile = func(inheritedEnv, overrodeEnv *environment.Environment, baseDir, file string, evaluateBases bool) (*HelmState, error) { creator.LoadFile = func(inheritedEnv, overrodeEnv *environment.Environment, baseDir, file string, evaluateBases bool) (*HelmState, error) {
path := filepath.Join(baseDir, file) path := filepath.Join(baseDir, file)
content, ok := tt.files[path] content, ok := tt.files[path]
if !ok { if !ok {
return nil, fmt.Errorf("file not found: %s", path) return nil, fmt.Errorf("file not found: %s", path)
} }
return creator.ParseAndLoad([]byte(content), filepath.Dir(path), path, DefaultEnv, true, evaluateBases, inheritedEnv, overrodeEnv) return creator.ParseAndLoad([]byte(content), filepath.Dir(path), path, DefaultEnv, true, evaluateBases, inheritedEnv, overrodeEnv)
} }
yamlContent, ok := tt.files[tt.mainFile] yamlContent, ok := tt.files[tt.mainFile]
if !ok { if !ok {
t.Fatalf("no file named %q registered", tt.mainFile) t.Fatalf("no file named %q registered", tt.mainFile)
} }
state, err := creator.ParseAndLoad([]byte(yamlContent), filepath.Dir(tt.mainFile), tt.mainFile, DefaultEnv, true, true, nil, nil) state, err := creator.ParseAndLoad([]byte(yamlContent), filepath.Dir(tt.mainFile), tt.mainFile, DefaultEnv, true, true, nil, nil)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
} }
if state.DefaultHelmBinary != tt.expectedHelmBinary { if state.DefaultHelmBinary != tt.expectedHelmBinary {
t.Errorf("helmBinary mismatch: expected=%s, actual=%s", t.Errorf("helmBinary mismatch: expected=%s, actual=%s",
tt.expectedHelmBinary, state.DefaultHelmBinary) tt.expectedHelmBinary, state.DefaultHelmBinary)
} }
if state.DefaultKustomizeBinary != tt.expectedKustomizeBinary { if state.DefaultKustomizeBinary != tt.expectedKustomizeBinary {
t.Errorf("kustomizeBinary mismatch: expected=%s, actual=%s", t.Errorf("kustomizeBinary mismatch: expected=%s, actual=%s",
tt.expectedKustomizeBinary, state.DefaultKustomizeBinary) tt.expectedKustomizeBinary, state.DefaultKustomizeBinary)
} }
}) })
} }
} }