mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-15 19:08:58 +02:00
* add trackLogsUntilReady flag Signed-off-by: pznamensky <kompastver@gmail.com> * refactor(kubedog): flatten nested conditionals in trackLogsUntilReady filter - podLogFilter.update: replace nested if-found/if-uid block with a single combined guard plus a no-op delete - podLogFilter.watch: extract cutoffTrackedKind predicate and watchNamespacePods helper; use RWTransactionErr (kubedog's own idiom) instead of capturing err in plain RWTransaction closures, removing the 'if err == nil { inf.Run() }' nesting - TrackResources: extract newStartupLogFilter guard-clause helper so the printer wiring stays flat - add table tests for the new helpers No behavior change; race tests and golangci-lint pass. Signed-off-by: yxxhero <aiopsclub@163.com> --------- Signed-off-by: pznamensky <kompastver@gmail.com> Signed-off-by: yxxhero <aiopsclub@163.com> Co-authored-by: yxxhero <aiopsclub@163.com>
86 lines
1.9 KiB
Go
86 lines
1.9 KiB
Go
package state
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
)
|
|
|
|
func TestGenerateID(t *testing.T) {
|
|
type testcase struct {
|
|
subject string
|
|
release ReleaseSpec
|
|
data any
|
|
want string
|
|
}
|
|
|
|
ids := map[string]int{}
|
|
|
|
run := func(tc testcase) {
|
|
t.Helper()
|
|
|
|
t.Run(tc.subject, func(t *testing.T) {
|
|
t.Helper()
|
|
|
|
got, err := generateValuesID(&tc.release, tc.data)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if d := cmp.Diff(tc.want, got); d != "" {
|
|
t.Fatalf("unexpected result: want (-), got (+):\n%s", d)
|
|
}
|
|
|
|
ids[got]++
|
|
})
|
|
}
|
|
|
|
// NOTE: These hashes are derived from the full ReleaseSpec struct via
|
|
// generateValuesID -> HashObject. Adding or renaming fields on ReleaseSpec
|
|
// (even nil-defaulted pointer fields like ResolveOCIVersions) shifts every
|
|
// expected hash below. Regenerate the values whenever the struct changes.
|
|
run(testcase{
|
|
subject: "baseline",
|
|
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw"},
|
|
want: "foo-values-699f8dfb8f",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "different bytes content",
|
|
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw"},
|
|
data: []byte(`{"k":"v"}`),
|
|
want: "foo-values-8484b97b54",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "different map content",
|
|
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw"},
|
|
data: map[string]any{"k": "v"},
|
|
want: "foo-values-6d74854796",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "different chart",
|
|
release: ReleaseSpec{Name: "foo", Chart: "stable/envoy"},
|
|
want: "foo-values-6c75d94b64",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "different name",
|
|
release: ReleaseSpec{Name: "bar", Chart: "incubator/raw"},
|
|
want: "bar-values-fdc66db9d",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "specific ns",
|
|
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw", Namespace: "myns"},
|
|
want: "myns-foo-values-74d9576cdb",
|
|
})
|
|
|
|
for id, n := range ids {
|
|
if n > 1 {
|
|
t.Fatalf("too many occurrences of %s: %d", id, n)
|
|
}
|
|
}
|
|
}
|