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