@@ -7,7 +7,7 @@ package vcs
7
7
import (
8
8
"io/ioutil"
9
9
"os"
10
- pathpkg "path"
10
+ "path"
11
11
"path/filepath"
12
12
"reflect"
13
13
"runtime"
@@ -50,45 +50,32 @@ func TestRepoRootForImportPath(t *testing.T) {
50
50
51
51
// Test that FromDir correctly inspects a given directory and returns the right VCS and root.
52
52
func TestFromDir (t * testing.T ) {
53
- type testStruct struct {
54
- path string
55
- want * RepoRoot
56
- }
57
-
58
- tests := make ([]testStruct , len (vcsList ))
59
53
tempDir , err := ioutil .TempDir ("" , "vcstest" )
60
54
if err != nil {
61
55
t .Fatal (err )
62
56
}
63
57
defer os .RemoveAll (tempDir )
64
58
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 )
72
64
}
73
- }
74
65
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 )
82
72
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 )
85
74
continue
86
75
}
87
- want := test .want
88
76
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 )
90
78
}
91
- os .RemoveAll (test .path )
92
79
}
93
80
}
94
81
0 commit comments