mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 14:01:46 +02:00
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>
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package state
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestAppendApiVersionsFlags_KubeVersion tests that kubeVersion is properly
|
|
// passed to helm diff. This is a regression test for issue #2275.
|
|
// Priority: 1) paramKubeVersion (auto-detected), 2) release.KubeVersion, 3) state.KubeVersion (helmfile.yaml)
|
|
func TestAppendApiVersionsFlags_KubeVersion(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
stateKubeVersion string // kubeVersion from HelmState (helmfile.yaml)
|
|
paramKubeVersion string // kubeVersion parameter passed to appendApiVersionsFlags
|
|
expectedVersion string // which version should be in the flags
|
|
}{
|
|
{
|
|
name: "state kubeVersion should be used when param is empty",
|
|
stateKubeVersion: "1.34.0",
|
|
paramKubeVersion: "",
|
|
expectedVersion: "1.34.0",
|
|
},
|
|
{
|
|
name: "param kubeVersion takes precedence over state",
|
|
stateKubeVersion: "1.34.0",
|
|
paramKubeVersion: "1.30.0",
|
|
expectedVersion: "1.30.0",
|
|
},
|
|
{
|
|
name: "no version when both are empty",
|
|
stateKubeVersion: "",
|
|
paramKubeVersion: "",
|
|
expectedVersion: "",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
state := &HelmState{
|
|
KubeVersion: tt.stateKubeVersion,
|
|
}
|
|
|
|
release := &ReleaseSpec{
|
|
Name: "test-release",
|
|
Chart: "test/chart",
|
|
}
|
|
|
|
result := state.appendApiVersionsFlags([]string{}, release, tt.paramKubeVersion)
|
|
|
|
if tt.expectedVersion != "" {
|
|
// Should have --kube-version flag
|
|
foundKubeVersion := false
|
|
for i := 0; i < len(result)-1; i++ {
|
|
if result[i] == "--kube-version" {
|
|
require.Equal(t, tt.expectedVersion, result[i+1],
|
|
"kube-version value should match expected")
|
|
foundKubeVersion = true
|
|
break
|
|
}
|
|
}
|
|
require.True(t, foundKubeVersion, "Should have --kube-version flag in result")
|
|
} else {
|
|
// Should NOT have --kube-version flag
|
|
for i := range result {
|
|
require.NotEqual(t, "--kube-version", result[i],
|
|
"Should not have --kube-version flag when nothing is set")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|