| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package notify |
| 8 |
|
| 9 |
import ( |
| 10 |
"os" |
| 11 |
"testing" |
| 12 |
"time" |
| 13 |
) |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
func TestWatcher(t *testing.T) { |
| 18 |
w := NewWatcherTest(t, "testdata/vfs.txt") |
| 19 |
defer w.Close() |
| 20 |
|
| 21 |
cases := [...]WCase{ |
| 22 |
create(w, "src/github.com/ppknap/link/include/coost/.link.hpp.swp"), |
| 23 |
create(w, "src/github.com/rjeczalik/fs/fs_test.go"), |
| 24 |
create(w, "src/github.com/rjeczalik/fs/binfs/"), |
| 25 |
create(w, "src/github.com/rjeczalik/fs/binfs.go"), |
| 26 |
create(w, "src/github.com/rjeczalik/fs/binfs_test.go"), |
| 27 |
remove(w, "src/github.com/rjeczalik/fs/binfs/"), |
| 28 |
create(w, "src/github.com/rjeczalik/fs/binfs/"), |
| 29 |
create(w, "src/github.com/rjeczalik/fs/virfs"), |
| 30 |
remove(w, "src/github.com/rjeczalik/fs/virfs"), |
| 31 |
create(w, "file"), |
| 32 |
create(w, "dir/"), |
| 33 |
} |
| 34 |
|
| 35 |
w.ExpectAny(cases[:]) |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
func TestStopPathNotExists(t *testing.T) { |
| 42 |
w := NewWatcherTest(t, "testdata/vfs.txt") |
| 43 |
defer w.Close() |
| 44 |
|
| 45 |
if err := os.RemoveAll(w.root); err != nil { |
| 46 |
panic(err) |
| 47 |
} |
| 48 |
Sync() |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
time.Sleep(time.Duration(100) * time.Millisecond) |
| 54 |
w.Watcher.Unwatch(w.root) |
| 55 |
time.Sleep(time.Duration(100) * time.Millisecond) |
| 56 |
|
| 57 |
if err := os.Mkdir(w.root, 0777); err != nil { |
| 58 |
panic(err) |
| 59 |
} |
| 60 |
Sync() |
| 61 |
w.Watch("", All) |
| 62 |
|
| 63 |
drainall(w.C) |
| 64 |
cases := [...]WCase{ |
| 65 |
create(w, "file"), |
| 66 |
create(w, "dir/"), |
| 67 |
} |
| 68 |
w.ExpectAny(cases[:]) |
| 69 |
} |
| 70 |
|
| 71 |
func TestWatcherUnwatch(t *testing.T) { |
| 72 |
w := NewWatcherTest(t, "testdata/vfs.txt") |
| 73 |
defer w.Close() |
| 74 |
|
| 75 |
remove(w, "src/github.com/ppknap/link/test/test_circular_calls.cpp").Action() |
| 76 |
w.Unwatch("") |
| 77 |
|
| 78 |
w.Watch("", All) |
| 79 |
|
| 80 |
drainall(w.C) |
| 81 |
cases := [...]WCase{ |
| 82 |
create(w, "file"), |
| 83 |
create(w, "dir/"), |
| 84 |
} |
| 85 |
w.ExpectAny(cases[:]) |
| 86 |
} |