55package gps
66
77import (
8+ "bytes"
89 "context"
910 "fmt"
1011 "io/ioutil"
@@ -13,9 +14,11 @@ import (
1314 "path"
1415 "path/filepath"
1516 "runtime"
17+ "sort"
1618 "sync"
1719 "sync/atomic"
1820 "testing"
21+ "text/tabwriter"
1922 "time"
2023
2124 "github.com/golang/dep/internal/test"
@@ -349,8 +352,8 @@ func TestMgrMethodsFailWithBadPath(t *testing.T) {
349352}
350353
351354type sourceCreationTestFixture struct {
352- roots []ProjectIdentifier
353- urlcount , srccount int
355+ roots []ProjectIdentifier
356+ namecount , srccount int
354357}
355358
356359func (f sourceCreationTestFixture ) run (t * testing.T ) {
@@ -365,13 +368,33 @@ func (f sourceCreationTestFixture) run(t *testing.T) {
365368 }
366369 }
367370
368- if len (sm .srcCoord .nameToURL ) != f .urlcount {
369- t .Errorf ("want %v names in the name->url map, but got %v. contents: \n %v" , f .urlcount , len (sm .srcCoord .nameToURL ), sm .srcCoord .nameToURL )
371+ if len (sm .srcCoord .nameToURL ) != f .namecount {
372+ t .Errorf ("want %v names in the name->url map, but got %v. contents: \n %v" , f .namecount , len (sm .srcCoord .nameToURL ), sm .srcCoord .nameToURL )
370373 }
371374
372375 if len (sm .srcCoord .srcs ) != f .srccount {
373376 t .Errorf ("want %v gateways in the sources map, but got %v" , f .srccount , len (sm .srcCoord .srcs ))
374377 }
378+
379+ var keys []string
380+ for k := range sm .srcCoord .nameToURL {
381+ keys = append (keys , k )
382+ }
383+ sort .Strings (keys )
384+
385+ var buf bytes.Buffer
386+ w := tabwriter .NewWriter (& buf , 0 , 4 , 2 , ' ' , 0 )
387+ fmt .Fprint (w , "NAME\t MAPPED URL\n " )
388+ for _ , r := range keys {
389+ fmt .Fprintf (w , "%s\t %s\n " , r , sm .srcCoord .nameToURL [r ])
390+ }
391+ w .Flush ()
392+ t .Log ("\n " , buf .String ())
393+
394+ t .Log ("SRC KEYS" )
395+ for k := range sm .srcCoord .srcs {
396+ t .Log (k )
397+ }
375398}
376399
377400// This test is primarily about making sure that the logic around folding
@@ -390,16 +413,27 @@ func TestSourceCreationCounts(t *testing.T) {
390413 mkPI ("gopkg.in/sdboyer/gpkt.v2" ),
391414 mkPI ("gopkg.in/sdboyer/gpkt.v3" ),
392415 },
393- urlcount : 6 ,
394- srccount : 3 ,
416+ namecount : 6 ,
417+ srccount : 3 ,
395418 },
396419 "gopkgin separation from github" : {
397420 roots : []ProjectIdentifier {
398421 mkPI ("gopkg.in/sdboyer/gpkt.v1" ),
399422 mkPI ("github.com/sdboyer/gpkt" ),
400423 },
401- urlcount : 4 ,
402- srccount : 2 ,
424+ namecount : 4 ,
425+ srccount : 2 ,
426+ },
427+ "case variance across path and URL-based access" : {
428+ roots : []ProjectIdentifier {
429+ ProjectIdentifier {ProjectRoot : ProjectRoot ("github.com/sdboyer/gpkt" ), Source : "https://github.com/Sdboyer/gpkt" },
430+ ProjectIdentifier {ProjectRoot : ProjectRoot ("github.com/sdboyer/gpkt" ), Source : "https://github.com/SdbOyer/gpkt" },
431+ mkPI ("github.com/sdboyer/gpkt" ),
432+ ProjectIdentifier {ProjectRoot : ProjectRoot ("github.com/sdboyer/gpkt" ), Source : "https://github.com/sdboyeR/gpkt" },
433+ mkPI ("github.com/sdboyeR/gpkt" ),
434+ },
435+ namecount : 6 ,
436+ srccount : 1 ,
403437 },
404438 }
405439
@@ -467,13 +501,70 @@ func TestGetSources(t *testing.T) {
467501 })
468502
469503 // nine entries (of which three are dupes): for each vcs, raw import path,
470- // the https url, and the http url
471- if len (sm .srcCoord .nameToURL ) != 9 {
472- t .Errorf ("Should have nine discrete entries in the nameToURL map, got %v" , len (sm .srcCoord .nameToURL ))
504+ // the https url, and the http url. also three more from case folding of
505+ // github.com/Masterminds/VCSTestRepo -> github.com/masterminds/vcstestrepo
506+ if len (sm .srcCoord .nameToURL ) != 12 {
507+ t .Errorf ("Should have twelve discrete entries in the nameToURL map, got %v" , len (sm .srcCoord .nameToURL ))
473508 }
474509 clean ()
475510}
476511
512+ func TestFSCaseSensitivityConvergesSources (t * testing.T ) {
513+ if testing .Short () {
514+ t .Skip ("Skipping slow test in short mode" )
515+ }
516+
517+ f := func (name string , pi1 , pi2 ProjectIdentifier ) {
518+ t .Run (name , func (t * testing.T ) {
519+ t .Parallel ()
520+ sm , clean := mkNaiveSM (t )
521+ defer clean ()
522+
523+ sm .SyncSourceFor (pi1 )
524+ sg1 , err := sm .srcCoord .getSourceGatewayFor (context .Background (), pi1 )
525+ if err != nil {
526+ t .Fatal (err )
527+ }
528+
529+ sm .SyncSourceFor (pi2 )
530+ sg2 , err := sm .srcCoord .getSourceGatewayFor (context .Background (), pi2 )
531+ if err != nil {
532+ t .Fatal (err )
533+ }
534+
535+ path1 := sg1 .src .(* gitSource ).repo .LocalPath ()
536+ t .Log ("path1:" , path1 )
537+ stat1 , err := os .Stat (path1 )
538+ if err != nil {
539+ t .Fatal (err )
540+ }
541+ path2 := sg2 .src .(* gitSource ).repo .LocalPath ()
542+ t .Log ("path2:" , path2 )
543+ stat2 , err := os .Stat (path2 )
544+ if err != nil {
545+ t .Fatal (err )
546+ }
547+
548+ same , count := os .SameFile (stat1 , stat2 ), len (sm .srcCoord .srcs )
549+ if same && count != 1 {
550+ t .Log ("are same, count" , count )
551+ t .Fatal ("on case-insensitive filesystem, case-varying sources should have been folded together but were not" )
552+ }
553+ if ! same && count != 2 {
554+ t .Log ("not same, count" , count )
555+ t .Fatal ("on case-sensitive filesystem, case-varying sources should not have been folded together, but were" )
556+ }
557+ })
558+ }
559+
560+ folded := mkPI ("github.com/sdboyer/deptest" ).normalize ()
561+ casevar1 := mkPI ("github.com/Sdboyer/deptest" ).normalize ()
562+ casevar2 := mkPI ("github.com/SdboyeR/deptest" ).normalize ()
563+ f ("folded first" , folded , casevar1 )
564+ f ("folded second" , casevar1 , folded )
565+ f ("both unfolded" , casevar1 , casevar2 )
566+ }
567+
477568// Regression test for #32
478569func TestGetInfoListVersionsOrdering (t * testing.T ) {
479570 // This test is quite slow, skip it on -short
0 commit comments