summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--watcher_test.go28
1 files changed, 9 insertions, 19 deletions
diff --git a/watcher_test.go b/watcher_test.go
index 6136afc..7aa7d22 100644
--- a/watcher_test.go
+++ b/watcher_test.go
@@ -15,7 +15,7 @@ import (
func TestWatcher(t *testing.T) {
var (
- testDir = `testdata/watcher`
+ testDir = t.TempDir()
convertOpts = ConvertOptions{
Root: testDir,
}
@@ -24,20 +24,6 @@ func TestWatcher(t *testing.T) {
err error
)
- err = os.RemoveAll(testDir)
- if err != nil {
- t.Logf(err.Error())
- }
-
- err = os.MkdirAll(testDir, 0700)
- if err != nil {
- t.Fatal(err)
- }
-
- t.Cleanup(func() {
- os.RemoveAll(testDir)
- })
-
converter, err = NewConverter(``)
if err != nil {
t.Fatal(err)
@@ -55,6 +41,8 @@ func TestWatcher(t *testing.T) {
t.Fatal(err)
}
+ testWatcher.watchDir.Delay = 100 * time.Millisecond
+
err = testWatcher.start()
if err != nil {
t.Fatal(err)
@@ -105,7 +93,7 @@ func testAdocCreate(t *testing.T, testWatcher *watcher, tdata *test.Data, pathFi
// Let the OS sync the file system before we create new file,
// otherwise the modtime for fs.Root does not changes.
- time.Sleep(1 * time.Second)
+ time.Sleep(100 * time.Millisecond)
err = os.WriteFile(pathFile, expBody, 0600)
if err != nil {
@@ -138,7 +126,7 @@ func testAdocUpdate(t *testing.T, testWatcher *watcher, tdata *test.Data, pathFi
// Let the OS sync the file system before we create new file,
// otherwise the modtime for fs.Root does not changes.
- time.Sleep(1 * time.Second)
+ time.Sleep(100 * time.Millisecond)
err = os.WriteFile(pathFile, expBody, 0600)
if err != nil {
@@ -192,7 +180,7 @@ func testMarkdownCreate(t *testing.T, testWatcher *watcher, tdata *test.Data, pa
// Let the OS sync the file system before we create new file,
// otherwise the modtime for fs.Root does not changes.
- time.Sleep(1 * time.Second)
+ time.Sleep(100 * time.Millisecond)
err = os.WriteFile(pathFileMarkdown, body, 0600)
if err != nil {
@@ -225,7 +213,7 @@ func testMarkdownUpdate(t *testing.T, testWatcher *watcher, tdata *test.Data, pa
// Let the OS sync the file system before we create new file,
// otherwise the modtime for fs.Root does not changes.
- time.Sleep(1 * time.Second)
+ time.Sleep(100 * time.Millisecond)
err = os.WriteFile(pathFileMarkdown, body, 0600)
if err != nil {
@@ -253,6 +241,8 @@ func testMarkdownDelete(t *testing.T, testWatcher *watcher, pathFileMarkdown str
gotIsExist bool
)
+ time.Sleep(100 * time.Millisecond)
+
err = os.Remove(pathFileMarkdown)
if err != nil {
t.Fatal(err)