balmeida-nokia 2 days ago committed by GitHub
commit a8b5c868d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -68,6 +68,8 @@ func funcMap() template.FuncMap {
"fromJson": fromJSON,
"fromJsonArray": fromJSONArray,
"omitted": omitted,
// Duration helpers
"mustToDuration": mustToDuration,
"durationSeconds": durationSeconds,
@ -269,6 +271,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