@@ -87,66 +87,63 @@ func TestNoTest(t *testing.T) {
87
87
}
88
88
89
89
func TestTestSuccess (t * testing.T ) {
90
- tmpDir , cleanup := testutil .NewTempDir (t )
91
- defer cleanup ()
92
-
93
- tmpDir .Touch ("tests/test1.yaml" , "tests/test2.yaml" , "test3.yaml" )
94
-
95
- defer func (c util.Command ) { util .DefaultExecCommand = c }(util .DefaultExecCommand )
96
- util .DefaultExecCommand = testutil .
97
- NewFakeCmd (t ).
98
- WithRun ("container-structure-test test -v warn --image TAG --config " + tmpDir .Path ("tests/test1.yaml" ) + " --config " + tmpDir .Path ("tests/test2.yaml" )).
99
- WithRun ("container-structure-test test -v warn --image TAG --config " + tmpDir .Path ("test3.yaml" ))
100
-
101
- runCtx := & runcontext.RunContext {
102
- WorkingDir : tmpDir .Root (),
103
- Cfg : latest.Pipeline {
104
- Test : []* latest.TestCase {
105
- {
106
- ImageName : "image" ,
107
- StructureTests : []string {"./tests/*" },
108
- },
109
- {},
110
- {
111
- ImageName : "image" ,
112
- StructureTests : []string {"test3.yaml" },
90
+ testutil .Run (t , "" , func (t * testutil.T ) {
91
+ tmpDir := t .NewTempDir ()
92
+ tmpDir .Touch ("tests/test1.yaml" , "tests/test2.yaml" , "test3.yaml" )
93
+
94
+ fakeCmd := t .NewFakeCmd ().
95
+ WithRun ("container-structure-test test -v warn --image TAG --config " + tmpDir .Path ("tests/test1.yaml" ) + " --config " + tmpDir .Path ("tests/test2.yaml" )).
96
+ WithRun ("container-structure-test test -v warn --image TAG --config " + tmpDir .Path ("test3.yaml" ))
97
+ t .Override (& util .DefaultExecCommand , fakeCmd )
98
+
99
+ runCtx := & runcontext.RunContext {
100
+ WorkingDir : tmpDir .Root (),
101
+ Cfg : latest.Pipeline {
102
+ Test : []* latest.TestCase {
103
+ {
104
+ ImageName : "image" ,
105
+ StructureTests : []string {"./tests/*" },
106
+ },
107
+ {},
108
+ {
109
+ ImageName : "image" ,
110
+ StructureTests : []string {"test3.yaml" },
111
+ },
113
112
},
114
113
},
115
- },
116
- }
114
+ }
117
115
118
- err := NewTester (runCtx ).Test (context .Background (), ioutil .Discard , []build.Artifact {{
119
- ImageName : "image" ,
120
- Tag : "TAG" ,
121
- }})
116
+ err := NewTester (runCtx ).Test (context .Background (), ioutil .Discard , []build.Artifact {{
117
+ ImageName : "image" ,
118
+ Tag : "TAG" ,
119
+ }})
122
120
123
- testutil .CheckError (t , false , err )
121
+ t .CheckError (false , err )
122
+ })
124
123
}
125
124
126
125
func TestTestFailure (t * testing.T ) {
127
- tmpDir , cleanup := testutil .NewTempDir (t )
128
- defer cleanup ()
129
-
130
- tmpDir .Touch ("test.yaml" )
131
-
132
- defer func (c util.Command ) { util .DefaultExecCommand = c }(util .DefaultExecCommand )
133
- util .DefaultExecCommand = testutil .
134
- NewFakeCmd (t ).
135
- WithRunErr ("container-structure-test test -v warn --image broken-image --config " + tmpDir .Path ("test.yaml" ), errors .New ("FAIL" ))
136
-
137
- runCtx := & runcontext.RunContext {
138
- WorkingDir : tmpDir .Root (),
139
- Cfg : latest.Pipeline {
140
- Test : []* latest.TestCase {
141
- {
142
- ImageName : "broken-image" ,
143
- StructureTests : []string {"test.yaml" },
126
+ testutil .Run (t , "" , func (t * testutil.T ) {
127
+ tmpDir := t .NewTempDir ()
128
+ tmpDir .Touch ("test.yaml" )
129
+
130
+ fakeCmd := t .NewFakeCmd ().
131
+ WithRunErr ("container-structure-test test -v warn --image broken-image --config " + tmpDir .Path ("test.yaml" ), errors .New ("FAIL" ))
132
+ t .Override (& util .DefaultExecCommand , fakeCmd )
133
+
134
+ runCtx := & runcontext.RunContext {
135
+ WorkingDir : tmpDir .Root (),
136
+ Cfg : latest.Pipeline {
137
+ Test : []* latest.TestCase {
138
+ {
139
+ ImageName : "broken-image" ,
140
+ StructureTests : []string {"test.yaml" },
141
+ },
144
142
},
145
143
},
146
- },
147
- }
148
-
149
- err := NewTester (runCtx ).Test (context .Background (), ioutil .Discard , []build.Artifact {{}})
144
+ }
150
145
151
- testutil .CheckError (t , true , err )
146
+ err := NewTester (runCtx ).Test (context .Background (), ioutil .Discard , []build.Artifact {{}})
147
+ t .CheckError (true , err )
148
+ })
152
149
}
0 commit comments