mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-18 02:57:01 +02:00
Use ghodss/yaml for yaml marshaling & unmarshaling in template (#1556)
Fixes #1555 Co-authored-by: Yoann Ciabaud <yoann@linxo.com> Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
co-authored by
Yoann Ciabaud
Yusuke Kuoka
parent
4c0987a618
commit
54eb73b423
@@ -2,9 +2,9 @@ package tmpl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/roboll/helmfile/pkg/helmexec"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package tmpl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
@@ -47,12 +49,31 @@ func TestReadFile_PassAbsPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestToYaml_UnsupportedNestedMapKey(t *testing.T) {
|
||||
expected := ``
|
||||
vals := Values(map[string]interface{}{
|
||||
"foo": map[interface{}]interface{}{
|
||||
"bar": "BAR",
|
||||
},
|
||||
})
|
||||
actual, err := ToYaml(vals)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error but got none")
|
||||
} else if err.Error() != "error marshaling into JSON: json: unsupported type: map[interface {}]interface {}" {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual, expected) {
|
||||
t.Errorf("unexpected result: expected=%v, actual=%v", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestToYaml(t *testing.T) {
|
||||
expected := `foo:
|
||||
bar: BAR
|
||||
`
|
||||
vals := Values(map[string]interface{}{
|
||||
"foo": map[interface{}]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
"bar": "BAR",
|
||||
},
|
||||
})
|
||||
@@ -70,7 +91,7 @@ func TestFromYaml(t *testing.T) {
|
||||
bar: BAR
|
||||
`
|
||||
expected := Values(map[string]interface{}{
|
||||
"foo": map[interface{}]interface{}{
|
||||
"foo": map[string]interface{}{
|
||||
"bar": "BAR",
|
||||
},
|
||||
})
|
||||
@@ -83,6 +104,27 @@ func TestFromYaml(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromYamlToJson(t *testing.T) {
|
||||
input := `foo:
|
||||
bar: BAR
|
||||
`
|
||||
want := `{"foo":{"bar":"BAR"}}`
|
||||
|
||||
m, err := FromYaml(input)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
got, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if d := cmp.Diff(want, string(got)); d != "" {
|
||||
t.Errorf("unexpected result: want (-), got (+):\n%s", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetValueAtPath_OneComponent(t *testing.T) {
|
||||
input := map[string]interface{}{
|
||||
"foo": "",
|
||||
|
||||
Reference in New Issue
Block a user