@@ -42,11 +42,7 @@ var buildTests = []func(t *testing.T, sb integration.Sandbox){
42
42
testBuildDetailsLink ,
43
43
testBuildProgress ,
44
44
testBuildAnnotations ,
45
- testBuildBuildArgNoKey ,
46
- testBuildLabelNoKey ,
47
- testBuildCacheExportNotSupported ,
48
- testBuildOCIExportNotSupported ,
49
- testBuildMultiPlatformNotSupported ,
45
+ testInvalidArgs ,
50
46
}
51
47
52
48
func testBuild (t * testing.T , sb integration.Sandbox ) {
@@ -364,54 +360,54 @@ func testBuildAnnotations(t *testing.T, sb integration.Sandbox) {
364
360
assert .Equal (t , "zzz" , img .Desc .Annotations ["example4" ])
365
361
}
366
362
367
- func testBuildBuildArgNoKey (t * testing.T , sb integration.Sandbox ) {
363
+ func testInvalidArgs (t * testing.T , sb integration.Sandbox ) {
368
364
dir := createTestProject (t )
369
- cmd := buildxCmd (sb , withArgs ("build" , "--build-arg" , "=TEST_STRING" , dir ))
370
- out , err := cmd .CombinedOutput ()
371
- require .Error (t , err , string (out ))
372
- require .Equal (t , strings .TrimSpace (string (out )), `ERROR: invalid key-value pair "=TEST_STRING": empty key` )
373
- }
374
-
375
- func testBuildLabelNoKey (t * testing.T , sb integration.Sandbox ) {
376
- dir := createTestProject (t )
377
- cmd := buildxCmd (sb , withArgs ("build" , "--label" , "=TEST_STRING" , dir ))
378
- out , err := cmd .CombinedOutput ()
379
- require .Error (t , err , string (out ))
380
- require .Equal (t , strings .TrimSpace (string (out )), `ERROR: invalid key-value pair "=TEST_STRING": empty key` )
381
- }
382
-
383
- func testBuildCacheExportNotSupported (t * testing.T , sb integration.Sandbox ) {
384
- if sb .Name () != "docker" {
385
- t .Skip ("skipping test for non-docker workers" )
386
- }
387
-
388
- dir := createTestProject (t )
389
- cmd := buildxCmd (sb , withArgs ("build" , "--cache-to=type=registry" , dir ))
390
- out , err := cmd .CombinedOutput ()
391
- require .Error (t , err , string (out ))
392
- require .Contains (t , string (out ), "Cache export is not supported" )
393
- }
394
365
395
- func testBuildOCIExportNotSupported (t * testing.T , sb integration.Sandbox ) {
396
- if sb .Name () != "docker" {
397
- t .Skip ("skipping test for non-docker workers" )
366
+ tests := []struct {
367
+ name string
368
+ args []string
369
+ expectedErr string
370
+ driver string
371
+ }{
372
+ {
373
+ name : "build-arg without key" ,
374
+ args : []string {"--build-arg" , "=TEST_STRING" , dir },
375
+ expectedErr : `ERROR: invalid key-value pair "=TEST_STRING": empty key` ,
376
+ },
377
+ {
378
+ name : "label without key" ,
379
+ args : []string {"--label" , "=TEST_STRING" , dir },
380
+ expectedErr : `ERROR: invalid key-value pair "=TEST_STRING": empty key` ,
381
+ },
382
+ {
383
+ name : "cache-to not supported" ,
384
+ args : []string {"--cache-to=type=registry" , dir },
385
+ expectedErr : "Cache export is not supported" ,
386
+ driver : "docker" ,
387
+ },
388
+ {
389
+ name : "oci not supported" ,
390
+ args : []string {fmt .Sprintf ("--output=type=oci,dest=%s/result" , dir ), dir },
391
+ expectedErr : "OCI exporter is not supported" ,
392
+ driver : "docker" ,
393
+ },
394
+ {
395
+ name : "multiple platforms not supported" ,
396
+ args : []string {"--platform=linux/amd64,linux/arm64" , dir },
397
+ expectedErr : "Multi-platform build is not supported" ,
398
+ driver : "docker" ,
399
+ },
398
400
}
399
-
400
- dir := createTestProject ( t )
401
- cmd := buildxCmd ( sb , withArgs ( "build" , fmt . Sprintf ( "--output=type=oci,dest=%s/result" , dir ), dir ))
402
- out , err := cmd . CombinedOutput ()
403
- require . Error ( t , err , string ( out ) )
404
- require . Contains ( t , string ( out ), "OCI exporter is not supported" )
405
- }
406
-
407
- func testBuildMultiPlatformNotSupported ( t * testing. T , sb integration. Sandbox ) {
408
- if sb . Name () != "docker" {
409
- t . Skip ( "skipping test for non-docker workers" )
401
+ for _ , tc := range tests {
402
+ tc := tc
403
+ t . Run ( tc . name , func ( t * testing. T ) {
404
+ if tc . driver != "" && sb . Name () != tc . driver {
405
+ t . Skipf ( "skipping test for non-%s workers" , tc . driver )
406
+ }
407
+
408
+ out , err := buildxCmd ( sb , withCommandAndArgs ( "build" , tc . args ... )). CombinedOutput ()
409
+ require . Error ( t , err , string ( out ))
410
+ require . Contains ( t , string ( out ), tc . expectedErr )
411
+ } )
410
412
}
411
-
412
- dir := createTestProject (t )
413
- cmd := buildxCmd (sb , withArgs ("build" , "--platform=linux/amd64,linux/arm64" , dir ))
414
- out , err := cmd .CombinedOutput ()
415
- require .Error (t , err , string (out ))
416
- require .Contains (t , string (out ), "Multi-platform build is not supported" )
417
413
}
0 commit comments