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

Commit

Permalink
Merge pull request #882 from tkrajina/simplify-tests
Browse files Browse the repository at this point in the history
Simplify temp dir creation in tests
  • Loading branch information
sdboyer authored Jul 26, 2017
2 parents 6b5e8cf + 39cdb41 commit 7d36525
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions internal/test/integration_testproj.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,7 @@ func NewTestProject(t *testing.T, initPath, wd string, externalProc bool, run Ru
new.TempDir(ProjectRoot, "vendor")
new.CopyTree(initPath)

// Note that the Travis darwin platform, directories with certain roots such
// as /var are actually links to a dirtree under /private. Without the patch
// below the wd, and therefore the GOPATH, is recorded as "/var/..." but the
// actual process runs in "/private/var/..." and dies due to not being in the
// GOPATH because the roots don't line up.
if externalProc && runtime.GOOS == "darwin" && needsPrivateLeader(new.tempdir) {
new.Setenv("GOPATH", filepath.Join("/private", new.tempdir))
} else {
new.Setenv("GOPATH", new.tempdir)
}
new.Setenv("GOPATH", new.tempdir)

return new
}
Expand Down Expand Up @@ -283,6 +274,12 @@ func (p *IntegrationTestProject) makeRootTempDir() {
var err error
p.tempdir, err = ioutil.TempDir("", "gotest")
p.Must(err)

// Fix for OSX where the tempdir is a symlink:
if runtime.GOOS == "darwin" {
p.tempdir, err = filepath.EvalSymlinks(p.tempdir)
p.Must(err)
}
}
}

Expand All @@ -298,15 +295,3 @@ func (p *IntegrationTestProject) Must(err error) {
p.t.Fatalf("%+v", err)
}
}

// Checks for filepath beginnings that result in the "/private" leader
// on Mac platforms
func needsPrivateLeader(path string) bool {
var roots = []string{"/var", "/tmp", "/etc"}
for _, root := range roots {
if strings.HasPrefix(path, root) {
return true
}
}
return false
}

0 comments on commit 7d36525

Please sign in to comment.