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

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ibrahim AshShohail <[email protected]>
  • Loading branch information
ibrasho committed Aug 9, 2017
1 parent 0f88088 commit 08af070
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,23 +314,16 @@ func TestDetectProjectGOPATH(t *testing.T) {
h := test.NewHelper(t)
defer h.Cleanup()

h.TempDir("go")
h.TempDir("go-two")
h.TempDir(filepath.Join("sym", "symlink"))
h.TempDir(filepath.Join("go", "src", "sym", "path"))
h.TempDir(filepath.Join("go", "src", "real", "path"))
h.TempDir(filepath.Join("go-two", "src", "real", "path"))
h.TempDir(filepath.Join("go-two", "src", "sym"))

ctx := &Ctx{
GOPATHs: []string{h.Path("go"), h.Path("go-two")},
}

h.TempDir("go/src/real/path")

// Another directory used as a GOPATH
h.TempDir("go-two/src/sym")

h.TempDir(filepath.Join(".", "sym/symlink")) // Directory for symlinks
h.TempDir(filepath.Join("go", "src", "sym", "path"))
h.TempDir(filepath.Join("go", "src", " real", "path"))
h.TempDir(filepath.Join("go-two", "src", "real", "path"))

testcases := []struct {
name string
root string
Expand Down Expand Up @@ -383,7 +376,7 @@ func TestDetectProjectGOPATH(t *testing.T) {
{
name: "AbsRoot-is-a-symlink-to-ResolvedAbsRoot",
root: filepath.Join(h.Path("."), "sym", "symlink"),
resolvedRoot: filepath.Join(ctx.GOPATHs[0], "src", " real", "path"),
resolvedRoot: filepath.Join(ctx.GOPATHs[0], "src", "real", "path"),
GOPATH: ctx.GOPATHs[0],
},
}
Expand Down Expand Up @@ -412,36 +405,33 @@ func TestDetectGOPATH(t *testing.T) {
th := test.NewHelper(t)
defer th.Cleanup()

th.TempDir("go")
th.TempDir("gotwo")
th.TempDir(filepath.Join("code", "src", "github.com", "username", "package"))
th.TempDir(filepath.Join("go", "src", "github.com", "username", "package"))
th.TempDir(filepath.Join("gotwo", "src", "github.com", "username", "package"))

ctx := &Ctx{GOPATHs: []string{
th.Path("go"),
th.Path("gotwo"),
}}

th.TempDir(filepath.Join("code", "src", "github.com", "username", "package"))
th.TempDir(filepath.Join("go", "src", "github.com", "username", "package"))
th.TempDir(filepath.Join("gotwo", "src", "github.com", "username", "package"))

testcases := []struct {
GOPATH string
path string
err bool
}{
{th.Path("go"), filepath.Join(th.Path("go"), "src/github.com/username/package"), false},
{th.Path("go"), filepath.Join(th.Path("go"), "src/github.com/username/package"), false},
{th.Path("gotwo"), filepath.Join(th.Path("gotwo"), "src/github.com/username/package"), false},
{"", filepath.Join(th.Path("."), "code/src/github.com/username/package"), true},
{th.Path("go"), th.Path(filepath.Join("go", "src", "github.com", "username", "package")), false},
{th.Path("go"), th.Path(filepath.Join("go", "src", "github.com", "username", "package")), false},
{th.Path("gotwo"), th.Path(filepath.Join("gotwo", "src", "github.com", "username", "package")), false},
{"", th.Path(filepath.Join("code", "src", "github.com", "username", "package")), true},
}

for _, tc := range testcases {
GOPATH, err := ctx.detectGOPATH(tc.path)
if tc.err && err == nil {
t.Error("Expected error but got none")
t.Error("expected error but got none")
}
if GOPATH != tc.GOPATH {
t.Errorf("Expected GOPATH to be %s, got %s", GOPATH, tc.GOPATH)
t.Errorf("expected GOPATH to be %s, got %s", GOPATH, tc.GOPATH)
}
}
}

0 comments on commit 08af070

Please sign in to comment.