-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
69 lines (55 loc) · 1.35 KB
/
utils_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
package tfsig_test
import (
"testing"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/yoanm/go-tfsig"
"github.com/yoanm/go-tfsig/testutils"
)
func TestAppendNewLineAndBlockIfNotNil(t *testing.T) {
t.Parallel()
testBlock := hclwrite.NewBlock("source", nil)
cases := map[string]struct {
Value *hclwrite.Block
Want string
}{
"Nil block": {nil, ""},
"Not nil block": {testBlock, "\nsource {\n}\n"},
}
for tcname, tcase := range cases {
t.Run(
tcname,
func(t *testing.T) {
t.Parallel()
file := hclwrite.NewEmptyFile()
tfsig.AppendNewLineAndBlockIfNotNil(file.Body(), tcase.Value)
if err := testutils.EnsureFileContentEquals(file, tcase.Want); err != nil {
t.Errorf("Case \"%s\": %v", t.Name(), err)
}
},
)
}
}
func TestAppendBlockIfNotNil(t *testing.T) {
t.Parallel()
testBlock := hclwrite.NewBlock("source", nil)
cases := map[string]struct {
Value *hclwrite.Block
Want string
}{
"Nil block": {nil, ""},
"Not nil block": {testBlock, "source {\n}\n"},
}
for tcname, tcase := range cases {
t.Run(
tcname,
func(t *testing.T) {
t.Parallel()
file := hclwrite.NewEmptyFile()
tfsig.AppendBlockIfNotNil(file.Body(), tcase.Value)
if err := testutils.EnsureFileContentEquals(file, tcase.Want); err != nil {
t.Errorf("Case \"%s\": %v", t.Name(), err)
}
},
)
}
}