Skip to content

Commit d601baa

Browse files
dmitshuralexbrainman
authored andcommitted
go/vcs: apply test style improvements from cmd/go
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]>
1 parent 2da0720 commit d601baa

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

go/vcs/vcs_test.go

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package vcs
77
import (
88
"io/ioutil"
99
"os"
10-
pathpkg "path"
10+
"path"
1111
"path/filepath"
1212
"reflect"
1313
"runtime"
@@ -50,45 +50,32 @@ func TestRepoRootForImportPath(t *testing.T) {
5050

5151
// Test that FromDir correctly inspects a given directory and returns the right VCS and root.
5252
func TestFromDir(t *testing.T) {
53-
type testStruct struct {
54-
path string
55-
want *RepoRoot
56-
}
57-
58-
tests := make([]testStruct, len(vcsList))
5953
tempDir, err := ioutil.TempDir("", "vcstest")
6054
if err != nil {
6155
t.Fatal(err)
6256
}
6357
defer os.RemoveAll(tempDir)
6458

65-
for i, vcs := range vcsList {
66-
tests[i] = testStruct{
67-
path: filepath.Join(tempDir, "example.com", vcs.Name, "."+vcs.Cmd),
68-
want: &RepoRoot{
69-
VCS: vcs,
70-
Root: pathpkg.Join("example.com", vcs.Name),
71-
},
59+
for _, vcs := range vcsList {
60+
dir := filepath.Join(tempDir, "example.com", vcs.Name, "."+vcs.Cmd)
61+
err := os.MkdirAll(dir, 0755)
62+
if err != nil {
63+
t.Fatal(err)
7264
}
73-
}
7465

75-
for _, test := range tests {
76-
os.MkdirAll(test.path, 0755)
77-
var (
78-
got = new(RepoRoot)
79-
err error
80-
)
81-
got.VCS, got.Root, err = FromDir(test.path, tempDir)
66+
want := RepoRoot{
67+
VCS: vcs,
68+
Root: path.Join("example.com", vcs.Name),
69+
}
70+
var got RepoRoot
71+
got.VCS, got.Root, err = FromDir(dir, tempDir)
8272
if err != nil {
83-
t.Errorf("FromDir(%q, %q): %v", test.path, tempDir, err)
84-
os.RemoveAll(test.path)
73+
t.Errorf("FromDir(%q, %q): %v", dir, tempDir, err)
8574
continue
8675
}
87-
want := test.want
8876
if got.VCS.Name != want.VCS.Name || got.Root != want.Root {
89-
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)
77+
t.Errorf("FromDir(%q, %q) = VCS(%s) Root(%s), want VCS(%s) Root(%s)", dir, tempDir, got.VCS, got.Root, want.VCS, want.Root)
9078
}
91-
os.RemoveAll(test.path)
9279
}
9380
}
9481

0 commit comments

Comments
 (0)