-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathformat_test.go
97 lines (67 loc) · 1.36 KB
/
format_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package envsec
import (
"bytes"
"encoding/json"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestFormatCloudformation(t *testing.T) {
assert := assert.New(t)
buf := bytes.NewBuffer(nil)
cloudformation(buf, []string{
"foo=bar",
})
assert.Equal(`"foo": {
"Default": "bar",
"Type": "String"
}
`, buf.String())
buf.Reset()
cloudformation(buf, []string{
"foo=bar",
"wee=gee",
})
var r map[string]map[string]string
err := json.Unmarshal([]byte(fmt.Sprintf("{%s}", buf.String())), &r)
assert.NoError(err)
assert.Equal("bar", r["foo"]["Default"])
assert.Equal("String", r["foo"]["Type"])
assert.Equal("gee", r["wee"]["Default"])
assert.Equal("String", r["wee"]["Type"])
}
func TestFormatTerraform(t *testing.T) {
assert := assert.New(t)
buf := bytes.NewBuffer(nil)
terraform(buf, []string{
"foo=bar",
})
assert.Equal(`variable "foo" {
type = "string"
default = "bar"
}
`, buf.String())
buf.Reset()
terraform(buf, []string{
"foo=bar",
"wee=gee",
})
assert.Contains(buf.String(), `variable "foo" {
type = "string"
default = "bar"
}`)
assert.Contains(buf.String(), `variable "wee" {
type = "string"
default = "gee"
}`)
}
func TestFormatShell(t *testing.T) {
buf := bytes.NewBuffer(nil)
shell(buf, []string{
"foo=bar",
"wee=gee",
})
assert.Equal(t, `foo=bar
wee=gee
`, buf.String())
}