mirror of
https://github.com/docker/compose.git
synced 2025-07-26 23:24:05 +02:00
tests: make test fixtures responsible for tearing themselves down (#5512)
This commit is contained in:
parent
1b71e3efb3
commit
cf31462398
@ -39,13 +39,11 @@ func TestWindowsBufferSize(t *testing.T) {
|
|||||||
|
|
||||||
func TestNoEvents(t *testing.T) {
|
func TestNoEvents(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
f.assertEvents()
|
f.assertEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoWatches(t *testing.T) {
|
func TestNoWatches(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
f.paths = nil
|
f.paths = nil
|
||||||
f.rebuildWatcher()
|
f.rebuildWatcher()
|
||||||
f.assertEvents()
|
f.assertEvents()
|
||||||
@ -58,7 +56,6 @@ func TestEventOrdering(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
count := 8
|
count := 8
|
||||||
dirs := make([]string, count)
|
dirs := make([]string, count)
|
||||||
@ -90,7 +87,6 @@ func TestEventOrdering(t *testing.T) {
|
|||||||
// them all quickly. Make sure there are no errors.
|
// them all quickly. Make sure there are no errors.
|
||||||
func TestGitBranchSwitch(t *testing.T) {
|
func TestGitBranchSwitch(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
count := 10
|
count := 10
|
||||||
dirs := make([]string, count)
|
dirs := make([]string, count)
|
||||||
@ -144,7 +140,6 @@ func TestGitBranchSwitch(t *testing.T) {
|
|||||||
|
|
||||||
func TestWatchesAreRecursive(t *testing.T) {
|
func TestWatchesAreRecursive(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.TempDir("root")
|
root := f.TempDir("root")
|
||||||
|
|
||||||
@ -166,7 +161,6 @@ func TestWatchesAreRecursive(t *testing.T) {
|
|||||||
|
|
||||||
func TestNewDirectoriesAreRecursivelyWatched(t *testing.T) {
|
func TestNewDirectoriesAreRecursivelyWatched(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.TempDir("root")
|
root := f.TempDir("root")
|
||||||
|
|
||||||
@ -191,7 +185,6 @@ func TestNewDirectoriesAreRecursivelyWatched(t *testing.T) {
|
|||||||
|
|
||||||
func TestWatchNonExistentPath(t *testing.T) {
|
func TestWatchNonExistentPath(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.TempDir("root")
|
root := f.TempDir("root")
|
||||||
path := filepath.Join(root, "change")
|
path := filepath.Join(root, "change")
|
||||||
@ -206,7 +199,6 @@ func TestWatchNonExistentPath(t *testing.T) {
|
|||||||
|
|
||||||
func TestWatchNonExistentPathDoesNotFireSiblingEvent(t *testing.T) {
|
func TestWatchNonExistentPathDoesNotFireSiblingEvent(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.TempDir("root")
|
root := f.TempDir("root")
|
||||||
watchedFile := filepath.Join(root, "a.txt")
|
watchedFile := filepath.Join(root, "a.txt")
|
||||||
@ -222,7 +214,6 @@ func TestWatchNonExistentPathDoesNotFireSiblingEvent(t *testing.T) {
|
|||||||
|
|
||||||
func TestRemove(t *testing.T) {
|
func TestRemove(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.TempDir("root")
|
root := f.TempDir("root")
|
||||||
path := filepath.Join(root, "change")
|
path := filepath.Join(root, "change")
|
||||||
@ -242,7 +233,6 @@ func TestRemove(t *testing.T) {
|
|||||||
|
|
||||||
func TestRemoveAndAddBack(t *testing.T) {
|
func TestRemoveAndAddBack(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
path := filepath.Join(f.paths[0], "change")
|
path := filepath.Join(f.paths[0], "change")
|
||||||
|
|
||||||
@ -272,7 +262,6 @@ func TestRemoveAndAddBack(t *testing.T) {
|
|||||||
|
|
||||||
func TestSingleFile(t *testing.T) {
|
func TestSingleFile(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.TempDir("root")
|
root := f.TempDir("root")
|
||||||
path := filepath.Join(root, "change")
|
path := filepath.Join(root, "change")
|
||||||
@ -296,7 +285,6 @@ func TestWriteBrokenLink(t *testing.T) {
|
|||||||
t.Skip("no user-space symlinks on windows")
|
t.Skip("no user-space symlinks on windows")
|
||||||
}
|
}
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
link := filepath.Join(f.paths[0], "brokenLink")
|
link := filepath.Join(f.paths[0], "brokenLink")
|
||||||
missingFile := filepath.Join(f.paths[0], "missingFile")
|
missingFile := filepath.Join(f.paths[0], "missingFile")
|
||||||
@ -313,7 +301,6 @@ func TestWriteGoodLink(t *testing.T) {
|
|||||||
t.Skip("no user-space symlinks on windows")
|
t.Skip("no user-space symlinks on windows")
|
||||||
}
|
}
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
goodFile := filepath.Join(f.paths[0], "goodFile")
|
goodFile := filepath.Join(f.paths[0], "goodFile")
|
||||||
err := ioutil.WriteFile(goodFile, []byte("hello"), 0644)
|
err := ioutil.WriteFile(goodFile, []byte("hello"), 0644)
|
||||||
@ -335,7 +322,6 @@ func TestWatchBrokenLink(t *testing.T) {
|
|||||||
t.Skip("no user-space symlinks on windows")
|
t.Skip("no user-space symlinks on windows")
|
||||||
}
|
}
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
newRoot, err := NewDir(t.Name())
|
newRoot, err := NewDir(t.Name())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -363,7 +349,6 @@ func TestWatchBrokenLink(t *testing.T) {
|
|||||||
|
|
||||||
func TestMoveAndReplace(t *testing.T) {
|
func TestMoveAndReplace(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.TempDir("root")
|
root := f.TempDir("root")
|
||||||
file := filepath.Join(root, "myfile")
|
file := filepath.Join(root, "myfile")
|
||||||
@ -383,7 +368,6 @@ func TestMoveAndReplace(t *testing.T) {
|
|||||||
|
|
||||||
func TestWatchBothDirAndFile(t *testing.T) {
|
func TestWatchBothDirAndFile(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
dir := f.JoinPath("foo")
|
dir := f.JoinPath("foo")
|
||||||
fileA := f.JoinPath("foo", "a")
|
fileA := f.JoinPath("foo", "a")
|
||||||
@ -402,7 +386,6 @@ func TestWatchBothDirAndFile(t *testing.T) {
|
|||||||
|
|
||||||
func TestWatchNonexistentFileInNonexistentDirectoryCreatedSimultaneously(t *testing.T) {
|
func TestWatchNonexistentFileInNonexistentDirectoryCreatedSimultaneously(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.JoinPath("root")
|
root := f.JoinPath("root")
|
||||||
err := os.Mkdir(root, 0777)
|
err := os.Mkdir(root, 0777)
|
||||||
@ -420,7 +403,6 @@ func TestWatchNonexistentFileInNonexistentDirectoryCreatedSimultaneously(t *test
|
|||||||
|
|
||||||
func TestWatchNonexistentDirectory(t *testing.T) {
|
func TestWatchNonexistentDirectory(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.JoinPath("root")
|
root := f.JoinPath("root")
|
||||||
err := os.Mkdir(root, 0777)
|
err := os.Mkdir(root, 0777)
|
||||||
@ -450,7 +432,6 @@ func TestWatchNonexistentDirectory(t *testing.T) {
|
|||||||
|
|
||||||
func TestWatchNonexistentFileInNonexistentDirectory(t *testing.T) {
|
func TestWatchNonexistentFileInNonexistentDirectory(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.JoinPath("root")
|
root := f.JoinPath("root")
|
||||||
err := os.Mkdir(root, 0777)
|
err := os.Mkdir(root, 0777)
|
||||||
@ -475,7 +456,6 @@ func TestWatchNonexistentFileInNonexistentDirectory(t *testing.T) {
|
|||||||
|
|
||||||
func TestWatchCountInnerFile(t *testing.T) {
|
func TestWatchCountInnerFile(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.paths[0]
|
root := f.paths[0]
|
||||||
a := f.JoinPath(root, "a")
|
a := f.JoinPath(root, "a")
|
||||||
@ -493,7 +473,6 @@ func TestWatchCountInnerFile(t *testing.T) {
|
|||||||
|
|
||||||
func TestWatchCountInnerFileWithIgnore(t *testing.T) {
|
func TestWatchCountInnerFileWithIgnore(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.paths[0]
|
root := f.paths[0]
|
||||||
ignore, _ := dockerignore.NewDockerPatternMatcher(root, []string{
|
ignore, _ := dockerignore.NewDockerPatternMatcher(root, []string{
|
||||||
@ -517,7 +496,6 @@ func TestWatchCountInnerFileWithIgnore(t *testing.T) {
|
|||||||
|
|
||||||
func TestIgnoreCreatedDir(t *testing.T) {
|
func TestIgnoreCreatedDir(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.paths[0]
|
root := f.paths[0]
|
||||||
ignore, _ := dockerignore.NewDockerPatternMatcher(root, []string{"a/b"})
|
ignore, _ := dockerignore.NewDockerPatternMatcher(root, []string{"a/b"})
|
||||||
@ -538,7 +516,6 @@ func TestIgnoreCreatedDir(t *testing.T) {
|
|||||||
|
|
||||||
func TestIgnoreCreatedDirWithExclusions(t *testing.T) {
|
func TestIgnoreCreatedDirWithExclusions(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.paths[0]
|
root := f.paths[0]
|
||||||
ignore, _ := dockerignore.NewDockerPatternMatcher(root,
|
ignore, _ := dockerignore.NewDockerPatternMatcher(root,
|
||||||
@ -564,7 +541,6 @@ func TestIgnoreCreatedDirWithExclusions(t *testing.T) {
|
|||||||
|
|
||||||
func TestIgnoreInitialDir(t *testing.T) {
|
func TestIgnoreInitialDir(t *testing.T) {
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
root := f.TempDir("root")
|
root := f.TempDir("root")
|
||||||
ignore, _ := dockerignore.NewDockerPatternMatcher(root, []string{"a/b"})
|
ignore, _ := dockerignore.NewDockerPatternMatcher(root, []string{"a/b"})
|
||||||
@ -612,6 +588,7 @@ func newNotifyFixture(t *testing.T) *notifyFixture {
|
|||||||
out: out,
|
out: out,
|
||||||
}
|
}
|
||||||
nf.watch(nf.TempDir("watched"))
|
nf.watch(nf.TempDir("watched"))
|
||||||
|
t.Cleanup(nf.tearDown)
|
||||||
return nf
|
return nf
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,6 +736,5 @@ func (f *notifyFixture) closeWatcher() {
|
|||||||
func (f *notifyFixture) tearDown() {
|
func (f *notifyFixture) tearDown() {
|
||||||
f.cancel()
|
f.cancel()
|
||||||
f.closeWatcher()
|
f.closeWatcher()
|
||||||
f.TempDirFixture.TearDown()
|
|
||||||
numberOfWatches.Set(0)
|
numberOfWatches.Set(0)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
|
|
||||||
func TestGreatestExistingAncestor(t *testing.T) {
|
func TestGreatestExistingAncestor(t *testing.T) {
|
||||||
f := tempdir.NewTempDirFixture(t)
|
f := tempdir.NewTempDirFixture(t)
|
||||||
defer f.TearDown()
|
|
||||||
|
|
||||||
p, err := greatestExistingAncestor(f.Path())
|
p, err := greatestExistingAncestor(f.Path())
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -23,7 +23,6 @@ func TestDontWatchEachFile(t *testing.T) {
|
|||||||
// this test uses a Linux way to get the number of watches to make sure we're watching
|
// this test uses a Linux way to get the number of watches to make sure we're watching
|
||||||
// per-directory, not per-file
|
// per-directory, not per-file
|
||||||
f := newNotifyFixture(t)
|
f := newNotifyFixture(t)
|
||||||
defer f.tearDown()
|
|
||||||
|
|
||||||
watched := f.TempDir("watched")
|
watched := f.TempDir("watched")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user