@@ -7,6 +7,7 @@ package dep
77import (
88 "bytes"
99 "errors"
10+ "fmt"
1011 "io/ioutil"
1112 "log"
1213 "reflect"
@@ -47,7 +48,8 @@ func TestReadManifest(t *testing.T) {
4748 Ignored : []string {"github.com/foo/bar" },
4849 PruneOptions : gps .PruneNestedVendorDirs | gps .PruneNonGoFiles ,
4950 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 ,
5153 },
5254 }
5355
@@ -82,11 +84,6 @@ func TestWriteManifest(t *testing.T) {
8284 }
8385 m .Ignored = []string {"github.com/foo/bar" }
8486
85- m .PruneOptions = gps .PruneNestedVendorDirs | gps .PruneNonGoFiles
86- m .PruneProjectOptions = gps.PruneProjectOptions {
87- gps .ProjectRoot ("github.com/golang/dep" ): gps .PruneNestedVendorDirs ,
88- }
89-
9087 got , err := m .MarshalTOML ()
9188 if err != nil {
9289 t .Fatalf ("error while marshaling valid manifest to TOML: %q" , err )
@@ -364,7 +361,9 @@ func TestValidateManifest(t *testing.T) {
364361 name = "github.com/foo/bar"
365362 revision = "b86ad16"
366363 ` ,
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+ },
368367 wantError : nil ,
369368 },
370369 {
@@ -380,10 +379,6 @@ func TestValidateManifest(t *testing.T) {
380379 {
381380 name : "valid prune options" ,
382381 tomlString : `
383- [[constraint]]
384- name = "github.com/foo/bar"
385- version = "1.0.0"
386-
387382 [prune]
388383 non-go = true
389384 ` ,
@@ -393,26 +388,37 @@ func TestValidateManifest(t *testing.T) {
393388 {
394389 name : "invalid root prune options" ,
395390 tomlString : `
396- [[constraint]]
397- name = "github.com/foo/bar"
398- version = "1.0.0"
399-
400391 [prune]
401392 non-go = false
402393 ` ,
403394 wantWarn : []error {},
404395 wantError : errInvalidRootPruneValue ,
405396 },
406- }
397+ {
398+ name : "root options should not contain a name" ,
399+ tomlString : `
400+ [prune]
401+ non-go = 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
407414
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+ },
416422 }
417423
418424 for _ , c := range cases {
@@ -431,14 +437,55 @@ func TestValidateManifest(t *testing.T) {
431437
432438 // check if the expected errors exist in actual errors slice
433439 for _ , er := range errs {
434- if ! contains (c .wantWarn , er ) {
440+ if ! containsErr (c .wantWarn , er ) {
435441 t .Fatalf ("manifest errors are not as expected: \n \t (MISSING) %v\n \t (FROM) %v" , er , c .wantWarn )
436442 }
437443 }
438444 })
439445 }
440446}
441447
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+
442489func TestValidateProjectRoots (t * testing.T ) {
443490 cases := []struct {
444491 name string
@@ -545,3 +592,16 @@ func TestValidateProjectRoots(t *testing.T) {
545592 })
546593 }
547594}
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