mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-18 09:05:47 +02:00
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:
@@ -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")
|
||||
}
|
||||
Reference in New Issue
Block a user