Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 753c8dd

Browse files
committed
Add test case for multiple GOPATH situation
1 parent c2deecc commit 753c8dd

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

context_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,25 +354,36 @@ func TestResolveProjectRoot(t *testing.T) {
354354

355355
tg.TempDir("go")
356356
tg.TempDir("go/src")
357-
tg.TempDir("sym")
358357
tg.TempDir("go/src/real")
359358
tg.TempDir("go/src/real/path")
360359
tg.TempDir("go/src/sym")
361360

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+
362369
tg.Setenv("GOPATH", tg.Path(filepath.Join(".", "go")))
363370

364371
ctx := &Ctx{
365372
GOPATH: tg.Path(filepath.Join(".", "go")),
366373
GOPATHS: []string{
367374
tg.Path(filepath.Join(".", "go")),
375+
tg.Path(filepath.Join(".", "gotwo")),
368376
},
369377
}
370378

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")
372381
symlinkedPath := filepath.Join(tg.Path("."), "sym", "symlink")
373382
symlinkedInGoPath := filepath.Join(ctx.GOPATH, "src/sym/path")
383+
symlinkedInOtherGoPath := filepath.Join(tg.Path("."), "sym", "symtwo")
374384
os.Symlink(realPath, symlinkedPath)
375385
os.Symlink(realPath, symlinkedInGoPath)
386+
os.Symlink(realPathTwo, symlinkedInOtherGoPath)
376387

377388
// Real path should be returned, no symlinks to deal with
378389
p, err := ctx.resolveProjectRoot(realPath)
@@ -392,6 +403,15 @@ func TestResolveProjectRoot(t *testing.T) {
392403
t.Fatalf("Want path to be %s, got %s", realPath, p)
393404
}
394405

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+
395415
// Symlinked path is inside GOPATH, should return error
396416
_, err = ctx.resolveProjectRoot(symlinkedInGoPath)
397417
if err == nil {

0 commit comments

Comments
 (0)