fix(v3): fix type error while merging map loaded with `fromYaml` template func (#6630)

Fixes #6626

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
pull/6609/head
KUOKA Yusuke 5 years ago committed by Martin Hickey
parent 1da0d011f9
commit 4c351c7248

@ -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.

@ -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 {

Loading…
Cancel
Save