Files
helmfile/pkg/yaml/yaml_test.go
T
Yusuke Kuoka 4688cf0132 Use gopkg.in/yaml.v2 for Helmfile v0.x (#609)
This should fix #435 for Helmfile v0.x releases since the next v0.150.0.
We introduce a new envvar to opt-in to the new YAML library, so that you can give it a shot before upgrading your Helmfile to v1. The same envvar can be used to opt-out of the new YAML library after you upgrade to Helmfile v1, giving you a more flexible migration story.

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
2023-01-04 18:17:24 +09:00

55 lines
1.0 KiB
Go

package yaml
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/helmfile/helmfile/pkg/runtime"
)
func testYamlMarshal(t *testing.T, goccyGoYaml bool) {
t.Helper()
v := runtime.GoccyGoYaml
runtime.GoccyGoYaml = goccyGoYaml
t.Cleanup(func() {
runtime.GoccyGoYaml = v
})
tests := []struct {
Name string `yaml:"name"`
Info []struct {
Age int `yaml:"age"`
Address string `yaml:"address"`
} `yaml:"info"`
expected string
}{
{
Name: "John",
Info: []struct {
Age int `yaml:"age"`
Address string `yaml:"address"`
}{{Age: 20, Address: "New York"}},
expected: "name: John\ninfo:\n- age: 20\n address: New York\n",
},
}
for _, tt := range tests {
actual, err := Marshal(tt)
require.NoError(t, err)
require.Equal(t, tt.expected, string(actual))
}
}
func TestYamlMarshal(t *testing.T) {
t.Run("with goccy/go-yaml", func(t *testing.T) {
testYamlMarshal(t, true)
})
t.Run("with gopkg.in/yaml.v2", func(t *testing.T) {
testYamlMarshal(t, false)
})
}