@@ -18,7 +18,6 @@ package initializer
18
18
19
19
import (
20
20
"bytes"
21
- "os"
22
21
"strings"
23
22
"testing"
24
23
@@ -27,36 +26,36 @@ import (
27
26
28
27
func TestPrintAnalyzeJSON (t * testing.T ) {
29
28
tests := []struct {
30
- name string
29
+ description string
31
30
dockerfiles []string
32
31
images []string
33
32
skipBuild bool
34
33
shouldErr bool
35
34
expected string
36
35
}{
37
36
{
38
- name : "dockerfile and image" ,
37
+ description : "dockerfile and image" ,
39
38
dockerfiles : []string {"Dockerfile" , "Dockerfile_2" },
40
39
images : []string {"image1" , "image2" },
41
40
expected : "{\" dockerfiles\" :[\" Dockerfile\" ,\" Dockerfile_2\" ],\" images\" :[\" image1\" ,\" image2\" ]}" ,
42
41
},
43
42
{
44
- name : "no dockerfile, skip build" ,
45
- images : []string {"image1" , "image2" },
46
- skipBuild : true ,
47
- expected : "{\" images\" :[\" image1\" ,\" image2\" ]}" },
43
+ description : "no dockerfile, skip build" ,
44
+ images : []string {"image1" , "image2" },
45
+ skipBuild : true ,
46
+ expected : "{\" images\" :[\" image1\" ,\" image2\" ]}" },
48
47
{
49
- name : "no dockerfile" ,
50
- images : []string {"image1" , "image2" },
51
- shouldErr : true ,
48
+ description : "no dockerfile" ,
49
+ images : []string {"image1" , "image2" },
50
+ shouldErr : true ,
52
51
},
53
52
{
54
- name : "no dockerfiles or images" ,
55
- shouldErr : true ,
53
+ description : "no dockerfiles or images" ,
54
+ shouldErr : true ,
56
55
},
57
56
}
58
57
for _ , test := range tests {
59
- t .Run (test .name , func (t * testing.T ) {
58
+ t .Run (test .description , func (t * testing.T ) {
60
59
out := bytes .NewBuffer ([]byte {})
61
60
err := printAnalyzeJSON (out , test .skipBuild , test .dockerfiles , test .images )
62
61
testutil .CheckErrorAndDeepEqual (t , test .shouldErr , err , test .expected , out .String ())
@@ -67,15 +66,15 @@ func TestPrintAnalyzeJSON(t *testing.T) {
67
66
func TestWalk (t * testing.T ) {
68
67
emptyFile := ""
69
68
tests := []struct {
70
- name string
69
+ description string
71
70
filesWithContents map [string ]string
72
71
expectedConfigs []string
73
72
expectedDockerfiles []string
74
73
force bool
75
74
shouldErr bool
76
75
}{
77
76
{
78
- name : "should return correct k8 configs and dockerfiles" ,
77
+ description : "should return correct k8 configs and dockerfiles" ,
79
78
filesWithContents : map [string ]string {
80
79
"config/test.yaml" : emptyFile ,
81
80
"k8pod.yml" : emptyFile ,
@@ -95,7 +94,7 @@ func TestWalk(t *testing.T) {
95
94
shouldErr : false ,
96
95
},
97
96
{
98
- name : "should skip hidden dir" ,
97
+ description : "should skip hidden dir" ,
99
98
filesWithContents : map [string ]string {
100
99
".hidden/test.yaml" : emptyFile ,
101
100
"k8pod.yml" : emptyFile ,
@@ -113,7 +112,7 @@ func TestWalk(t *testing.T) {
113
112
shouldErr : false ,
114
113
},
115
114
{
116
- name : "should not error when skaffold.config present and force = true" ,
115
+ description : "should not error when skaffold.config present and force = true" ,
117
116
filesWithContents : map [string ]string {
118
117
"skaffold.yaml" : `apiVersion: skaffold/v1beta6
119
118
kind: Config
@@ -137,7 +136,7 @@ deploy:
137
136
shouldErr : false ,
138
137
},
139
138
{
140
- name : "should error when skaffold.config present and force = false" ,
139
+ description : "should error when skaffold.config present and force = false" ,
141
140
filesWithContents : map [string ]string {
142
141
"config/test.yaml" : emptyFile ,
143
142
"k8pod.yml" : emptyFile ,
@@ -156,17 +155,16 @@ deploy:
156
155
},
157
156
}
158
157
for _ , test := range tests {
159
- t .Run (test .name , func (t * testing.T ) {
160
- testDir , deleteFunc := testutil .NewTempDir (t )
158
+ t .Run (test .description , func (t * testing.T ) {
159
+ testDir , cleanUp := testutil .NewTempDir (t )
160
+ defer cleanUp ()
161
161
rootDir := testDir .Root ()
162
- deleteFunc ()
163
162
writeAllFiles (testDir , test .filesWithContents )
164
163
potentialConfigs , dockerfiles , err := walk (rootDir , test .force , testValidDocker )
165
164
testutil .CheckErrorAndDeepEqual (t , test .shouldErr , err ,
166
165
testDir .Paths (test .expectedConfigs ), potentialConfigs )
167
166
testutil .CheckErrorAndDeepEqual (t , test .shouldErr , err ,
168
167
testDir .Paths (test .expectedDockerfiles ), dockerfiles )
169
- os .Remove (rootDir )
170
168
})
171
169
}
172
170
}
0 commit comments