@@ -354,25 +354,36 @@ func TestResolveProjectRoot(t *testing.T) {
354
354
355
355
tg .TempDir ("go" )
356
356
tg .TempDir ("go/src" )
357
- tg .TempDir ("sym" )
358
357
tg .TempDir ("go/src/real" )
359
358
tg .TempDir ("go/src/real/path" )
360
359
tg .TempDir ("go/src/sym" )
361
360
361
+ tg .TempDir ("gotwo" ) // Another directory used as a GOPATH
362
+ tg .TempDir ("gotwo/src" )
363
+ tg .TempDir ("gotwo/src/real" )
364
+ tg .TempDir ("gotwo/src/real/path" )
365
+ tg .TempDir ("gotwo/src/sym" )
366
+
367
+ tg .TempDir ("sym" ) // Directory for symlinks
368
+
362
369
tg .Setenv ("GOPATH" , tg .Path (filepath .Join ("." , "go" )))
363
370
364
371
ctx := & Ctx {
365
372
GOPATH : tg .Path (filepath .Join ("." , "go" )),
366
373
GOPATHS : []string {
367
374
tg .Path (filepath .Join ("." , "go" )),
375
+ tg .Path (filepath .Join ("." , "gotwo" )),
368
376
},
369
377
}
370
378
371
- realPath := filepath .Join (ctx .GOPATH , "src/real/path" )
379
+ realPath := filepath .Join (ctx .GOPATH , "src" , "real" , "path" )
380
+ realPathTwo := filepath .Join (ctx .GOPATHS [1 ], "src" , "real" , "path" )
372
381
symlinkedPath := filepath .Join (tg .Path ("." ), "sym" , "symlink" )
373
382
symlinkedInGoPath := filepath .Join (ctx .GOPATH , "src/sym/path" )
383
+ symlinkedInOtherGoPath := filepath .Join (tg .Path ("." ), "sym" , "symtwo" )
374
384
os .Symlink (realPath , symlinkedPath )
375
385
os .Symlink (realPath , symlinkedInGoPath )
386
+ os .Symlink (realPathTwo , symlinkedInOtherGoPath )
376
387
377
388
// Real path should be returned, no symlinks to deal with
378
389
p , err := ctx .resolveProjectRoot (realPath )
@@ -392,6 +403,15 @@ func TestResolveProjectRoot(t *testing.T) {
392
403
t .Fatalf ("Want path to be %s, got %s" , realPath , p )
393
404
}
394
405
406
+ // Real path should be returned, symlink is in another GOPATH
407
+ p , err = ctx .resolveProjectRoot (symlinkedInOtherGoPath )
408
+ if err != nil {
409
+ t .Fatalf ("Error resolving project root: %s" , err )
410
+ }
411
+ if p != realPathTwo {
412
+ t .Fatalf ("Want path to be %s, got %s" , realPathTwo , p )
413
+ }
414
+
395
415
// Symlinked path is inside GOPATH, should return error
396
416
_ , err = ctx .resolveProjectRoot (symlinkedInGoPath )
397
417
if err == nil {
0 commit comments