@@ -7,6 +7,7 @@ package dep
7
7
import (
8
8
"bytes"
9
9
"errors"
10
+ "fmt"
10
11
"io/ioutil"
11
12
"log"
12
13
"reflect"
@@ -47,7 +48,8 @@ func TestReadManifest(t *testing.T) {
47
48
Ignored : []string {"github.com/foo/bar" },
48
49
PruneOptions : gps .PruneNestedVendorDirs | gps .PruneNonGoFiles ,
49
50
PruneProjectOptions : gps.PruneProjectOptions {
50
- gps .ProjectRoot ("github.com/golang/dep" ): gps .PruneNestedVendorDirs ,
51
+ gps .ProjectRoot ("github.com/golang/dep" ): gps .PruneNestedVendorDirs ,
52
+ gps .ProjectRoot ("github.com/babble/brook" ): gps .PruneNestedVendorDirs | gps .PruneGoTestFiles ,
51
53
},
52
54
}
53
55
@@ -82,11 +84,6 @@ func TestWriteManifest(t *testing.T) {
82
84
}
83
85
m .Ignored = []string {"github.com/foo/bar" }
84
86
85
- m .PruneOptions = gps .PruneNestedVendorDirs | gps .PruneNonGoFiles
86
- m .PruneProjectOptions = gps.PruneProjectOptions {
87
- gps .ProjectRoot ("github.com/golang/dep" ): gps .PruneNestedVendorDirs ,
88
- }
89
-
90
87
got , err := m .MarshalTOML ()
91
88
if err != nil {
92
89
t .Fatalf ("error while marshaling valid manifest to TOML: %q" , err )
@@ -364,7 +361,9 @@ func TestValidateManifest(t *testing.T) {
364
361
name = "github.com/foo/bar"
365
362
revision = "b86ad16"
366
363
` ,
367
- wantWarn : []error {errors .New ("revision \" b86ad16\" should not be in abbreviated form" )},
364
+ wantWarn : []error {
365
+ errors .New ("revision \" b86ad16\" should not be in abbreviated form" ),
366
+ },
368
367
wantError : nil ,
369
368
},
370
369
{
@@ -380,10 +379,6 @@ func TestValidateManifest(t *testing.T) {
380
379
{
381
380
name : "valid prune options" ,
382
381
tomlString : `
383
- [[constraint]]
384
- name = "github.com/foo/bar"
385
- version = "1.0.0"
386
-
387
382
[prune]
388
383
non-go = true
389
384
` ,
@@ -393,26 +388,37 @@ func TestValidateManifest(t *testing.T) {
393
388
{
394
389
name : "invalid root prune options" ,
395
390
tomlString : `
396
- [[constraint]]
397
- name = "github.com/foo/bar"
398
- version = "1.0.0"
399
-
400
391
[prune]
401
392
non-go = false
402
393
` ,
403
394
wantWarn : []error {},
404
395
wantError : errInvalidRootPruneValue ,
405
396
},
406
- }
397
+ {
398
+ name : "root options should not contain a name" ,
399
+ tomlString : `
400
+ [prune]
401
+ go-tests = true
402
+ name = "github.com/golang/dep"
403
+ ` ,
404
+ wantWarn : []error {
405
+ fmt .Errorf ("%q should not include a name" , "prune" ),
406
+ },
407
+ wantError : nil ,
408
+ },
409
+ {
410
+ name : "invalid prune project" ,
411
+ tomlString : `
412
+ [prune]
413
+ non-go = true
407
414
408
- // contains for error
409
- contains := func (s []error , e error ) bool {
410
- for _ , a := range s {
411
- if a .Error () == e .Error () {
412
- return true
413
- }
414
- }
415
- return false
415
+ [prune.project]
416
+ name = "github.com/org/project"
417
+ non-go = true
418
+ ` ,
419
+ wantWarn : []error {},
420
+ wantError : errInvalidPruneProject ,
421
+ },
416
422
}
417
423
418
424
for _ , c := range cases {
@@ -431,14 +437,55 @@ func TestValidateManifest(t *testing.T) {
431
437
432
438
// check if the expected errors exist in actual errors slice
433
439
for _ , er := range errs {
434
- if ! contains (c .wantWarn , er ) {
440
+ if ! containsErr (c .wantWarn , er ) {
435
441
t .Fatalf ("manifest errors are not as expected: \n \t (MISSING) %v\n \t (FROM) %v" , er , c .wantWarn )
436
442
}
437
443
}
438
444
})
439
445
}
440
446
}
441
447
448
+ func TestCheckRedundantPruneOptions (t * testing.T ) {
449
+ cases := []struct {
450
+ name string
451
+ pruneOptions rawPruneOptions
452
+ wantWarn []error
453
+ }{
454
+ {
455
+ name : "redundant project prune options" ,
456
+ pruneOptions : rawPruneOptions {
457
+ NonGoFiles : true ,
458
+ Projects : []rawPruneProjectOptions {
459
+ rawPruneProjectOptions {
460
+ Name : "github.com/org/project" ,
461
+ NonGoFiles : true ,
462
+ },
463
+ },
464
+ },
465
+ wantWarn : []error {
466
+ fmt .Errorf ("redundant prune option %q set for %q" , "non-go" , "github.com/org/project" ),
467
+ },
468
+ },
469
+ }
470
+
471
+ for _ , c := range cases {
472
+ t .Run (c .name , func (t * testing.T ) {
473
+ errs := checkRedundantPruneOptions (rawManifest {PruneOptions : c .pruneOptions })
474
+
475
+ // compare length of error slice
476
+ if len (errs ) != len (c .wantWarn ) {
477
+ t .Fatalf ("number of manifest errors are not as expected:\n \t (GOT) %v errors(%v)\n \t (WNT) %v errors(%v)." , len (errs ), errs , len (c .wantWarn ), c .wantWarn )
478
+ }
479
+
480
+ for _ , er := range errs {
481
+ if ! containsErr (c .wantWarn , er ) {
482
+ t .Fatalf ("manifest errors are not as expected:\n \t (MISSING)\n %v\n \t (FROM)\n %v" , er , c .wantWarn )
483
+ }
484
+ }
485
+ })
486
+ }
487
+ }
488
+
442
489
func TestValidateProjectRoots (t * testing.T ) {
443
490
cases := []struct {
444
491
name string
@@ -545,3 +592,16 @@ func TestValidateProjectRoots(t *testing.T) {
545
592
})
546
593
}
547
594
}
595
+
596
+ func TestPruneOptionsFor (t * testing.T ) {
597
+
598
+ }
599
+
600
+ func containsErr (s []error , e error ) bool {
601
+ for _ , a := range s {
602
+ if a .Error () == e .Error () {
603
+ return true
604
+ }
605
+ }
606
+ return false
607
+ }
0 commit comments