mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-03 11:06:57 +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>
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package testhelper
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func RequireLog(t *testing.T, dir string, bs *bytes.Buffer) {
|
|
t.Helper()
|
|
|
|
// Get the caller pkg used for instruction on rerunning the specific test
|
|
pc, _, _, _ := runtime.Caller(1)
|
|
funcName := runtime.FuncForPC(pc).Name()
|
|
lastSlash := max(strings.LastIndexByte(funcName, '/'), 0)
|
|
firstDot := strings.IndexByte(funcName[lastSlash:], '.') + lastSlash
|
|
callerPkg := funcName[:firstDot]
|
|
|
|
testNameComponents := strings.Split(t.Name(), "/")
|
|
testBaseName := strings.ToLower(
|
|
strings.ReplaceAll(
|
|
testNameComponents[len(testNameComponents)-1],
|
|
" ",
|
|
"_",
|
|
),
|
|
)
|
|
wantLogFileDir := filepath.Join("testdata", dir)
|
|
wantLogFile := filepath.Join(wantLogFileDir, testBaseName)
|
|
|
|
if os.Getenv("HELMFILE_UPDATE_SNAPSHOT") != "" {
|
|
if err := os.MkdirAll(wantLogFileDir, 0755); err != nil {
|
|
t.Fatalf("unable to create directory %q: %v", wantLogFileDir, err)
|
|
}
|
|
if err := os.WriteFile(wantLogFile, bs.Bytes(), 0644); err != nil {
|
|
t.Fatalf("unable to update lint log snapshot: %v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
wantLogData, err := os.ReadFile(wantLogFile)
|
|
if err != nil {
|
|
t.Fatalf(
|
|
"Snapshot file %q does not exist. Rerun this test with `HELMFILE_UPDATE_SNAPSHOT=1 go test -v -run %s %s` to create the snapshot",
|
|
wantLogFile,
|
|
t.Name(),
|
|
callerPkg,
|
|
)
|
|
}
|
|
|
|
wantLog := string(wantLogData)
|
|
gotLog := bs.String()
|
|
|
|
assert.Equalf(
|
|
t,
|
|
wantLog,
|
|
gotLog,
|
|
"If you think this is due to the snapshot file being outdated, rerun this test with `HELMFILE_UPDATE_SNAPSHOT=1 go test -v -run %s %s` to update the snapshot",
|
|
t.Name(),
|
|
callerPkg,
|
|
)
|
|
}
|