Skip to content

Commit 6c259af

Browse files
committed
Make the vcs_repo tests fail when encountering an error
Calling `t.Error` is not enough when encountering an error. While this marks the test as failed, it won't actually prevent the test from continuing to run with invalid state. I've replaced these instances with `t.Fatal`. There looks to be plenty of opportunity to refactor these tests, but that's better done in a follow up PR. I've made the smallest change possible to make these tests not panic in case of errors.
1 parent b0f646b commit 6c259af

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

vcs_repo_test.go

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestSvnRepo(t *testing.T) {
1919

2020
tempDir, err := ioutil.TempDir("", "go-vcs-svn-tests")
2121
if err != nil {
22-
t.Error(err)
22+
t.Fatal(err)
2323
}
2424
defer func() {
2525
err = os.RemoveAll(tempDir)
@@ -30,54 +30,54 @@ func TestSvnRepo(t *testing.T) {
3030

3131
rep, err := vcs.NewSvnRepo("https://github.com/Masterminds/VCSTestRepo/trunk", tempDir+string(os.PathSeparator)+"VCSTestRepo")
3232
if err != nil {
33-
t.Error(err)
33+
t.Fatal(err)
3434
}
3535
repo := &svnRepo{rep}
3636

3737
// Do an initial checkout.
3838
err = repo.Get()
3939
if err != nil {
40-
t.Errorf("Unable to checkout SVN repo. Err was %s", err)
40+
t.Fatalf("Unable to checkout SVN repo. Err was %#v", err)
4141
}
4242

4343
// Verify SVN repo is a SVN repo
4444
if !repo.CheckLocal() {
45-
t.Error("Problem checking out repo or SVN CheckLocal is not working")
45+
t.Fatal("Problem checking out repo or SVN CheckLocal is not working")
4646
}
4747

4848
// Update the version to a previous version.
4949
err = repo.UpdateVersion("r2")
5050
if err != nil {
51-
t.Errorf("Unable to update SVN repo version. Err was %s", err)
51+
t.Fatalf("Unable to update SVN repo version. Err was %s", err)
5252
}
5353

5454
// Use Version to verify we are on the right version.
5555
v, err := repo.Version()
56-
if v != "2" {
57-
t.Error("Error checking checked SVN out version")
58-
}
5956
if err != nil {
60-
t.Error(err)
57+
t.Fatal(err)
58+
}
59+
if v != "2" {
60+
t.Fatal("Error checking checked SVN out version")
6161
}
6262

6363
// Perform an update which should take up back to the latest version.
6464
err = repo.Update()
6565
if err != nil {
66-
t.Error(err)
66+
t.Fatal(err)
6767
}
6868

6969
// Make sure we are on a newer version because of the update.
7070
v, err = repo.Version()
71-
if v == "2" {
72-
t.Error("Error with version. Still on old version. Update failed")
73-
}
7471
if err != nil {
75-
t.Error(err)
72+
t.Fatal(err)
73+
}
74+
if v == "2" {
75+
t.Fatal("Error with version. Still on old version. Update failed")
7676
}
7777

7878
ci, err := repo.CommitInfo("2")
7979
if err != nil {
80-
t.Error(err)
80+
t.Fatal(err)
8181
}
8282
if ci.Commit != "2" {
8383
t.Error("Svn.CommitInfo wrong commit id")
@@ -90,7 +90,7 @@ func TestSvnRepo(t *testing.T) {
9090
}
9191
ti, err := time.Parse(time.RFC3339Nano, "2015-07-29T13:46:20.000000Z")
9292
if err != nil {
93-
t.Error(err)
93+
t.Fatal(err)
9494
}
9595
if !ti.Equal(ci.Date) {
9696
t.Error("Svn.CommitInfo wrong date")
@@ -109,7 +109,7 @@ func TestHgRepo(t *testing.T) {
109109

110110
tempDir, err := ioutil.TempDir("", "go-vcs-hg-tests")
111111
if err != nil {
112-
t.Error(err)
112+
t.Fatal(err)
113113
}
114114

115115
defer func() {
@@ -121,49 +121,49 @@ func TestHgRepo(t *testing.T) {
121121

122122
rep, err := vcs.NewHgRepo("https://bitbucket.org/mattfarina/testhgrepo", tempDir+"/testhgrepo")
123123
if err != nil {
124-
t.Error(err)
124+
t.Fatal(err)
125125
}
126126

127127
repo := &hgRepo{rep}
128128

129129
// Do an initial clone.
130130
err = repo.Get()
131131
if err != nil {
132-
t.Errorf("Unable to clone Hg repo. Err was %s", err)
132+
t.Fatalf("Unable to clone Hg repo. Err was %s", err)
133133
}
134134

135135
// Verify Hg repo is a Hg repo
136136
if !repo.CheckLocal() {
137-
t.Error("Problem checking out repo or Hg CheckLocal is not working")
137+
t.Fatal("Problem checking out repo or Hg CheckLocal is not working")
138138
}
139139

140140
// Set the version using the short hash.
141141
err = repo.UpdateVersion("a5494ba2177f")
142142
if err != nil {
143-
t.Errorf("Unable to update Hg repo version. Err was %s", err)
143+
t.Fatalf("Unable to update Hg repo version. Err was %s", err)
144144
}
145145

146146
// Use Version to verify we are on the right version.
147147
v, err := repo.Version()
148-
if v != "a5494ba2177ff9ef26feb3c155dfecc350b1a8ef" {
149-
t.Errorf("Error checking checked out Hg version: %s", v)
150-
}
151148
if err != nil {
152-
t.Error(err)
149+
t.Fatal(err)
150+
}
151+
if v != "a5494ba2177ff9ef26feb3c155dfecc350b1a8ef" {
152+
t.Fatalf("Error checking checked out Hg version: %s", v)
153153
}
154154

155155
// Perform an update.
156156
err = repo.Update()
157157
if err != nil {
158-
t.Error(err)
158+
t.Fatal(err)
159159
}
160160

161161
v, err = repo.Version()
162162
if v != "9c6ccbca73e8a1351c834f33f57f1f7a0329ad35" {
163-
t.Errorf("Error checking checked out Hg version: %s", v)
163+
t.Fatalf("Error checking checked out Hg version: %s", v)
164164
}
165165
if err != nil {
166-
t.Error(err)
166+
t.Fatal(err)
167167
}
168168
}
169169

@@ -174,7 +174,7 @@ func TestGitRepo(t *testing.T) {
174174

175175
tempDir, err := ioutil.TempDir("", "go-vcs-git-tests")
176176
if err != nil {
177-
t.Error(err)
177+
t.Fatal(err)
178178
}
179179

180180
defer func() {
@@ -186,40 +186,40 @@ func TestGitRepo(t *testing.T) {
186186

187187
rep, err := vcs.NewGitRepo("https://github.com/Masterminds/VCSTestRepo", tempDir+"/VCSTestRepo")
188188
if err != nil {
189-
t.Error(err)
189+
t.Fatal(err)
190190
}
191191

192192
repo := &gitRepo{rep}
193193

194194
// Do an initial clone.
195195
err = repo.Get()
196196
if err != nil {
197-
t.Errorf("Unable to clone Git repo. Err was %s", err)
197+
t.Fatalf("Unable to clone Git repo. Err was %s", err)
198198
}
199199

200200
// Verify Git repo is a Git repo
201201
if !repo.CheckLocal() {
202-
t.Error("Problem checking out repo or Git CheckLocal is not working")
202+
t.Fatal("Problem checking out repo or Git CheckLocal is not working")
203203
}
204204

205205
// Perform an update.
206206
err = repo.Update()
207207
if err != nil {
208-
t.Error(err)
208+
t.Fatal(err)
209209
}
210210

211211
v, err := repo.Current()
212212
if err != nil {
213-
t.Errorf("Error trying Git Current: %s", err)
213+
t.Fatalf("Error trying Git Current: %s", err)
214214
}
215215
if v != "master" {
216-
t.Errorf("Current failed to detect Git on tip of master. Got version: %s", v)
216+
t.Fatalf("Current failed to detect Git on tip of master. Got version: %s", v)
217217
}
218218

219219
// Set the version using the short hash.
220220
err = repo.UpdateVersion("806b07b")
221221
if err != nil {
222-
t.Errorf("Unable to update Git repo version. Err was %s", err)
222+
t.Fatalf("Unable to update Git repo version. Err was %s", err)
223223
}
224224

225225
// Once a ref has been checked out the repo is in a detached head state.
@@ -228,16 +228,16 @@ func TestGitRepo(t *testing.T) {
228228
// skipping that here.
229229
err = repo.Update()
230230
if err != nil {
231-
t.Error(err)
231+
t.Fatal(err)
232232
}
233233

234234
// Use Version to verify we are on the right version.
235235
v, err = repo.Version()
236-
if v != "806b07b08faa21cfbdae93027904f80174679402" {
237-
t.Error("Error checking checked out Git version")
238-
}
239236
if err != nil {
240-
t.Error(err)
237+
t.Fatal(err)
238+
}
239+
if v != "806b07b08faa21cfbdae93027904f80174679402" {
240+
t.Fatal("Error checking checked out Git version")
241241
}
242242
}
243243

@@ -248,7 +248,7 @@ func TestBzrRepo(t *testing.T) {
248248

249249
tempDir, err := ioutil.TempDir("", "go-vcs-bzr-tests")
250250
if err != nil {
251-
t.Error(err)
251+
t.Fatal(err)
252252
}
253253

254254
defer func() {
@@ -268,41 +268,41 @@ func TestBzrRepo(t *testing.T) {
268268
// Do an initial clone.
269269
err = repo.Get()
270270
if err != nil {
271-
t.Errorf("Unable to clone Bzr repo. Err was %s", err)
271+
t.Fatalf("Unable to clone Bzr repo. Err was %s", err)
272272
}
273273

274274
// Verify Bzr repo is a Bzr repo
275275
if !repo.CheckLocal() {
276-
t.Error("Problem checking out repo or Bzr CheckLocal is not working")
276+
t.Fatal("Problem checking out repo or Bzr CheckLocal is not working")
277277
}
278278

279279
v, err := repo.Current()
280280
if err != nil {
281-
t.Errorf("Error trying Bzr Current: %s", err)
281+
t.Fatalf("Error trying Bzr Current: %s", err)
282282
}
283283
if v != "-1" {
284-
t.Errorf("Current failed to detect Bzr on tip of branch. Got version: %s", v)
284+
t.Fatalf("Current failed to detect Bzr on tip of branch. Got version: %s", v)
285285
}
286286

287287
err = repo.UpdateVersion("2")
288288
if err != nil {
289-
t.Errorf("Unable to update Bzr repo version. Err was %s", err)
289+
t.Fatalf("Unable to update Bzr repo version. Err was %s", err)
290290
}
291291

292292
// Use Version to verify we are on the right version.
293293
v, err = repo.Version()
294-
if v != "2" {
295-
t.Error("Error checking checked out Bzr version")
296-
}
297294
if err != nil {
298-
t.Error(err)
295+
t.Fatal(err)
296+
}
297+
if v != "2" {
298+
t.Fatal("Error checking checked out Bzr version")
299299
}
300300

301301
v, err = repo.Current()
302302
if err != nil {
303-
t.Errorf("Error trying Bzr Current: %s", err)
303+
t.Fatalf("Error trying Bzr Current: %s", err)
304304
}
305305
if v != "2" {
306-
t.Errorf("Current failed to detect Bzr on rev 2 of branch. Got version: %s", v)
306+
t.Fatalf("Current failed to detect Bzr on rev 2 of branch. Got version: %s", v)
307307
}
308308
}

0 commit comments

Comments
 (0)