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