@@ -900,6 +900,130 @@ bar: "bar1"
900
900
}
901
901
}
902
902
903
+ func TestVisitDesiredStatesWithReleasesFiltered_StateValueOverrides (t * testing.T ) {
904
+ envTmplExpr := "{{ .Values.foo }}-{{ .Values.bar }}-{{ .Values.baz }}-{{ .Values.hoge }}-{{ .Values.fuga }}-{{ .Values.a | first | pluck \" b\" | first | first | pluck \" c\" | first }}"
905
+ relTmplExpr := "\" {{`{{ .Values.foo }}-{{ .Values.bar }}-{{ .Values.baz }}-{{ .Values.hoge }}-{{ .Values.fuga }}-{{ .Values.a | first | pluck \\ \" b\\ \" | first | first | pluck \\ \" c\\ \" | first }}`}}\" "
906
+
907
+ testcases := []struct {
908
+ expr , env , expected string
909
+ }{
910
+ {
911
+ expr : envTmplExpr ,
912
+ env : "default" ,
913
+ expected : "foo-bar_default-baz_override-hoge_set-fuga_set-C" ,
914
+ },
915
+ {
916
+ expr : envTmplExpr ,
917
+ env : "production" ,
918
+ expected : "foo-bar_production-baz_override-hoge_set-fuga_set-C" ,
919
+ },
920
+ {
921
+ expr : relTmplExpr ,
922
+ env : "default" ,
923
+ expected : "foo-bar_default-baz_override-hoge_set-fuga_set-C" ,
924
+ },
925
+ {
926
+ expr : relTmplExpr ,
927
+ env : "production" ,
928
+ expected : "foo-bar_production-baz_override-hoge_set-fuga_set-C" ,
929
+ },
930
+ }
931
+ for i := range testcases {
932
+ testcase := testcases [i ]
933
+ t .Run (fmt .Sprintf ("case %d" , i ), func (t * testing.T ) {
934
+ files := map [string ]string {
935
+ "/path/to/helmfile.yaml" : fmt .Sprintf (`
936
+ # The top-level "values" are "base" values has inherited to state values with the lowest priority.
937
+ # The lowest priority results in environment-specific values to override values defined in the base.
938
+ values:
939
+ - values.yaml
940
+
941
+ environments:
942
+ default:
943
+ values:
944
+ - default.yaml
945
+ production:
946
+ values:
947
+ - production.yaml
948
+ ---
949
+ releases:
950
+ - name: %s
951
+ chart: %s
952
+ namespace: %s
953
+ ` , testcase .expr , testcase .expr , testcase .expr ),
954
+ "/path/to/values.yaml" : `
955
+ foo: foo
956
+ bar: bar
957
+ baz: baz
958
+ hoge: hoge
959
+ fuga: fuga
960
+
961
+ a: []
962
+ ` ,
963
+ "/path/to/default.yaml" : `
964
+ bar: "bar_default"
965
+ baz: "baz_default"
966
+
967
+ a:
968
+ - b: []
969
+ ` ,
970
+ "/path/to/production.yaml" : `
971
+ bar: "bar_production"
972
+ baz: "baz_production"
973
+
974
+ a:
975
+ - b: []
976
+ ` ,
977
+ "/path/to/overrides.yaml" : `
978
+ baz: baz_override
979
+ hoge: hoge_override
980
+
981
+ a:
982
+ - b:
983
+ - c: C
984
+ ` ,
985
+ }
986
+
987
+ actual := []state.ReleaseSpec {}
988
+
989
+ collectReleases := func (st * state.HelmState , helm helmexec.Interface ) []error {
990
+ for _ , r := range st .Releases {
991
+ actual = append (actual , r )
992
+ }
993
+ return []error {}
994
+ }
995
+ app := appWithFs (& App {
996
+ KubeContext : "default" ,
997
+ Logger : helmexec .NewLogger (os .Stderr , "debug" ),
998
+ Reverse : false ,
999
+ Namespace : "" ,
1000
+ Selectors : []string {},
1001
+ Env : testcase .env ,
1002
+ ValuesFiles : []string {"overrides.yaml" },
1003
+ Set : map [string ]interface {}{"hoge" : "hoge_set" , "fuga" : "fuga_set" },
1004
+ }, files )
1005
+ err := app .VisitDesiredStatesWithReleasesFiltered (
1006
+ "helmfile.yaml" , collectReleases ,
1007
+ )
1008
+ if err != nil {
1009
+ t .Fatalf ("unexpected error: %v" , err )
1010
+ }
1011
+ if len (actual ) != 1 {
1012
+ t .Errorf ("unexpected number of processed releases: expected=1, got=%d" , len (actual ))
1013
+ }
1014
+ if actual [0 ].Name != testcase .expected {
1015
+ t .Errorf ("unexpected name: expected=%s, got=%s" , testcase .expected , actual [0 ].Name )
1016
+ }
1017
+ if actual [0 ].Chart != testcase .expected {
1018
+ t .Errorf ("unexpected chart: expected=%s, got=%s" , testcase .expected , actual [0 ].Chart )
1019
+ }
1020
+ if actual [0 ].Namespace != testcase .expected {
1021
+ t .Errorf ("unexpected namespace: expected=%s, got=%s" , testcase .expected , actual [0 ].Namespace )
1022
+ }
1023
+ })
1024
+ }
1025
+ }
1026
+
903
1027
func TestLoadDesiredStateFromYaml_DuplicateReleaseName (t * testing.T ) {
904
1028
yamlFile := "example/path/to/yaml/file"
905
1029
yamlContent := []byte (`releases:
0 commit comments