-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyaml2hcl_test.go
69 lines (57 loc) · 1.6 KB
/
yaml2hcl_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
// Copyright © 2020 Martin Whittington <[email protected]>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file
package yaml2hcl
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestConvert(t *testing.T) {
assert := assert.New(t)
v := make(map[interface{}]interface{})
v["subnet_name"] = "subnet-1"
v["subnet_private"] = true
tf := Convert(v)
assert.Contains(tf.Attributes(), "subnet_name")
assert.Contains(tf.Attributes(), "subnet_private")
assert.Nil(tf.GetAttribute("some_other_var"))
}
func TestConvertToString(t *testing.T) {
assert := assert.New(t)
v := make(map[interface{}]interface{})
v["subnet_name"] = "subnet-1"
v["subnet_private"] = true
tf := ConvertToString(v)
assert.Contains(tf, "subnet_name")
assert.Contains(tf, "subnet-1")
assert.Contains(tf, "subnet_private")
assert.Contains(tf, "true")
}
func TestGetValue(t *testing.T) {
assert := assert.New(t)
v := interface{}("string")
val := getValue(v)
assert.True(val.Type().IsPrimitiveType())
v = true
val = getValue(v)
assert.True(val.Type().IsPrimitiveType())
v = 10
val = getValue(v)
assert.True(val.Type().IsPrimitiveType())
m := make(map[interface{}]interface{})
k := interface{}("key")
m[k] = interface{}("value")
val = getValue(m)
assert.True(val.Type().IsObjectType())
l := make([]interface{}, 0)
val = getValue(l)
assert.True(val.Type().IsListType())
li := interface{}("value")
l = append(l, li)
val = getValue(l)
assert.True(val.Type().IsListType())
v = 3.4 // not handling floats
val = getValue(v)
assert.True(val.IsNull())
}