Skip to content

Commit

Permalink
dep init refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niranjan92 committed May 20, 2017
1 parent 358d80c commit d8abdbf
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 52 deletions.
7 changes: 3 additions & 4 deletions cmd/dep/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func testIntegration(name, wd string, externalProc bool, run test.RunFunc) func(
t.Parallel()

// Set up environment
testCase := test.NewTestCase(t, name, wd)
testCase := test.NewTestCase(t, name, "harness_tests", wd)
defer testCase.Cleanup()
testProj := test.NewTestProject(t, testCase.InitialPath(), wd, externalProc, run)
defer testProj.Cleanup()
Expand Down Expand Up @@ -158,9 +158,9 @@ func testRelativePath(name, wd string, externalProc bool, run test.RunFunc) func
t.Parallel()

// Set up environment
testCase := test.NewTestCaseRelPath(t, name, wd)
testCase := test.NewTestCase(t, name, "init_path_tests", wd)
defer testCase.Cleanup()
testProj := test.NewTestProjectRelPath(t, testCase.InitialPath(), testCase.InitPath, wd, externalProc, run)
testProj := test.NewTestProject(t, testCase.InitialPath(), wd, externalProc, run)
defer testProj.Cleanup()

// Create and checkout the vendor revisions
Expand Down Expand Up @@ -196,7 +196,6 @@ func testRelativePath(name, wd string, externalProc bool, run test.RunFunc) func
testCase.CompareFile(dep.ManifestName, testProj.ProjPath(dep.ManifestName))
testCase.CompareFile(dep.LockName, testProj.ProjPath(dep.LockName))

// Check vendor paths
testProj.CompareImportPaths()
}
}
2 changes: 1 addition & 1 deletion cmd/dep/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestRemoveErrors(t *testing.T) {

func removeErrors(name, wd string, externalProc bool, run test.RunFunc) func(*testing.T) {
return func(t *testing.T) {
testCase := test.NewTestCase(t, name, wd)
testCase := test.NewTestCase(t, name, "harness_tests", wd)
testProj := test.NewTestProject(t, testCase.InitialPath(), wd, externalProc, run)
defer testProj.Cleanup()

Expand Down
24 changes: 2 additions & 22 deletions internal/test/integration_testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,8 @@ type IntegrationTestCase struct {
InitPath string `json:"init-path"`
}

func NewTestCase(t *testing.T, name, wd string) *IntegrationTestCase {
rootPath := filepath.FromSlash(filepath.Join(wd, "testdata", "harness_tests", name))
n := &IntegrationTestCase{
t: t,
name: name,
rootPath: rootPath,
initialPath: filepath.Join(rootPath, "initial"),
finalPath: filepath.Join(rootPath, "final"),
}
j, err := ioutil.ReadFile(filepath.Join(rootPath, "testcase.json"))
if err != nil {
panic(err)
}
err = json.Unmarshal(j, n)
if err != nil {
panic(err)
}
return n
}

func NewTestCaseRelPath(t *testing.T, name, wd string) *IntegrationTestCase {
rootPath := filepath.FromSlash(filepath.Join(wd, "testdata", "init_path_tests", name))
func NewTestCase(t *testing.T, name, test_dir, wd string) *IntegrationTestCase {
rootPath := filepath.FromSlash(filepath.Join(wd, "testdata", test_dir, name))
n := &IntegrationTestCase{
t: t,
name: name,
Expand Down
25 changes: 0 additions & 25 deletions internal/test/integration_testproj.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,6 @@ func NewTestProject(t *testing.T, initPath, wd string, externalProc bool, run Ru
return new
}

func NewTestProjectRelPath(t *testing.T, initPath, wd, relativePath string, externalProc bool, run RunFunc) *IntegrationTestProject {
new := &IntegrationTestProject{
t: t,
origWd: wd,
env: os.Environ(),
run: run,
}
new.makeRootTempDir()
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)
}

return new
}

func (p *IntegrationTestProject) Cleanup() {
os.RemoveAll(p.tempdir)
}
Expand Down

0 comments on commit d8abdbf

Please sign in to comment.