Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Jun 4, 2019
1 parent 2d2b3e4 commit 16f3d7f
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions pkg/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 16f3d7f

Please sign in to comment.