Files
helmfile/pkg/app/app_parallel_test.go
T
yxxheroandClaude ad81e4231e build: update Go to 1.27.1 and modernize the codebase (#2798)
Toolchain and CI:
- Bump go directive from 1.26.8 to 1.27.1 (go.mod)
- Use golang:1.27-alpine builder images in all Dockerfiles
- Bump golangci-lint to v2.13.2 (first release with go1.27 support)
- Add CI gate: `go fix -diff` fails when outdated Go patterns are
  detected (locally: `make check-modernize`)

Note: darwin binaries now require macOS 13 or later.

Lint fixes required by golangci-lint v2.13.2:
- goconst: ignore tests (all 436 findings were test-only; goconst
  got stricter since v2.12 and this option was added for it)
- openai.go: keep deprecated MaxTokens deliberately with a nolint
  rationale (max_tokens is the only form universally supported by
  OpenAI-compatible backends like One-API, LiteLLM, Ollama shim)
- state.go: drop always-nil flags param from appendChartVersionFlags
  (renamed to chartVersionFlags, unparam)

Modernization (go fix ./..., 62 files):
- interface{} -> any, maps.Copy, strings.SplitSeq, range-over-int,
  builtin min/max, slices.Contains/ContainsFunc/Sort, WaitGroup.Go,
  reflect.Type.Fields(), new(expr)
- exit_error.go: strings.Builder + fmt.Fprintf instead of string
  concatenation and WriteString(fmt.Sprintf(...)) (QF1012)
- chart_dependency.go: strings.CutLast for OCI dependency helpers

Signed-off-by: yxxhero <aiopsclub@163.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-09-16 13:29:02 +08:00

158 lines
4.1 KiB
Go

package app
import (
"bytes"
"testing"
"github.com/helmfile/vals"
ffs "github.com/helmfile/helmfile/pkg/filesystem"
"github.com/helmfile/helmfile/pkg/helmexec"
"github.com/helmfile/helmfile/pkg/testhelper"
"github.com/helmfile/helmfile/pkg/testutil"
)
// TestParallelProcessingDeterministicOutput verifies that ListReleases produces
// consistent sorted output even with parallel processing of multiple helmfile.d files
func TestParallelProcessingDeterministicOutput(t *testing.T) {
files := map[string]string{
"/path/to/helmfile.d/z-last.yaml": `
releases:
- name: zulu-release
chart: stable/chart-z
namespace: ns-z
`,
"/path/to/helmfile.d/a-first.yaml": `
releases:
- name: alpha-release
chart: stable/chart-a
namespace: ns-a
`,
"/path/to/helmfile.d/m-middle.yaml": `
releases:
- name: mike-release
chart: stable/chart-m
namespace: ns-m
`,
}
// Run ListReleases multiple times to verify consistent ordering
var outputs []string
for i := range 5 {
var buffer bytes.Buffer
syncWriter := testhelper.NewSyncWriter(&buffer)
logger := helmexec.NewLogger(syncWriter, "debug")
valsRuntime, err := vals.New(vals.Options{CacheSize: 32})
if err != nil {
t.Fatalf("unexpected error creating vals runtime: %v", err)
}
app := appWithFs(&App{
OverrideHelmBinary: DefaultHelmBinary,
fs: ffs.DefaultFileSystem(),
OverrideKubeContext: "default",
DisableKubeVersionAutoDetection: true,
Env: "default",
Logger: logger,
valsRuntime: valsRuntime,
FileOrDir: "/path/to/helmfile.d",
}, files)
expectNoCallsToHelm(app)
err = app.ListReleases(configImpl{
skipCharts: false,
output: "table",
})
if err != nil {
t.Fatalf("unexpected error on iteration %d: %v", i, err)
}
outputs = append(outputs, buffer.String())
}
// Verify all outputs are identical (deterministic)
firstOutput := outputs[0]
for i, output := range outputs[1:] {
if output != firstOutput {
t.Errorf("output %d differs from first output (non-deterministic ordering)", i+1)
t.Logf("First output:\n%s", firstOutput)
t.Logf("Output %d:\n%s", i+1, output)
}
}
}
// TestMultipleHelmfileDFiles verifies that all files in helmfile.d are processed
func TestMultipleHelmfileDFiles(t *testing.T) {
files := map[string]string{
"/path/to/helmfile.d/001-app.yaml": `
releases:
- name: app1
chart: stable/app1
namespace: default
`,
"/path/to/helmfile.d/002-db.yaml": `
releases:
- name: db1
chart: stable/postgresql
namespace: default
`,
"/path/to/helmfile.d/003-cache.yaml": `
releases:
- name: cache1
chart: stable/redis
namespace: default
`,
}
var buffer bytes.Buffer
syncWriter := testhelper.NewSyncWriter(&buffer)
logger := helmexec.NewLogger(syncWriter, "debug")
valsRuntime, err := vals.New(vals.Options{CacheSize: 32})
if err != nil {
t.Fatalf("unexpected error creating vals runtime: %v", err)
}
app := appWithFs(&App{
OverrideHelmBinary: DefaultHelmBinary,
fs: ffs.DefaultFileSystem(),
OverrideKubeContext: "default",
DisableKubeVersionAutoDetection: true,
Env: "default",
Logger: logger,
valsRuntime: valsRuntime,
FileOrDir: "/path/to/helmfile.d",
}, files)
expectNoCallsToHelm(app)
// Capture stdout since ListReleases outputs to stdout
out, err := testutil.CaptureStdout(func() {
err := app.ListReleases(configImpl{
skipCharts: false,
output: "json",
})
if err != nil {
t.Logf("ListReleases error: %v", err)
}
})
if err != nil {
t.Fatalf("unexpected error capturing output: %v", err)
}
// Verify all three releases are present in output (JSON format)
if !bytes.Contains([]byte(out), []byte("app1")) {
t.Errorf("app1 release not found in output:\n%s", out)
}
if !bytes.Contains([]byte(out), []byte("db1")) {
t.Errorf("db1 release not found in output:\n%s", out)
}
if !bytes.Contains([]byte(out), []byte("cache1")) {
t.Errorf("cache1 release not found in output:\n%s", out)
}
}