Skip to content

Commit

Permalink
Simplify temp dir creation in tests
Browse files Browse the repository at this point in the history
If the tempdir is evaluated on creation, there is no need for special
handling of "darwin" (OSX) in NewTestProject()
  • Loading branch information
tkrajina committed Jul 22, 2017
1 parent 911cd22 commit a09c316
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions internal/test/integration_testproj.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -50,16 +49,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 +273,10 @@ func (p *IntegrationTestProject) makeRootTempDir() {
var err error
p.tempdir, err = ioutil.TempDir("", "gotest")
p.Must(err)

// Fox for OSX where the tempdir is a symlink:
p.tempdir, err = filepath.EvalSymlinks(p.tempdir)
p.Must(err)
}
}

Expand All @@ -298,15 +292,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 a09c316

Please sign in to comment.