-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtocty_test.go
74 lines (63 loc) · 2 KB
/
tocty_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package dgocty_test
import (
"fmt"
"testing"
"github.com/lyraproj/dgo/vf"
"github.com/lyraproj/dgocty"
)
func ExampleToCty_mixed() {
v := vf.Map("a", 1, "b", vf.Values("c", 3.14, true))
c := dgocty.ToCty(v, false)
fmt.Println(c.GoString())
// Output: cty.ObjectVal(map[string]cty.Value{"a":cty.NumberIntVal(1), "b":cty.TupleVal([]cty.Value{cty.StringVal("c"), cty.NumberFloatVal(3.14), cty.True})})
}
func ExampleToCty_list() {
v := vf.Strings("a", "b")
c := dgocty.ToCty(v, true)
fmt.Println(c.GoString())
// Output: cty.ListVal([]cty.Value{cty.StringVal("a"), cty.StringVal("b")})
}
func ExampleToCty_autoTuple() {
v := vf.Values("a", 2)
c := dgocty.ToCty(v, true)
fmt.Println(c.GoString())
// Output: cty.TupleVal([]cty.Value{cty.StringVal("a"), cty.NumberIntVal(2)})
}
func ExampleToCty_forcedTuple() {
v := vf.Strings("a", "b")
c := dgocty.ToCty(v, false)
fmt.Println(c.GoString())
// Output: cty.TupleVal([]cty.Value{cty.StringVal("a"), cty.StringVal("b")})
}
func ExampleToCty_map() {
v := vf.Map("a", 1, "b", 2)
c := dgocty.ToCty(v, true)
fmt.Println(c.GoString())
// Output: cty.MapVal(map[string]cty.Value{"a":cty.NumberIntVal(1), "b":cty.NumberIntVal(2)})
}
func ExampleToCty_autoObject() {
v := vf.Map("a", 1, "b", `two`)
c := dgocty.ToCty(v, true)
fmt.Println(c.GoString())
// Output: cty.ObjectVal(map[string]cty.Value{"a":cty.NumberIntVal(1), "b":cty.StringVal("two")})
}
func ExampleToCty_forcedObject() {
v := vf.Map("a", 1, "b", 2)
c := dgocty.ToCty(v, false)
fmt.Println(c.GoString())
// Output: cty.ObjectVal(map[string]cty.Value{"a":cty.NumberIntVal(1), "b":cty.NumberIntVal(2)})
}
func ExampleToCty_nil() {
fmt.Println(dgocty.ToCty(vf.Nil, false).GoString())
// Output: cty.NullVal(cty.DynamicPseudoType)
}
func TestToCty_capsule(t *testing.T) {
s := vf.Sensitive(`secret`)
c := dgocty.ToCty(s, false)
if !c.Type().IsCapsuleType() {
t.Fatal(`sensitive not converted to cty.Capsule`)
}
if !s.Equals(dgocty.FromCty(c)) {
t.Fatal(`sensitive not recreated from cty.Capsule`)
}
}