fix: ValuesTemplate quote issue (#787)

* fix: ValuesTemplate quote issue

Signed-off-by: yxxhero <aiopsclub@163.com>

* optimize goccy yaml options

Signed-off-by: yxxhero <aiopsclub@163.com>

* add more options

Signed-off-by: yxxhero <aiopsclub@163.com>

* fix tests

Signed-off-by: yxxhero <aiopsclub@163.com>

* fix tests

Signed-off-by: yxxhero <aiopsclub@163.com>

---------

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2023-04-14 13:03:26 +09:00
committed by GitHub
parent 219602ebc7
commit 7c72e2ba3e
3 changed files with 60 additions and 3 deletions
+45
View File
@@ -0,0 +1,45 @@
package state
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/helmfile/helmfile/pkg/filesystem"
"github.com/helmfile/helmfile/pkg/runtime"
"github.com/helmfile/helmfile/pkg/tmpl"
)
func TestExecuteTemplateExpressions(t *testing.T) {
render := tmpl.NewFileRenderer(filesystem.DefaultFileSystem(), "", map[string]interface{}{
"Values": map[string]interface{}{
"foo": map[string]interface{}{
"releaseName": "foo",
},
},
"Release": map[string]interface{}{
"Name": "foo",
},
})
v := runtime.GoccyGoYaml
runtime.GoccyGoYaml = true
t.Cleanup(func() {
runtime.GoccyGoYaml = v
})
rs := ReleaseSpec{
Name: "foo",
Chart: "bar",
Namespace: "baz",
ValuesTemplate: []interface{}{
map[string]interface{}{
"fullnameOverride": "{{ .Values | get (printf \"%s.releaseName\" .Release.Name) .Release.Name }}",
},
},
}
result, err := rs.ExecuteTemplateExpressions(render)
require.NoErrorf(t, err, "failed to execute template expressions: %v", err)
require.Equalf(t, result.ValuesTemplate[0].(map[string]interface{})["fullnameOverride"], "foo", "failed to execute template expressions")
}