Browse Source

add tests

marcincuber 3 years ago
parent
commit
a1e7862698
1 changed files with 27 additions and 3 deletions
  1. 27 3
      pkg/template/v2/template_test.go

+ 27 - 3
pkg/template/v2/template_test.go

@@ -159,7 +159,7 @@ func TestExecute(t *testing.T) {
 			},
 		},
 		{
-			name: "fromJSON func",
+			name: "fromJson func",
 			tpl: map[string][]byte{
 				"foo": []byte("{{ $var := .secret | fromJson }}{{ $var.foo }}"),
 			},
@@ -171,7 +171,7 @@ func TestExecute(t *testing.T) {
 			},
 		},
 		{
-			name: "from & toJSON func",
+			name: "from & toJson func",
 			tpl: map[string][]byte{
 				"foo": []byte("{{ $var := .secret | fromJson }}{{ $var.foo | toJson }}"),
 			},
@@ -183,6 +183,30 @@ func TestExecute(t *testing.T) {
 			},
 		},
 		{
+			name: "fromJson & toYaml func",
+			tpl: map[string][]byte{
+				"foo": []byte("{{ $var := .secret | fromJson | toYaml }}{{ $var }}"),
+			},
+			data: map[string][]byte{
+				"secret": []byte(`{"foo": "bar"}`),
+			},
+			expetedData: map[string][]byte{
+				"foo": []byte(`foo: bar`),
+			},
+		},
+		{
+			name: "fromYaml & toJson func",
+			tpl: map[string][]byte{
+				"foo": []byte("{{ $var := .secret | fromYaml | toJson }}{{ $var }}"),
+			},
+			data: map[string][]byte{
+				"secret": []byte(`foo: bar`),
+			},
+			expetedData: map[string][]byte{
+				"foo": []byte(`{"foo": "bar"}`),
+			},
+		},
+		{
 			name: "use sprig functions",
 			tpl: map[string][]byte{
 				"foo": []byte(`{{ .path | ext }}`),
@@ -302,7 +326,7 @@ func TestExecute(t *testing.T) {
 			expErr: "unable to decode pkcs12",
 		},
 		{
-			name: "fromJSON error",
+			name: "fromJson error",
 			tpl: map[string][]byte{
 				"key": []byte(`{{ "{ # no json # }" | fromJson }}`),
 			},