Skip to content

Commit cf31462

Browse files
landismndeloof
authored andcommitted
tests: make test fixtures responsible for tearing themselves down (docker#5512)
1 parent 1b71e3e commit cf31462

File tree

3 files changed

+1
-27
lines changed

3 files changed

+1
-27
lines changed

pkg/watch/notify_test.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ func TestWindowsBufferSize(t *testing.T) {
3939

4040
func TestNoEvents(t *testing.T) {
4141
f := newNotifyFixture(t)
42-
defer f.tearDown()
4342
f.assertEvents()
4443
}
4544

4645
func TestNoWatches(t *testing.T) {
4746
f := newNotifyFixture(t)
48-
defer f.tearDown()
4947
f.paths = nil
5048
f.rebuildWatcher()
5149
f.assertEvents()
@@ -58,7 +56,6 @@ func TestEventOrdering(t *testing.T) {
5856
return
5957
}
6058
f := newNotifyFixture(t)
61-
defer f.tearDown()
6259

6360
count := 8
6461
dirs := make([]string, count)
@@ -90,7 +87,6 @@ func TestEventOrdering(t *testing.T) {
9087
// them all quickly. Make sure there are no errors.
9188
func TestGitBranchSwitch(t *testing.T) {
9289
f := newNotifyFixture(t)
93-
defer f.tearDown()
9490

9591
count := 10
9692
dirs := make([]string, count)
@@ -144,7 +140,6 @@ func TestGitBranchSwitch(t *testing.T) {
144140

145141
func TestWatchesAreRecursive(t *testing.T) {
146142
f := newNotifyFixture(t)
147-
defer f.tearDown()
148143

149144
root := f.TempDir("root")
150145

@@ -166,7 +161,6 @@ func TestWatchesAreRecursive(t *testing.T) {
166161

167162
func TestNewDirectoriesAreRecursivelyWatched(t *testing.T) {
168163
f := newNotifyFixture(t)
169-
defer f.tearDown()
170164

171165
root := f.TempDir("root")
172166

@@ -191,7 +185,6 @@ func TestNewDirectoriesAreRecursivelyWatched(t *testing.T) {
191185

192186
func TestWatchNonExistentPath(t *testing.T) {
193187
f := newNotifyFixture(t)
194-
defer f.tearDown()
195188

196189
root := f.TempDir("root")
197190
path := filepath.Join(root, "change")
@@ -206,7 +199,6 @@ func TestWatchNonExistentPath(t *testing.T) {
206199

207200
func TestWatchNonExistentPathDoesNotFireSiblingEvent(t *testing.T) {
208201
f := newNotifyFixture(t)
209-
defer f.tearDown()
210202

211203
root := f.TempDir("root")
212204
watchedFile := filepath.Join(root, "a.txt")
@@ -222,7 +214,6 @@ func TestWatchNonExistentPathDoesNotFireSiblingEvent(t *testing.T) {
222214

223215
func TestRemove(t *testing.T) {
224216
f := newNotifyFixture(t)
225-
defer f.tearDown()
226217

227218
root := f.TempDir("root")
228219
path := filepath.Join(root, "change")
@@ -242,7 +233,6 @@ func TestRemove(t *testing.T) {
242233

243234
func TestRemoveAndAddBack(t *testing.T) {
244235
f := newNotifyFixture(t)
245-
defer f.tearDown()
246236

247237
path := filepath.Join(f.paths[0], "change")
248238

@@ -272,7 +262,6 @@ func TestRemoveAndAddBack(t *testing.T) {
272262

273263
func TestSingleFile(t *testing.T) {
274264
f := newNotifyFixture(t)
275-
defer f.tearDown()
276265

277266
root := f.TempDir("root")
278267
path := filepath.Join(root, "change")
@@ -296,7 +285,6 @@ func TestWriteBrokenLink(t *testing.T) {
296285
t.Skip("no user-space symlinks on windows")
297286
}
298287
f := newNotifyFixture(t)
299-
defer f.tearDown()
300288

301289
link := filepath.Join(f.paths[0], "brokenLink")
302290
missingFile := filepath.Join(f.paths[0], "missingFile")
@@ -313,7 +301,6 @@ func TestWriteGoodLink(t *testing.T) {
313301
t.Skip("no user-space symlinks on windows")
314302
}
315303
f := newNotifyFixture(t)
316-
defer f.tearDown()
317304

318305
goodFile := filepath.Join(f.paths[0], "goodFile")
319306
err := ioutil.WriteFile(goodFile, []byte("hello"), 0644)
@@ -335,7 +322,6 @@ func TestWatchBrokenLink(t *testing.T) {
335322
t.Skip("no user-space symlinks on windows")
336323
}
337324
f := newNotifyFixture(t)
338-
defer f.tearDown()
339325

340326
newRoot, err := NewDir(t.Name())
341327
if err != nil {
@@ -363,7 +349,6 @@ func TestWatchBrokenLink(t *testing.T) {
363349

364350
func TestMoveAndReplace(t *testing.T) {
365351
f := newNotifyFixture(t)
366-
defer f.tearDown()
367352

368353
root := f.TempDir("root")
369354
file := filepath.Join(root, "myfile")
@@ -383,7 +368,6 @@ func TestMoveAndReplace(t *testing.T) {
383368

384369
func TestWatchBothDirAndFile(t *testing.T) {
385370
f := newNotifyFixture(t)
386-
defer f.tearDown()
387371

388372
dir := f.JoinPath("foo")
389373
fileA := f.JoinPath("foo", "a")
@@ -402,7 +386,6 @@ func TestWatchBothDirAndFile(t *testing.T) {
402386

403387
func TestWatchNonexistentFileInNonexistentDirectoryCreatedSimultaneously(t *testing.T) {
404388
f := newNotifyFixture(t)
405-
defer f.tearDown()
406389

407390
root := f.JoinPath("root")
408391
err := os.Mkdir(root, 0777)
@@ -420,7 +403,6 @@ func TestWatchNonexistentFileInNonexistentDirectoryCreatedSimultaneously(t *test
420403

421404
func TestWatchNonexistentDirectory(t *testing.T) {
422405
f := newNotifyFixture(t)
423-
defer f.tearDown()
424406

425407
root := f.JoinPath("root")
426408
err := os.Mkdir(root, 0777)
@@ -450,7 +432,6 @@ func TestWatchNonexistentDirectory(t *testing.T) {
450432

451433
func TestWatchNonexistentFileInNonexistentDirectory(t *testing.T) {
452434
f := newNotifyFixture(t)
453-
defer f.tearDown()
454435

455436
root := f.JoinPath("root")
456437
err := os.Mkdir(root, 0777)
@@ -475,7 +456,6 @@ func TestWatchNonexistentFileInNonexistentDirectory(t *testing.T) {
475456

476457
func TestWatchCountInnerFile(t *testing.T) {
477458
f := newNotifyFixture(t)
478-
defer f.tearDown()
479459

480460
root := f.paths[0]
481461
a := f.JoinPath(root, "a")
@@ -493,7 +473,6 @@ func TestWatchCountInnerFile(t *testing.T) {
493473

494474
func TestWatchCountInnerFileWithIgnore(t *testing.T) {
495475
f := newNotifyFixture(t)
496-
defer f.tearDown()
497476

498477
root := f.paths[0]
499478
ignore, _ := dockerignore.NewDockerPatternMatcher(root, []string{
@@ -517,7 +496,6 @@ func TestWatchCountInnerFileWithIgnore(t *testing.T) {
517496

518497
func TestIgnoreCreatedDir(t *testing.T) {
519498
f := newNotifyFixture(t)
520-
defer f.tearDown()
521499

522500
root := f.paths[0]
523501
ignore, _ := dockerignore.NewDockerPatternMatcher(root, []string{"a/b"})
@@ -538,7 +516,6 @@ func TestIgnoreCreatedDir(t *testing.T) {
538516

539517
func TestIgnoreCreatedDirWithExclusions(t *testing.T) {
540518
f := newNotifyFixture(t)
541-
defer f.tearDown()
542519

543520
root := f.paths[0]
544521
ignore, _ := dockerignore.NewDockerPatternMatcher(root,
@@ -564,7 +541,6 @@ func TestIgnoreCreatedDirWithExclusions(t *testing.T) {
564541

565542
func TestIgnoreInitialDir(t *testing.T) {
566543
f := newNotifyFixture(t)
567-
defer f.tearDown()
568544

569545
root := f.TempDir("root")
570546
ignore, _ := dockerignore.NewDockerPatternMatcher(root, []string{"a/b"})
@@ -612,6 +588,7 @@ func newNotifyFixture(t *testing.T) *notifyFixture {
612588
out: out,
613589
}
614590
nf.watch(nf.TempDir("watched"))
591+
t.Cleanup(nf.tearDown)
615592
return nf
616593
}
617594

@@ -759,6 +736,5 @@ func (f *notifyFixture) closeWatcher() {
759736
func (f *notifyFixture) tearDown() {
760737
f.cancel()
761738
f.closeWatcher()
762-
f.TempDirFixture.TearDown()
763739
numberOfWatches.Set(0)
764740
}

pkg/watch/paths_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
func TestGreatestExistingAncestor(t *testing.T) {
1313
f := tempdir.NewTempDirFixture(t)
14-
defer f.TearDown()
1514

1615
p, err := greatestExistingAncestor(f.Path())
1716
assert.NoError(t, err)

pkg/watch/watcher_naive_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ func TestDontWatchEachFile(t *testing.T) {
2323
// this test uses a Linux way to get the number of watches to make sure we're watching
2424
// per-directory, not per-file
2525
f := newNotifyFixture(t)
26-
defer f.tearDown()
2726

2827
watched := f.TempDir("watched")
2928

0 commit comments

Comments
 (0)