5
5
package gps
6
6
7
7
import (
8
+ "bytes"
8
9
"context"
9
10
"fmt"
10
11
"io/ioutil"
@@ -13,9 +14,11 @@ import (
13
14
"path"
14
15
"path/filepath"
15
16
"runtime"
17
+ "sort"
16
18
"sync"
17
19
"sync/atomic"
18
20
"testing"
21
+ "text/tabwriter"
19
22
"time"
20
23
21
24
"github.com/golang/dep/internal/test"
@@ -349,8 +352,8 @@ func TestMgrMethodsFailWithBadPath(t *testing.T) {
349
352
}
350
353
351
354
type sourceCreationTestFixture struct {
352
- roots []ProjectIdentifier
353
- urlcount , srccount int
355
+ roots []ProjectIdentifier
356
+ namecount , srccount int
354
357
}
355
358
356
359
func (f sourceCreationTestFixture ) run (t * testing.T ) {
@@ -365,13 +368,33 @@ func (f sourceCreationTestFixture) run(t *testing.T) {
365
368
}
366
369
}
367
370
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 )
370
373
}
371
374
372
375
if len (sm .srcCoord .srcs ) != f .srccount {
373
376
t .Errorf ("want %v gateways in the sources map, but got %v" , f .srccount , len (sm .srcCoord .srcs ))
374
377
}
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
+ }
375
398
}
376
399
377
400
// This test is primarily about making sure that the logic around folding
@@ -390,16 +413,27 @@ func TestSourceCreationCounts(t *testing.T) {
390
413
mkPI ("gopkg.in/sdboyer/gpkt.v2" ),
391
414
mkPI ("gopkg.in/sdboyer/gpkt.v3" ),
392
415
},
393
- urlcount : 6 ,
394
- srccount : 3 ,
416
+ namecount : 6 ,
417
+ srccount : 3 ,
395
418
},
396
419
"gopkgin separation from github" : {
397
420
roots : []ProjectIdentifier {
398
421
mkPI ("gopkg.in/sdboyer/gpkt.v1" ),
399
422
mkPI ("github.com/sdboyer/gpkt" ),
400
423
},
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 ,
403
437
},
404
438
}
405
439
@@ -467,13 +501,70 @@ func TestGetSources(t *testing.T) {
467
501
})
468
502
469
503
// 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 ))
473
508
}
474
509
clean ()
475
510
}
476
511
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
+
477
568
// Regression test for #32
478
569
func TestGetInfoListVersionsOrdering (t * testing.T ) {
479
570
// This test is quite slow, skip it on -short
0 commit comments