@@ -298,48 +298,50 @@ func TestCollectConstraints(t *testing.T) {
298
298
ver2 , _ := gps .NewSemverConstraintIC ("v2.0.0" )
299
299
300
300
cases := []struct {
301
- name string
302
- project dep.Project
301
+ name string
302
+ // project dep.Project
303
+ lock dep.Lock
303
304
wantConstraints constraintsCollection
305
+ wantErr bool
304
306
}{
305
307
{
306
308
name : "without any constraints" ,
307
- project : dep.Project {
308
- Lock : & dep.Lock {
309
- P : []gps.LockedProject {
310
- gps .NewLockedProject (
311
- gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/sdboyer/deptest" )},
312
- gps .NewVersion ("v1.0.0" ),
313
- []string {"." },
314
- ),
315
- },
309
+ // project: dep.Project{
310
+ lock : dep.Lock {
311
+ P : []gps.LockedProject {
312
+ gps .NewLockedProject (
313
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/sdboyer/deptest" )},
314
+ gps .NewVersion ("v1.0.0" ),
315
+ []string {"." },
316
+ ),
316
317
},
317
318
},
319
+ // },
318
320
wantConstraints : constraintsCollection {},
319
321
},
320
322
{
321
323
name : "with multiple constraints" ,
322
- project : dep.Project {
323
- Lock : & dep.Lock {
324
- P : []gps.LockedProject {
325
- gps .NewLockedProject (
326
- gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/sdboyer/deptest" )},
327
- gps .NewVersion ("v1.0.0" ),
328
- []string {"." },
329
- ),
330
- gps .NewLockedProject (
331
- gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-1" )},
332
- gps .NewVersion ("v0.1.0" ),
333
- []string {"." },
334
- ),
335
- gps .NewLockedProject (
336
- gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-2" )},
337
- gps .NewBranch ("master" ).Pair (gps .Revision ("824a8d56a4c6b2f4718824a98cd6d70d3dbd4c3e" )),
338
- []string {"." },
339
- ),
340
- },
324
+ // project: dep.Project{
325
+ lock : dep.Lock {
326
+ P : []gps.LockedProject {
327
+ gps .NewLockedProject (
328
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/sdboyer/deptest" )},
329
+ gps .NewVersion ("v1.0.0" ),
330
+ []string {"." },
331
+ ),
332
+ gps .NewLockedProject (
333
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-1" )},
334
+ gps .NewVersion ("v0.1.0" ),
335
+ []string {"." },
336
+ ),
337
+ gps .NewLockedProject (
338
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-2" )},
339
+ gps .NewBranch ("master" ).Pair (gps .Revision ("824a8d56a4c6b2f4718824a98cd6d70d3dbd4c3e" )),
340
+ []string {"." },
341
+ ),
341
342
},
342
343
},
344
+ // },
343
345
wantConstraints : constraintsCollection {
344
346
"github.com/sdboyer/deptestdos" : []projectConstraint {
345
347
{"github.com/darkowlzz/deptest-project-2" , ver2 },
@@ -355,27 +357,28 @@ func TestCollectConstraints(t *testing.T) {
355
357
},
356
358
{
357
359
name : "skip projects with invalid versions" ,
358
- project : dep.Project {
359
- Lock : & dep.Lock {
360
- P : []gps.LockedProject {
361
- gps .NewLockedProject (
362
- gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-1" )},
363
- gps .NewVersion ("v0.1.0" ),
364
- []string {"." },
365
- ),
366
- gps .NewLockedProject (
367
- gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-2" )},
368
- gps .NewVersion ("v1.0.0" ),
369
- []string {"." },
370
- ),
371
- },
360
+ // project: dep.Project{
361
+ lock : dep.Lock {
362
+ P : []gps.LockedProject {
363
+ gps .NewLockedProject (
364
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-1" )},
365
+ gps .NewVersion ("v0.1.0" ),
366
+ []string {"." },
367
+ ),
368
+ gps .NewLockedProject (
369
+ gps.ProjectIdentifier {ProjectRoot : gps .ProjectRoot ("github.com/darkowlzz/deptest-project-2" )},
370
+ gps .NewVersion ("v1.0.0" ),
371
+ []string {"." },
372
+ ),
372
373
},
373
374
},
375
+ // },
374
376
wantConstraints : constraintsCollection {
375
377
"github.com/sdboyer/deptest" : []projectConstraint {
376
378
{"github.com/darkowlzz/deptest-project-1" , ver1 },
377
379
},
378
380
},
381
+ wantErr : true ,
379
382
},
380
383
}
381
384
@@ -396,12 +399,20 @@ func TestCollectConstraints(t *testing.T) {
396
399
h .Must (err )
397
400
defer sm .Release ()
398
401
402
+ p := new (dep.Project )
403
+
399
404
for _ , c := range cases {
400
405
t .Run (c .name , func (t * testing.T ) {
401
- gotConstraints , _ := collectConstraints (ctx , & c .project , sm )
406
+ p .Lock = & c .lock
407
+ gotConstraints , err := collectConstraints (ctx , p , sm )
408
+ if len (err ) > 0 && ! c .wantErr {
409
+ t .Fatalf ("unexpected errors while collecting constraints: %v" , err )
410
+ } else if len (err ) == 0 && c .wantErr {
411
+ t .Fatalf ("expected errors while collecting constraints, but got none" )
412
+ }
402
413
403
414
if ! reflect .DeepEqual (gotConstraints , c .wantConstraints ) {
404
- t .Fatalf ("Unexpected collected constraints: \n \t (GOT): %v\n \t (WNT): %v" , gotConstraints , c .wantConstraints )
415
+ t .Fatalf ("unexpected collected constraints: \n \t (GOT): %v\n \t (WNT): %v" , gotConstraints , c .wantConstraints )
405
416
}
406
417
})
407
418
}
0 commit comments