mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 13:44:57 +02:00
* feat: Add ConditionTemplate support in releaseSpec Signed-off-by: Arthur Garreau <arthur.garreau98@gmail.com> * feat: improve testing, clarify doc Signed-off-by: Arthur Garreau <arthur.garreau98@gmail.com> * feat: update CHANGELOG for ConditionTemplate support and fix test cases for ID generation Signed-off-by: Arthur Garreau <arthur.garreau98@gmail.com> * Update pkg/state/state_exec_tmpl.go Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> Signed-off-by: Arthur Garreau <arthur.garreau98@gmail.com> * Update pkg/state/state_exec_tmpl.go Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> Signed-off-by: Arthur Garreau <arthur.garreau98@gmail.com> * Update docs/configuration.md Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com> Signed-off-by: Arthur Garreau <arthur.garreau98@gmail.com> * refactor: improve comments for condition checks and clean up whitespace Signed-off-by: Arthur Garreau <arthur.garreau98@gmail.com> --------- Signed-off-by: Arthur Garreau <arthur.garreau98@gmail.com> Co-authored-by: yxxhero <11087727+yxxhero@users.noreply.github.com>
82 lines
1.6 KiB
Go
82 lines
1.6 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]++
|
|
})
|
|
}
|
|
|
|
run(testcase{
|
|
subject: "baseline",
|
|
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw"},
|
|
want: "foo-values-6765d87f7c",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "different bytes content",
|
|
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw"},
|
|
data: []byte(`{"k":"v"}`),
|
|
want: "foo-values-6d7db5f8b",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "different map content",
|
|
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw"},
|
|
data: map[string]any{"k": "v"},
|
|
want: "foo-values-5c55f66dd",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "different chart",
|
|
release: ReleaseSpec{Name: "foo", Chart: "stable/envoy"},
|
|
want: "foo-values-7665888bf4",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "different name",
|
|
release: ReleaseSpec{Name: "bar", Chart: "incubator/raw"},
|
|
want: "bar-values-bc6f974bd",
|
|
})
|
|
|
|
run(testcase{
|
|
subject: "specific ns",
|
|
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw", Namespace: "myns"},
|
|
want: "myns-foo-values-76f8c7c596",
|
|
})
|
|
|
|
for id, n := range ids {
|
|
if n > 1 {
|
|
t.Fatalf("too many occurrences of %s: %d", id, n)
|
|
}
|
|
}
|
|
}
|