12987: test toToml int conversion

pull/13012/head
Calvin Krist 5 months ago
parent 1df00645e0
commit 8d055e271a

@ -161,6 +161,12 @@ func TestTemplateCmd(t *testing.T) {
cmd: fmt.Sprintf("template '%s' -f %s/extra_values.yaml", chartPath, chartPath),
golden: "output/template-subchart-cm-set-file.txt",
},
{
// Ensure that toToml processes integers as ints, and not floats
name: "template with toToml processing an integer",
cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/issue-12987"),
golden: "output/issue-12987.txt",
},
}
runTestCmd(t, tests)
}

@ -0,0 +1,4 @@
---
# Source: issue-12987/templates/object.yaml
data:
bar = 9

@ -0,0 +1,3 @@
apiVersion: v2
name: issue-12987
version: 0.1.0

@ -0,0 +1,2 @@
data:
{{ .Values | toToml }}

@ -98,6 +98,7 @@ func TestRender(t *testing.T) {
{Name: "templates/test3", Data: []byte("{{.noValue}}")},
{Name: "templates/test4", Data: []byte("{{toJson .Values}}")},
{Name: "templates/test5", Data: []byte("{{getHostByName \"helm.sh\"}}")},
{Name: "templates/test6", Data: []byte("{{ .Values.config | toToml }}")},
},
Values: map[string]interface{}{"outer": "DEFAULT", "inner": "DEFAULT"},
}
@ -109,6 +110,9 @@ func TestRender(t *testing.T) {
"global": map[string]interface{}{
"callme": "Ishmael",
},
"config": map[string]interface{}{
"bar": 9,
},
},
}
@ -125,8 +129,9 @@ func TestRender(t *testing.T) {
"moby/templates/test1": "Spouter Inn",
"moby/templates/test2": "ishmael",
"moby/templates/test3": "",
"moby/templates/test4": `{"global":{"callme":"Ishmael"},"inner":"inn","outer":"spouter"}`,
"moby/templates/test4": `{"config":{"bar":9},"global":{"callme":"Ishmael"},"inner":"inn","outer":"spouter"}`,
"moby/templates/test5": "",
"moby/templates/test6": "bar = 9\n",
}
for name, data := range expect {

@ -99,6 +99,14 @@ func TestFuncs(t *testing.T) {
tpl: `{{ lookup "v1" "Namespace" "" "unlikelynamespace99999999" }}`,
expect: `map[]`,
vars: `["one", "two"]`,
}, {
tpl: `{{ toToml . }}`,
expect: "bar = 9\n",
vars: map[string]int{"bar": 9},
}, {
tpl: `{{ toToml . }}`,
expect: "bar = 9.0\n",
vars: map[string]float32{"bar": 9.0},
}}
for _, tt := range tests {

Loading…
Cancel
Save