test: add test case for toToml error swallowing

Add a test case that verifies toToml returns "" on encoding errors
(e.g. map[int]string where keys are not strings), consistent with
how toYaml and toJson handle errors.

Signed-off-by: Gagan Gupta <realgagangupta@users.noreply.github.com>
pull/31915/head
Gagan Gupta 1 month ago
parent e62421055a
commit 68097e3610

@ -122,6 +122,12 @@ keyInElement1 = "valueInElement1"`,
tpl: `{{ fromYamlArray . }}`,
expect: `[error unmarshaling JSON: while decoding JSON: json: cannot unmarshal object into Go value of type []interface {}]`,
vars: `hello: world`,
}, {
// toToml should swallow errors and return "" like toYaml and toJson do.
// map[int]string cannot be encoded as TOML (keys must be strings).
tpl: `{{ toToml . }}`,
expect: ``,
vars: map[int]string{1: "one"},
}, {
// This should never result in a network lookup. Regression for #7955
tpl: `{{ lookup "v1" "Namespace" "" "unlikelynamespace99999999" }}`,

Loading…
Cancel
Save