Create omitted function

Signed-off-by: Bruno Almeida <bruno.almeida@nokia.com>
pull/12864/head
Bruno Almeida 3 years ago
parent 67946bb22e
commit 528dd79e7c

@ -68,6 +68,8 @@ func funcMap() template.FuncMap {
"fromJson": fromJSON,
"fromJsonArray": fromJSONArray,
"omitted": omitted,
// Duration helpers
"mustToDuration": mustToDuration,
"durationSeconds": durationSeconds,
@ -268,6 +270,12 @@ func fromJSONArray(str string) []any {
return a
}
func omitted(a, b interface{}) interface{} {
if b == nil {
return a
}
return b
// -----------------------------------------------------------------------------
// Duration helpers (numeric and time.Duration returns)
// -----------------------------------------------------------------------------

@ -125,6 +125,14 @@ keyInElement1 = "valueInElement1"`,
tpl: `{{ fromYamlArray . }}`,
expect: `[error unmarshaling JSON: while decoding JSON: json: cannot unmarshal object into Go value of type []interface {}]`,
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
tpl: `{{ lookup "v1" "Namespace" "" "unlikelynamespace99999999" }}`,

Loading…
Cancel
Save