@@ -351,6 +351,7 @@ func TestCollectConstraints(t *testing.T) {
351
351
cases := []struct {
352
352
name string
353
353
lock dep.Lock
354
+ manifest dep.Manifest
354
355
wantConstraints constraintsCollection
355
356
wantErr bool
356
357
}{
@@ -368,7 +369,7 @@ func TestCollectConstraints(t *testing.T) {
368
369
wantConstraints : constraintsCollection {},
369
370
},
370
371
{
371
- name : "with multiple constraints" ,
372
+ name : "with multiple constraints from dependencies " ,
372
373
lock : dep.Lock {
373
374
P : []gps.LockedProject {
374
375
gps .NewLockedProject (
@@ -401,6 +402,53 @@ func TestCollectConstraints(t *testing.T) {
401
402
},
402
403
},
403
404
},
405
+ {
406
+ name : "with multiple constraints from dependencies and root project" ,
407
+ lock : dep.Lock {
408
+ P : []gps.LockedProject {
409
+ gps .NewLockedProject (
410
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/sdboyer/deptest" )},
411
+ gps .NewVersion ("v1.0.0" ),
412
+ []string {"." },
413
+ ),
414
+ gps .NewLockedProject (
415
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-1" )},
416
+ gps .NewVersion ("v0.1.0" ),
417
+ []string {"." },
418
+ ),
419
+ gps .NewLockedProject (
420
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-2" )},
421
+ gps .NewBranch ("master" ).Pair (gps .Revision ("824a8d56a4c6b2f4718824a98cd6d70d3dbd4c3e" )),
422
+ []string {"." },
423
+ ),
424
+ },
425
+ },
426
+ manifest : dep.Manifest {
427
+ Constraints : map [gps.ProjectRoot ]gps.ProjectProperties {
428
+ gps .ProjectRoot ("github.com/sdboyer/deptest" ): {
429
+ Constraint : gps .Revision ("3f4c3bea144e112a69bbe5d8d01c1b09a544253f" ),
430
+ },
431
+ },
432
+ Ovr : make (gps.ProjectConstraints ),
433
+ PruneOptions : gps.CascadingPruneOptions {
434
+ DefaultOptions : gps .PruneNestedVendorDirs ,
435
+ PerProjectOptions : make (map [gps.ProjectRoot ]gps.PruneOptionSet ),
436
+ },
437
+ },
438
+ wantConstraints : constraintsCollection {
439
+ "github.com/sdboyer/deptestdos" : []projectConstraint {
440
+ {"github.com/darkowlzz/deptest-project-2" , ver2 },
441
+ },
442
+ "github.com/sdboyer/dep-test" : []projectConstraint {
443
+ {"github.com/darkowlzz/deptest-project-2" , ver1 },
444
+ },
445
+ "github.com/sdboyer/deptest" : []projectConstraint {
446
+ {"github.com/darkowlzz/deptest-project-1" , ver1 },
447
+ {"github.com/darkowlzz/deptest-project-2" , ver08 },
448
+ {"root" , gps .Revision ("3f4c3bea144e112a69bbe5d8d01c1b09a544253f" )},
449
+ },
450
+ },
451
+ },
404
452
{
405
453
name : "skip projects with invalid versions" ,
406
454
lock : dep.Lock {
@@ -444,6 +492,31 @@ func TestCollectConstraints(t *testing.T) {
444
492
},
445
493
},
446
494
},
495
+ {
496
+ name : "skip ineffective constraint from manifest" ,
497
+ lock : dep.Lock {
498
+ P : []gps.LockedProject {
499
+ gps .NewLockedProject (
500
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/sdboyer/deptest" )},
501
+ gps .NewVersion ("v1.0.0" ),
502
+ []string {"." },
503
+ ),
504
+ },
505
+ },
506
+ manifest : dep.Manifest {
507
+ Constraints : map [gps.ProjectRoot ]gps.ProjectProperties {
508
+ gps .ProjectRoot ("github.com/darkowlzz/deptest-project-1" ): {
509
+ Constraint : ver1 ,
510
+ },
511
+ },
512
+ Ovr : make (gps.ProjectConstraints ),
513
+ PruneOptions : gps.CascadingPruneOptions {
514
+ DefaultOptions : gps .PruneNestedVendorDirs ,
515
+ PerProjectOptions : make (map [gps.ProjectRoot ]gps.PruneOptionSet ),
516
+ },
517
+ },
518
+ wantConstraints : constraintsCollection {},
519
+ },
447
520
}
448
521
449
522
h := test .NewHelper (t )
@@ -474,6 +547,7 @@ func TestCollectConstraints(t *testing.T) {
474
547
for _ , c := range cases {
475
548
t .Run (c .name , func (t * testing.T ) {
476
549
p .Lock = & c .lock
550
+ p .Manifest = & c .manifest
477
551
gotConstraints , err := collectConstraints (ctx , p , sm )
478
552
if len (err ) > 0 && ! c .wantErr {
479
553
t .Fatalf ("unexpected errors while collecting constraints: %v" , err )
0 commit comments