@@ -334,48 +334,35 @@ case "$1" in
334
334
esac
335
335
`
336
336
337
- func TestTagXRepos (t * testing.T ) {
337
+ type tagXTestDeps struct {
338
+ ctx context.Context
339
+ gerrit * FakeGerrit
340
+ tagXTasks * TagXReposTasks
341
+ }
342
+
343
+ func newTagXTestDeps (t * testing.T , repos ... * FakeRepo ) * tagXTestDeps {
338
344
if runtime .GOOS != "linux" && runtime .GOOS != "darwin" {
339
345
t .Skip ("Requires bash shell scripting support." )
340
346
}
341
347
348
+ ctx , cancel := context .WithCancel (context .Background ())
349
+ t .Cleanup (cancel )
350
+
342
351
goServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
343
352
ServeTarball ("dl/go1.19.linux-amd64.tar.gz" , map [string ]string {
344
353
"go/bin/go" : fakeGo ,
345
354
}, w , r )
346
355
}))
347
356
t .Cleanup (goServer .Close )
348
357
349
- fakeBuildlets := NewFakeBuildlets (t , "" )
350
-
351
358
goRepo := NewFakeRepo (t , "go" )
352
359
go1 := goRepo .Commit (map [string ]string {
353
360
"main.go" : "I'm the go command or something" ,
354
361
})
355
- sys := NewFakeRepo (t , "sys" )
356
- sys1 := sys .Commit (map [string ]string {
357
- "go.mod" : "module golang.org/x/sys\n " ,
358
- "go.sum" : "\n " ,
359
- })
360
- sys .Tag ("v0.1.0" , sys1 )
361
- sys2 := sys .Commit (map [string ]string {
362
- "main.go" : "package main" ,
363
- })
364
- mod := NewFakeRepo (t , "mod" )
365
- mod1 := mod .Commit (map [string ]string {
366
- "go.mod" : "module golang.org/x/mod\n " ,
367
- "go.sum" : "\n " ,
368
- })
369
- mod .Tag ("v1.0.0" , mod1 )
370
- tools := NewFakeRepo (t , "tools" )
371
- tools1 := tools .Commit (map [string ]string {
372
- "go.mod" : "module golang.org/x/tools\n require golang.org/x/mod v1.0.0\n go 1.18 // tagx:compat 1.16\n require golang.org/x/sys v0.1.0\n " ,
373
- "go.sum" : "\n " ,
374
- "gopls/go.mod" : "module golang.org/x/tools/gopls\n require golang.org/x/mod v1.0.0\n " ,
375
- "gopls/go.sum" : "\n " ,
376
- })
377
- tools .Tag ("v1.1.5" , tools1 )
378
- fakeGerrit := NewFakeGerrit (t , goRepo , sys , mod , tools )
362
+ repos = append (repos , goRepo )
363
+
364
+ fakeBuildlets := NewFakeBuildlets (t , "" )
365
+ fakeGerrit := NewFakeGerrit (t , repos ... )
379
366
var builders , allOK []string
380
367
for _ , b := range dashboard .Builders {
381
368
builders = append (builders , b .Name )
@@ -391,7 +378,7 @@ func TestTagXRepos(t *testing.T) {
391
378
},
392
379
}
393
380
}
394
- for _ , r := range [] * FakeRepo { sys , mod , tools } {
381
+ for _ , r := range repos {
395
382
if repo != "golang.org/x/" + r .name {
396
383
continue
397
384
}
@@ -427,39 +414,73 @@ func TestTagXRepos(t *testing.T) {
427
414
return nil
428
415
},
429
416
}
430
- wd := tasks .NewDefinition ()
417
+ return & tagXTestDeps {
418
+ ctx : ctx ,
419
+ gerrit : fakeGerrit ,
420
+ tagXTasks : tasks ,
421
+ }
422
+ }
423
+
424
+ func TestTagXRepos (t * testing.T ) {
425
+ sys := NewFakeRepo (t , "sys" )
426
+ sys1 := sys .Commit (map [string ]string {
427
+ "go.mod" : "module golang.org/x/sys\n " ,
428
+ "go.sum" : "\n " ,
429
+ })
430
+ sys .Tag ("v0.1.0" , sys1 )
431
+ sys2 := sys .Commit (map [string ]string {
432
+ "main.go" : "package main" ,
433
+ })
434
+ mod := NewFakeRepo (t , "mod" )
435
+ mod1 := mod .Commit (map [string ]string {
436
+ "go.mod" : "module golang.org/x/mod\n " ,
437
+ "go.sum" : "\n " ,
438
+ })
439
+ mod .Tag ("v1.0.0" , mod1 )
440
+ tools := NewFakeRepo (t , "tools" )
441
+ tools1 := tools .Commit (map [string ]string {
442
+ "go.mod" : "module golang.org/x/tools\n require golang.org/x/mod v1.0.0\n go 1.18 // tagx:compat 1.16\n require golang.org/x/sys v0.1.0\n " ,
443
+ "go.sum" : "\n " ,
444
+ "gopls/go.mod" : "module golang.org/x/tools/gopls\n require golang.org/x/mod v1.0.0\n " ,
445
+ "gopls/go.sum" : "\n " ,
446
+ })
447
+ tools .Tag ("v1.1.5" , tools1 )
448
+
449
+ deps := newTagXTestDeps (t , sys , mod , tools )
450
+
451
+ wd := deps .tagXTasks .NewDefinition ()
431
452
w , err := workflow .Start (wd , nil )
432
453
if err != nil {
433
454
t .Fatal (err )
434
455
}
435
- ctx , cancel := context .WithTimeout (context . Background () , time .Minute )
456
+ ctx , cancel := context .WithTimeout (deps . ctx , time .Minute )
436
457
defer cancel ()
437
458
_ , err = w .Run (ctx , & verboseListener {t : t })
438
459
if err != nil {
439
460
t .Fatal (err )
440
461
}
441
462
442
- tag , err := fakeGerrit .GetTag (ctx , "sys" , "v0.2.0" )
463
+ tag , err := deps . gerrit .GetTag (ctx , "sys" , "v0.2.0" )
443
464
if err != nil {
444
465
t .Fatalf ("sys should have been tagged with v0.2.0: %v" , err )
445
466
}
446
467
if tag .Revision != sys2 {
447
468
t .Errorf ("sys v0.2.0 = %v, want %v" , tag .Revision , sys2 )
448
469
}
449
470
450
- tags , err := fakeGerrit .ListTags (ctx , "mod" )
471
+ tags , err := deps . gerrit .ListTags (ctx , "mod" )
451
472
if err != nil {
452
473
t .Fatal (err )
453
474
}
454
475
if ! reflect .DeepEqual (tags , []string {"v1.0.0" }) {
455
476
t .Errorf ("mod has tags %v, wanted only v1.0.0" , tags )
456
477
}
457
478
458
- tag , err = fakeGerrit .GetTag (ctx , "tools" , "v1.2.0" )
479
+ tag , err = deps . gerrit .GetTag (ctx , "tools" , "v1.2.0" )
459
480
if err != nil {
460
481
t .Fatalf ("tools should have been tagged with v1.2.0: %v" , err )
461
482
}
462
- goMod , err := fakeGerrit .ReadFile (ctx , "tools" , tag .Revision , "go.mod" )
483
+ goMod , err := deps . gerrit .ReadFile (ctx , "tools" , tag .Revision , "go.mod" )
463
484
if err != nil {
464
485
t .Fatal (err )
465
486
}
@@ -469,7 +490,7 @@ func TestTagXRepos(t *testing.T) {
469
490
if ! strings .Contains (string (goMod ), "tidied!" ) {
470
491
t .Error ("tools go.mod should be tidied" )
471
492
}
472
- goplsMod , err := fakeGerrit .ReadFile (ctx , "tools" , tag .Revision , "gopls/go.mod" )
493
+ goplsMod , err := deps . gerrit .ReadFile (ctx , "tools" , tag .Revision , "gopls/go.mod" )
473
494
if err != nil {
474
495
t .Fatal (err )
475
496
}
@@ -478,6 +499,52 @@ func TestTagXRepos(t *testing.T) {
478
499
}
479
500
}
480
501
502
+ func TestTagSingleRepo (t * testing.T ) {
503
+ mod := NewFakeRepo (t , "mod" )
504
+ mod1 := mod .Commit (map [string ]string {
505
+ "go.mod" : "module golang.org/x/mod\n " ,
506
+ "go.sum" : "\n " ,
507
+ })
508
+ mod .Tag ("v1.1.0" , mod1 )
509
+ foo := NewFakeRepo (t , "foo" )
510
+ foo1 := foo .Commit (map [string ]string {
511
+ "go.mod" : "module golang.org/x/foo\n require golang.org/x/mod v1.0.0\n " ,
512
+ "go.sum" : "\n " ,
513
+ })
514
+ foo .Tag ("v1.1.5" , foo1 )
515
+ foo .Commit (map [string ]string {
516
+ "main.go" : "package main" ,
517
+ })
518
+
519
+ deps := newTagXTestDeps (t , mod , foo )
520
+
521
+ wd := deps .tagXTasks .NewSingleDefinition ()
522
+ ctx , cancel := context .WithTimeout (deps .ctx , time .Minute )
523
+ w , err := workflow .Start (wd , map [string ]interface {}{
524
+ "Repository name" : "foo" ,
525
+ })
526
+ if err != nil {
527
+ t .Fatal (err )
528
+ }
529
+ defer cancel ()
530
+ _ , err = w .Run (ctx , & verboseListener {t : t })
531
+ if err != nil {
532
+ t .Fatal (err )
533
+ }
534
+
535
+ tag , err := deps .gerrit .GetTag (ctx , "foo" , "v1.2.0" )
536
+ if err != nil {
537
+ t .Fatalf ("foo should have been tagged with v1.2.0: %v" , err )
538
+ }
539
+ goMod , err := deps .gerrit .ReadFile (ctx , "foo" , tag .Revision , "go.mod" )
540
+ if err != nil {
541
+ t .Fatal (err )
542
+ }
543
+ if ! strings .
Contains (
string (
goMod ),
"[email protected] " ) {
544
+ t .Errorf ("foo should use mod v1.1.0. go.mod: %v" , string (goMod ))
545
+ }
546
+ }
547
+
481
548
type verboseListener struct {
482
549
t * testing.T
483
550
outputListener func (string , interface {})
0 commit comments