@@ -2,10 +2,9 @@ package terraform
2
2
3
3
import (
4
4
"flag"
5
- "io/ioutil"
6
5
"testing"
7
6
8
- "github.com/mantil-io/mantil/kit/shell "
7
+ "github.com/mantil-io/mantil/kit/testutil "
9
8
"github.com/mantil-io/mantil/node/dto"
10
9
"github.com/stretchr/testify/require"
11
10
)
@@ -44,8 +43,8 @@ func TestRenderSetup(t *testing.T) {
44
43
require .Equal (t , tf .createPath , "/tmp/mantil/setup/create" )
45
44
require .Equal (t , tf .destroyPath , "/tmp/mantil/setup/destroy" )
46
45
47
- equalFiles (t , "testdata/setup.tf" , "/tmp/mantil/setup/create/main.tf" )
48
- equalFiles (t , "testdata/setup-destroy.tf" , "/tmp/mantil/setup/destroy/main.tf" )
46
+ testutil . EqualFiles (t , "testdata/setup.tf" , "/tmp/mantil/setup/create/main.tf" , * update )
47
+ testutil . EqualFiles (t , "testdata/setup-destroy.tf" , "/tmp/mantil/setup/destroy/main.tf" , * update )
49
48
}
50
49
51
50
func TestRenderProject (t * testing.T ) {
@@ -85,41 +84,8 @@ func TestRenderProject(t *testing.T) {
85
84
require .Equal (t , tf .createPath , "/tmp/mantil/my-project-my-stage/create" )
86
85
require .Equal (t , tf .destroyPath , "/tmp/mantil/my-project-my-stage/destroy" )
87
86
88
- equalFiles (t , "testdata/project.tf" , "/tmp/mantil/my-project-my-stage/create/main.tf" )
89
- equalFiles (t , "testdata/project-destroy.tf" , "/tmp/mantil/my-project-my-stage/destroy/main.tf" )
90
- }
91
-
92
- // TODO: same function in api/setup package
93
- func equalFiles (t * testing.T , expected , actual string ) {
94
- actualContent , err := ioutil .ReadFile (actual )
95
- if err != nil {
96
- t .Fatalf ("failed reading actual file: %s" , err )
97
- }
98
-
99
- if * update {
100
- t .Logf ("update expected file %s" , expected )
101
- if err := ioutil .WriteFile (expected , actualContent , 0644 ); err != nil {
102
- t .Fatalf ("failed to update expectexd file: %s" , err )
103
- }
104
- return
105
- }
106
-
107
- expectedContent , err := ioutil .ReadFile (expected )
108
- if err != nil {
109
- t .Fatalf ("failed reading expected file: %s" , err )
110
- }
111
-
112
- if string (actualContent ) != string (expectedContent ) {
113
- args := []string {"diff" , expected , actual }
114
- out , err := shell .Output (shell.ExecOptions {Args : args })
115
- if err != nil {
116
- t .Logf ("diff of files" )
117
- t .Logf ("expected %s, actual %s" , expected , actual )
118
- t .Logf ("%s" , out )
119
- t .Fatalf ("failed" )
120
- }
121
-
122
- }
87
+ testutil .EqualFiles (t , "testdata/project.tf" , "/tmp/mantil/my-project-my-stage/create/main.tf" , * update )
88
+ testutil .EqualFiles (t , "testdata/project-destroy.tf" , "/tmp/mantil/my-project-my-stage/destroy/main.tf" , * update )
123
89
}
124
90
125
91
// func TestParseLog(t *testing.T) {
0 commit comments