-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcty_funcs_test.go
55 lines (50 loc) · 1.09 KB
/
cty_funcs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package yaml
import (
"testing"
"github.com/zclconf/go-cty/cty"
)
func TestYAMLDecodeFunc(t *testing.T) {
// FIXME: This is not a very extensive test.
tests := map[string]struct {
input string
want cty.Value
}{
"only document separator": {
`---`,
cty.NullVal(cty.DynamicPseudoType),
},
"null": {
`~`,
cty.NullVal(cty.DynamicPseudoType),
},
"boolean true": {
`true`,
cty.True,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
got, err := YAMLDecodeFunc.Call([]cty.Value{
cty.StringVal(test.input),
})
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if want := test.want; !want.RawEquals(got) {
t.Fatalf("wrong result\ngot: %#v\nwant: %#v", got, want)
}
})
}
}
func TestYAMLEncodeFunc(t *testing.T) {
// FIXME: This is not a very extensive test.
got, err := YAMLEncodeFunc.Call([]cty.Value{
cty.StringVal("true"),
})
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
if want := cty.StringVal("\"true\"\n"); !want.RawEquals(got) {
t.Fatalf("wrong result\ngot: %#v\nwant: %#v", got, want)
}
}