@@ -31,6 +31,7 @@ import (
31
31
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy"
32
32
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
33
33
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
34
+ "github.com/GoogleContainerTools/skaffold/pkg/skaffold/test"
34
35
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/watch"
35
36
"github.com/GoogleContainerTools/skaffold/testutil"
36
37
clientgo "k8s.io/client-go/kubernetes"
@@ -65,6 +66,23 @@ func (t *TestBuilder) Build(ctx context.Context, w io.Writer, tagger tag.Tagger,
65
66
return builds , nil
66
67
}
67
68
69
+ type TestTester struct {
70
+ errors []error
71
+ }
72
+
73
+ func (t * TestTester ) Test (out io.Writer , builds []build.Artifact ) error {
74
+ if len (t .errors ) > 0 {
75
+ err := t .errors [0 ]
76
+ t .errors = t .errors [1 :]
77
+ return err
78
+ }
79
+ return nil
80
+ }
81
+
82
+ func (t * TestTester ) TestDependencies () []string {
83
+ return []string {}
84
+ }
85
+
68
86
type TestDeployer struct {
69
87
deployed []build.Artifact
70
88
errors []error
@@ -140,6 +158,7 @@ func TestNewForConfig(t *testing.T) {
140
158
config * latest.SkaffoldConfig
141
159
shouldErr bool
142
160
expectedBuilder build.Builder
161
+ expectedTester test.Tester
143
162
expectedDeployer deploy.Deployer
144
163
}{
145
164
{
@@ -158,6 +177,7 @@ func TestNewForConfig(t *testing.T) {
158
177
},
159
178
},
160
179
expectedBuilder : & local.Builder {},
180
+ expectedTester : & test.FullTester {},
161
181
expectedDeployer : & deploy.KubectlDeployer {},
162
182
},
163
183
{
@@ -184,6 +204,7 @@ func TestNewForConfig(t *testing.T) {
184
204
},
185
205
shouldErr : true ,
186
206
expectedBuilder : & local.Builder {},
207
+ expectedTester : & test.FullTester {},
187
208
expectedDeployer : & deploy.KubectlDeployer {},
188
209
},
189
210
{
@@ -197,6 +218,7 @@ func TestNewForConfig(t *testing.T) {
197
218
}},
198
219
shouldErr : true ,
199
220
expectedBuilder : & local.Builder {},
221
+ expectedTester : & test.FullTester {},
200
222
expectedDeployer : & deploy.KubectlDeployer {},
201
223
},
202
224
{
@@ -218,9 +240,10 @@ func TestNewForConfig(t *testing.T) {
218
240
219
241
testutil .CheckError (t , test .shouldErr , err )
220
242
if cfg != nil {
221
- b , d := WithTimings (test .expectedBuilder , test .expectedDeployer )
243
+ b , _t , d := WithTimings (test .expectedBuilder , test . expectedTester , test .expectedDeployer )
222
244
223
245
testutil .CheckErrorAndTypeEquality (t , test .shouldErr , err , b , cfg .Builder )
246
+ testutil .CheckErrorAndTypeEquality (t , test .shouldErr , err , _t , cfg .Tester )
224
247
testutil .CheckErrorAndTypeEquality (t , test .shouldErr , err , d , cfg .Deployer )
225
248
}
226
249
})
@@ -232,13 +255,15 @@ func TestRun(t *testing.T) {
232
255
description string
233
256
config * latest.SkaffoldConfig
234
257
builder build.Builder
258
+ tester test.Tester
235
259
deployer deploy.Deployer
236
260
shouldErr bool
237
261
}{
238
262
{
239
263
description : "run no error" ,
240
264
config : & latest.SkaffoldConfig {},
241
265
builder : & TestBuilder {},
266
+ tester : & TestTester {},
242
267
deployer : & TestDeployer {},
243
268
},
244
269
{
@@ -247,6 +272,7 @@ func TestRun(t *testing.T) {
247
272
builder : & TestBuilder {
248
273
errors : []error {fmt .Errorf ("" )},
249
274
},
275
+ tester : & TestTester {},
250
276
shouldErr : true ,
251
277
},
252
278
{
@@ -261,17 +287,42 @@ func TestRun(t *testing.T) {
261
287
},
262
288
},
263
289
builder : & TestBuilder {},
290
+ tester : & TestTester {},
264
291
deployer : & TestDeployer {
265
292
errors : []error {fmt .Errorf ("" )},
266
293
},
267
294
shouldErr : true ,
268
295
},
296
+ {
297
+ description : "run test error" ,
298
+ config : & latest.SkaffoldConfig {
299
+ Build : latest.BuildConfig {
300
+ Artifacts : []* latest.Artifact {
301
+ {
302
+ ImageName : "test" ,
303
+ },
304
+ },
305
+ },
306
+ Test : []latest.TestCase {
307
+ {
308
+ ImageName : "test" ,
309
+ StructureTests : []string {"fake_file.yaml" },
310
+ },
311
+ },
312
+ },
313
+ builder : & TestBuilder {},
314
+ tester : & TestTester {
315
+ errors : []error {fmt .Errorf ("" )},
316
+ },
317
+ shouldErr : true ,
318
+ },
269
319
}
270
320
271
321
for _ , test := range tests {
272
322
t .Run (test .description , func (t * testing.T ) {
273
323
runner := & SkaffoldRunner {
274
324
Builder : test .builder ,
325
+ Tester : test .tester ,
275
326
Deployer : test .deployer ,
276
327
Tagger : & tag.ChecksumTagger {},
277
328
opts : & config.SkaffoldOptions {},
@@ -290,6 +341,7 @@ func TestDev(t *testing.T) {
290
341
var tests = []struct {
291
342
description string
292
343
builder build.Builder
344
+ tester test.Tester
293
345
deployer deploy.Deployer
294
346
watcherFactory watch.Factory
295
347
shouldErr bool
@@ -306,23 +358,35 @@ func TestDev(t *testing.T) {
306
358
{
307
359
description : "fails to deploy the first time" ,
308
360
builder : & TestBuilder {},
361
+ tester : & TestTester {},
309
362
deployer : & TestDeployer {
310
363
errors : []error {fmt .Errorf ("" )},
311
364
},
312
365
watcherFactory : NewWatcherFactory (nil , nil ),
313
366
shouldErr : true ,
314
367
},
368
+ {
369
+ description : "fails to deploy due to failed tests" ,
370
+ builder : & TestBuilder {},
371
+ tester : & TestTester {
372
+ errors : []error {fmt .Errorf ("" )},
373
+ },
374
+ watcherFactory : NewWatcherFactory (nil , nil ),
375
+ shouldErr : true ,
376
+ },
315
377
{
316
378
description : "ignore subsequent build errors" ,
317
379
builder : & TestBuilder {
318
380
errors : []error {nil , fmt .Errorf ("" )},
319
381
},
382
+ tester : & TestTester {},
320
383
deployer : & TestDeployer {},
321
384
watcherFactory : NewWatcherFactory (nil , nil , nil ),
322
385
},
323
386
{
324
387
description : "ignore subsequent deploy errors" ,
325
388
builder : & TestBuilder {},
389
+ tester : & TestTester {},
326
390
deployer : & TestDeployer {
327
391
errors : []error {nil , fmt .Errorf ("" )},
328
392
},
@@ -331,6 +395,7 @@ func TestDev(t *testing.T) {
331
395
{
332
396
description : "fail to watch files" ,
333
397
builder : & TestBuilder {},
398
+ tester : & TestTester {},
334
399
deployer : & TestDeployer {},
335
400
watcherFactory : NewWatcherFactory (fmt .Errorf ("" ), nil ),
336
401
shouldErr : true ,
@@ -341,6 +406,7 @@ func TestDev(t *testing.T) {
341
406
t .Run (test .description , func (t * testing.T ) {
342
407
runner := & SkaffoldRunner {
343
408
Builder : test .builder ,
409
+ Tester : test .tester ,
344
410
Deployer : test .deployer ,
345
411
Tagger : & tag.ChecksumTagger {},
346
412
watchFactory : test .watcherFactory ,
@@ -360,6 +426,7 @@ func TestBuildAndDeployAllArtifacts(t *testing.T) {
360
426
defer resetClient ()
361
427
362
428
builder := & TestBuilder {}
429
+ tester := & TestTester {}
363
430
deployer := & TestDeployer {}
364
431
artifacts := []* latest.Artifact {
365
432
{ImageName : "image1" },
@@ -368,6 +435,7 @@ func TestBuildAndDeployAllArtifacts(t *testing.T) {
368
435
369
436
runner := & SkaffoldRunner {
370
437
Builder : builder ,
438
+ Tester : tester ,
371
439
Deployer : deployer ,
372
440
opts : & config.SkaffoldOptions {},
373
441
}
0 commit comments