Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit f840590

Browse files
tro3sdboyer
tro3
authored andcommitted
Move to subtests and add filepath.Joins
1 parent 841b32d commit f840590

File tree

2 files changed

+91
-90
lines changed

2 files changed

+91
-90
lines changed

cmd/dep/ensure_test.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package main
66

77
import (
8+
"path/filepath"
89
"testing"
910

1011
"github.com/golang/dep/test"
@@ -93,54 +94,53 @@ func TestEnsureCases(t *testing.T) {
9394
},
9495
}
9596

96-
runTest := func(t *testing.T, testCase ensureTestCase) {
97-
test.NeedsExternalNetwork(t)
98-
test.NeedsGit(t)
97+
test.NeedsExternalNetwork(t)
98+
test.NeedsGit(t)
9999

100-
h := test.NewHelper(t)
101-
defer h.Cleanup()
100+
for _, testCase := range tests {
101+
t.Run(testCase.dataRoot, func(t *testing.T) {
102+
h := test.NewHelper(t)
103+
defer h.Cleanup()
102104

103-
h.TempDir("src")
104-
h.Setenv("GOPATH", h.Path("."))
105+
h.TempDir("src")
106+
h.Setenv("GOPATH", h.Path("."))
105107

106-
// Build a fake consumer of these packages.
107-
root := "src/thing"
108-
for src, dest := range testCase.sourceFiles {
109-
h.TempCopy(root+"/"+dest, testCase.dataRoot+"/"+src)
110-
}
111-
h.Cd(h.Path(root))
108+
// Build a fake consumer of these packages.
109+
root := "src/thing"
110+
for src, dest := range testCase.sourceFiles {
111+
h.TempCopy(filepath.Join(root, dest), filepath.Join(testCase.dataRoot, src))
112+
}
113+
h.Cd(h.Path(root))
112114

113-
for _, cmd := range testCase.commands {
114-
h.Run(cmd...)
115-
}
115+
for _, cmd := range testCase.commands {
116+
h.Run(cmd...)
117+
}
116118

117-
wantManifest := h.GetTestFileString(testCase.dataRoot + "/" + testCase.goldenManifest)
118-
gotManifest := h.ReadManifest()
119-
if wantManifest != gotManifest {
120-
if *test.UpdateGolden {
121-
if err := h.WriteTestFile(testCase.dataRoot+"/"+testCase.goldenManifest, gotManifest); err != nil {
122-
t.Fatal(err)
119+
wantPath := filepath.Join(testCase.dataRoot, testCase.goldenManifest)
120+
wantManifest := h.GetTestFileString(wantPath)
121+
gotManifest := h.ReadManifest()
122+
if wantManifest != gotManifest {
123+
if *test.UpdateGolden {
124+
if err := h.WriteTestFile(wantPath, gotManifest); err != nil {
125+
t.Fatal(err)
126+
}
127+
} else {
128+
t.Errorf("expected %s, got %s", wantManifest, gotManifest)
123129
}
124-
} else {
125-
t.Errorf("expected %s, got %s", wantManifest, gotManifest)
126130
}
127-
}
128131

129-
wantLock := h.GetTestFileString(testCase.dataRoot + "/" + testCase.goldenLock)
130-
gotLock := h.ReadLock()
131-
if wantLock != gotLock {
132-
if *test.UpdateGolden {
133-
if err := h.WriteTestFile(testCase.dataRoot+"/"+testCase.goldenLock, gotLock); err != nil {
134-
t.Fatal(err)
132+
wantPath = filepath.Join(testCase.dataRoot, testCase.goldenLock)
133+
wantLock := h.GetTestFileString(wantPath)
134+
gotLock := h.ReadLock()
135+
if wantLock != gotLock {
136+
if *test.UpdateGolden {
137+
if err := h.WriteTestFile(wantPath, gotLock); err != nil {
138+
t.Fatal(err)
139+
}
140+
} else {
141+
t.Errorf("expected %s, got %s", wantLock, gotLock)
135142
}
136-
} else {
137-
t.Errorf("expected %s, got %s", wantLock, gotLock)
138143
}
139-
}
140-
141-
}
142-
143-
for _, testCase := range tests {
144-
runTest(t, testCase)
144+
})
145145
}
146146
}

cmd/dep/init_test.go

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package main
66

77
import (
8+
"path/filepath"
89
"testing"
910

1011
"github.com/golang/dep/test"
@@ -65,7 +66,7 @@ func TestInit(t *testing.T) {
6566
goldenLock: "lock.golden.json",
6667
},
6768

68-
// One dependency previously retrieved by version. Both will show up in lock, but only retrieved one in manifest.
69+
// One dependency previously retrieved by version. Both will show up in lock, but only retrieved one in manifest?
6970
{
7071
dataRoot: "init/case2",
7172
importPaths: map[string]string{
@@ -79,7 +80,7 @@ func TestInit(t *testing.T) {
7980
goldenLock: "lock.golden.json",
8081
},
8182

82-
// One dependency previously retrieved by sha. Both will show up in lock and manifest?
83+
// One dependency previously retrieved by sha. Both will show up in lock and manifest
8384
{
8485
dataRoot: "init/case3",
8586
importPaths: map[string]string{
@@ -94,63 +95,63 @@ func TestInit(t *testing.T) {
9495
},
9596
}
9697

97-
runTest := func(t *testing.T, testCase initTestCase) {
98-
test.NeedsExternalNetwork(t)
99-
test.NeedsGit(t)
98+
test.NeedsExternalNetwork(t)
99+
test.NeedsGit(t)
100100

101-
h := test.NewHelper(t)
102-
defer h.Cleanup()
103-
104-
h.TempDir("src")
105-
h.Setenv("GOPATH", h.Path("."))
106-
107-
// checkout the specified revisions
108-
for ip, rev := range testCase.importPaths {
109-
h.RunGo("get", ip)
110-
repoDir := h.Path("src/" + ip)
111-
h.RunGit(repoDir, "checkout", rev)
112-
}
113-
114-
// Build a fake consumer of these packages.
115-
root := "src/github.com/golang/notexist"
116-
for src, dest := range testCase.sourceFiles {
117-
h.TempCopy(root+"/"+dest, testCase.dataRoot+"/"+src)
118-
}
101+
for _, testCase := range tests {
102+
t.Run(testCase.dataRoot, func(t *testing.T) {
103+
h := test.NewHelper(t)
104+
defer h.Cleanup()
105+
106+
h.TempDir("src")
107+
h.Setenv("GOPATH", h.Path("."))
108+
109+
// checkout the specified revisions
110+
for ip, rev := range testCase.importPaths {
111+
h.RunGo("get", ip)
112+
repoDir := h.Path(filepath.Join("src", ip))
113+
h.RunGit(repoDir, "checkout", rev)
114+
}
119115

120-
h.Cd(h.Path(root))
121-
h.Run("init")
116+
// Build a fake consumer of these packages.
117+
root := "src/github.com/golang/notexist"
118+
for src, dest := range testCase.sourceFiles {
119+
h.TempCopy(filepath.Join(root, dest), filepath.Join(testCase.dataRoot, src))
120+
}
122121

123-
wantManifest := h.GetTestFileString(testCase.dataRoot + "/" + testCase.goldenManifest)
124-
gotManifest := h.ReadManifest()
125-
if wantManifest != gotManifest {
126-
if *test.UpdateGolden {
127-
if err := h.WriteTestFile(testCase.dataRoot+"/"+testCase.goldenManifest, gotManifest); err != nil {
128-
t.Fatal(err)
122+
h.Cd(h.Path(root))
123+
h.Run("init")
124+
125+
wantPath := filepath.Join(testCase.dataRoot, testCase.goldenManifest)
126+
wantManifest := h.GetTestFileString(wantPath)
127+
gotManifest := h.ReadManifest()
128+
if wantManifest != gotManifest {
129+
if *test.UpdateGolden {
130+
if err := h.WriteTestFile(wantPath, gotManifest); err != nil {
131+
t.Fatal(err)
132+
}
133+
} else {
134+
t.Errorf("expected %s, got %s", wantManifest, gotManifest)
129135
}
130-
} else {
131-
t.Errorf("expected %s, got %s", wantManifest, gotManifest)
132136
}
133-
}
134137

135-
wantLock := h.GetTestFileString(testCase.dataRoot + "/" + testCase.goldenLock)
136-
gotLock := h.ReadLock()
137-
if wantLock != gotLock {
138-
if *test.UpdateGolden {
139-
if err := h.WriteTestFile(testCase.dataRoot+"/"+testCase.goldenLock, gotLock); err != nil {
140-
t.Fatal(err)
138+
wantPath = filepath.Join(testCase.dataRoot, testCase.goldenLock)
139+
wantLock := h.GetTestFileString(wantPath)
140+
gotLock := h.ReadLock()
141+
if wantLock != gotLock {
142+
if *test.UpdateGolden {
143+
if err := h.WriteTestFile(wantPath, gotLock); err != nil {
144+
t.Fatal(err)
145+
}
146+
} else {
147+
t.Errorf("expected %s, got %s", wantLock, gotLock)
141148
}
142-
} else {
143-
t.Errorf("expected %s, got %s", wantLock, gotLock)
144149
}
145-
}
146150

147-
// vendor should have been created & populated
148-
for ip := range testCase.importPaths {
149-
h.MustExist(h.Path(root + "/vendor/" + ip))
150-
}
151-
}
152-
153-
for _, testCase := range tests {
154-
runTest(t, testCase)
151+
// vendor should have been created & populated
152+
for ip := range testCase.importPaths {
153+
h.MustExist(h.Path(filepath.Join(root, "vendor", ip)))
154+
}
155+
})
155156
}
156157
}

0 commit comments

Comments
 (0)