pull/12864/merge
balmeida-nokia 2 weeks ago committed by GitHub
commit 5272e0456a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -61,6 +61,8 @@ func funcMap() template.FuncMap {
"fromJson": fromJSON, "fromJson": fromJSON,
"fromJsonArray": fromJSONArray, "fromJsonArray": fromJSONArray,
"omitted": omitted,
// This is a placeholder for the "include" function, which is // This is a placeholder for the "include" function, which is
// late-bound to a template. By declaring it here, we preserve the // late-bound to a template. By declaring it here, we preserve the
// integrity of the linter. // integrity of the linter.
@ -232,3 +234,10 @@ func fromJSONArray(str string) []interface{} {
} }
return a return a
} }
func omitted(a, b interface{}) interface{} {
if b == nil {
return a
}
return b
}

@ -122,6 +122,14 @@ keyInElement1 = "valueInElement1"`,
tpl: `{{ fromYamlArray . }}`, tpl: `{{ fromYamlArray . }}`,
expect: `[error unmarshaling JSON: while decoding JSON: json: cannot unmarshal object into Go value of type []interface {}]`, expect: `[error unmarshaling JSON: while decoding JSON: json: cannot unmarshal object into Go value of type []interface {}]`,
vars: `hello: world`, vars: `hello: world`,
}, {
tpl: `{{ .hello | omitted 'yes' }}`,
expect: `false`,
vars: map[string]bool{"hello": false},
}, {
tpl: `{{ .value | omitted 'yes' }}`,
expect: `yes`,
vars: map[string]bool{"hello": false},
}, { }, {
// This should never result in a network lookup. Regression for #7955 // This should never result in a network lookup. Regression for #7955
tpl: `{{ lookup "v1" "Namespace" "" "unlikelynamespace99999999" }}`, tpl: `{{ lookup "v1" "Namespace" "" "unlikelynamespace99999999" }}`,

Loading…
Cancel
Save