diff --git a/pkg/engine/funcs.go b/pkg/engine/funcs.go index b80a80412..dac105e74 100644 --- a/pkg/engine/funcs.go +++ b/pkg/engine/funcs.go @@ -24,7 +24,7 @@ import ( "github.com/BurntSushi/toml" "github.com/Masterminds/sprig/v3" - yaml "gopkg.in/yaml.v2" + "sigs.k8s.io/yaml" ) // funcMap returns a mapping of all of the functions that Engine has. diff --git a/pkg/engine/funcs_test.go b/pkg/engine/funcs_test.go index 4c2addcee..a94ff257e 100644 --- a/pkg/engine/funcs_test.go +++ b/pkg/engine/funcs_test.go @@ -52,7 +52,7 @@ func TestFuncs(t *testing.T) { vars: map[string]map[string]string{"mast": {"sail": "white"}}, }, { tpl: `{{ fromYaml . }}`, - expect: "map[Error:yaml: unmarshal errors:\n line 1: cannot unmarshal !!seq into map[string]interface {}]", + expect: "map[Error:error unmarshaling JSON: while decoding JSON: json: cannot unmarshal array into Go value of type map[string]interface {}]", vars: "- one\n- two\n", }, { tpl: `{{ fromJson .}}`, @@ -62,6 +62,18 @@ func TestFuncs(t *testing.T) { tpl: `{{ fromJson . }}`, expect: `map[Error:json: cannot unmarshal array into Go value of type map[string]interface {}]`, vars: `["one", "two"]`, + }, { + tpl: `{{ merge .dict (fromYaml .yaml) }}`, + expect: `map[a:map[b:c]]`, + vars: map[string]interface{}{"dict": map[string]interface{}{"a": map[string]interface{}{"b": "c"}}, "yaml": `{"a":{"b":"d"}}`}, + }, { + tpl: `{{ merge (fromYaml .yaml) .dict }}`, + expect: `map[a:map[b:d]]`, + vars: map[string]interface{}{"dict": map[string]interface{}{"a": map[string]interface{}{"b": "c"}}, "yaml": `{"a":{"b":"d"}}`}, + }, { + tpl: `{{ fromYaml . }}`, + expect: `map[Error:error unmarshaling JSON: while decoding JSON: json: cannot unmarshal array into Go value of type map[string]interface {}]`, + vars: `["one", "two"]`, }} for _, tt := range tests {