diff --git a/pkg/app/app_test.go b/pkg/app/app_test.go index db4a5b231..2c7f9ee2c 100644 --- a/pkg/app/app_test.go +++ b/pkg/app/app_test.go @@ -900,6 +900,87 @@ bar: "bar1" } } +func TestVisitDesiredStatesWithReleasesFiltered_StateValueOverrides(t *testing.T) { + files := map[string]string{ + "/path/to/helmfile.yaml": ` +# The top-level "values" are "base" values has inherited to state values with the lowest priority. +# The lowest priority results in environment-specific values to override values defined in the base. +values: +- values.yaml + +environments: + default: + values: + - default.yaml + production: + values: + - production.yaml +--- +releases: +- name: {{ .Values.foo }}-{{ .Values.bar }}-{{ .Values.baz }} + chart: stable/zipkin +`, + "/path/to/values.yaml": ` +foo: foo +bar: bar +baz: baz +hoge: hoge +fuga; fuga +`, + "/path/to/default.yaml": ` +bar: "bar_default" +baz: "baz_default" +`, + "/path/to/production.yaml": ` +bar: "bar_production" +baz: "baz_production" +`, + "/path/to/overrides.yaml": ` +baz: baz_override +hoge: hoge_override +`, + } + + testcases := []struct { + env, expected string + }{ + {env: "default", expected: "foo-bar_default-baz_override-hoge_set-fuga_set"}, + {env: "production", expected: "foo-bar_production-baz_override-hoge_set-fuga_set"}, + } + for _, testcase := range testcases { + actual := []string{} + + collectReleases := func(st *state.HelmState, helm helmexec.Interface) []error { + for _, r := range st.Releases { + actual = append(actual, r.Name) + } + return []error{} + } + app := appWithFs(&App{ + KubeContext: "default", + Logger: helmexec.NewLogger(os.Stderr, "debug"), + Reverse: false, + Namespace: "", + Selectors: []string{}, + Env: testcase.env, + ValuesFiles: []string{"overrides.yaml"}, + Set: map[string]interface{}{"hoge": "hoge_set", "fuga": "fuga_set"}, + }, files) + err := app.VisitDesiredStatesWithReleasesFiltered( + "helmfile.yaml", collectReleases, + ) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if len(actual) != 1 { + t.Errorf("unexpected number of processed releases: expected=1, got=%d", len(actual)) + } + if actual[0] != testcase.expected { + t.Errorf("unexpected result: expected=%s, got=%s", testcase.expected, actual[0]) + } + } +} + func TestLoadDesiredStateFromYaml_DuplicateReleaseName(t *testing.T) { yamlFile := "example/path/to/yaml/file" yamlContent := []byte(`releases: