Skip to content

Commit

Permalink
go/vcs: apply test style improvements from cmd/go
Browse files Browse the repository at this point in the history
Apply style improvements to TestFromDir from golang/go@b6cd6d7d3211bd90,
in order to keep them in sync.

Check for error when creating a directory, its successful existence is a
precondition for the test to run.

Helps golang/go#11490.

Change-Id: I87054114c84aead96977f603ca3bd9eccfcfbd5e
Reviewed-on: https://go-review.googlesource.com/21795
Reviewed-by: Alex Brainman <[email protected]>
  • Loading branch information
dmitshur authored and alexbrainman committed Apr 12, 2016
1 parent 2da0720 commit d601baa
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions go/vcs/vcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package vcs
import (
"io/ioutil"
"os"
pathpkg "path"
"path"
"path/filepath"
"reflect"
"runtime"
Expand Down Expand Up @@ -50,45 +50,32 @@ func TestRepoRootForImportPath(t *testing.T) {

// Test that FromDir correctly inspects a given directory and returns the right VCS and root.
func TestFromDir(t *testing.T) {
type testStruct struct {
path string
want *RepoRoot
}

tests := make([]testStruct, len(vcsList))
tempDir, err := ioutil.TempDir("", "vcstest")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tempDir)

for i, vcs := range vcsList {
tests[i] = testStruct{
path: filepath.Join(tempDir, "example.com", vcs.Name, "."+vcs.Cmd),
want: &RepoRoot{
VCS: vcs,
Root: pathpkg.Join("example.com", vcs.Name),
},
for _, vcs := range vcsList {
dir := filepath.Join(tempDir, "example.com", vcs.Name, "."+vcs.Cmd)
err := os.MkdirAll(dir, 0755)
if err != nil {
t.Fatal(err)
}
}

for _, test := range tests {
os.MkdirAll(test.path, 0755)
var (
got = new(RepoRoot)
err error
)
got.VCS, got.Root, err = FromDir(test.path, tempDir)
want := RepoRoot{
VCS: vcs,
Root: path.Join("example.com", vcs.Name),
}
var got RepoRoot
got.VCS, got.Root, err = FromDir(dir, tempDir)
if err != nil {
t.Errorf("FromDir(%q, %q): %v", test.path, tempDir, err)
os.RemoveAll(test.path)
t.Errorf("FromDir(%q, %q): %v", dir, tempDir, err)
continue
}
want := test.want
if got.VCS.Name != want.VCS.Name || got.Root != want.Root {
t.Errorf("FromDir(%q, %q) = VCS(%s) Root(%s), want VCS(%s) Root(%s)", test.path, tempDir, got.VCS, got.Root, want.VCS, want.Root)
t.Errorf("FromDir(%q, %q) = VCS(%s) Root(%s), want VCS(%s) Root(%s)", dir, tempDir, got.VCS, got.Root, want.VCS, want.Root)
}
os.RemoveAll(test.path)
}
}

Expand Down

0 comments on commit d601baa

Please sign in to comment.