1 // Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
5 // +build darwin,!kqueue windows
14 // noevent stripts test-case from expected event list, used when action is not
15 // expected to trigger any events.
16 func noevent(cas WCase) WCase {
17 return WCase{Action: cas.Action}
20 func TestWatcherRecursiveRewatch(t *testing.T) {
21 w := newWatcherTest(t, "testdata/vfs.txt")
25 create(w, "src/github.com/rjeczalik/file"),
26 create(w, "src/github.com/rjeczalik/dir/"),
27 noevent(create(w, "src/github.com/rjeczalik/fs/dir/")),
28 noevent(create(w, "src/github.com/dir/")),
29 noevent(write(w, "src/github.com/rjeczalik/file", []byte("XD"))),
30 noevent(rename(w, "src/github.com/rjeczalik/fs/LICENSE", "src/LICENSE")),
33 w.Watch("src/github.com/rjeczalik", Create)
37 create(w, "src/github.com/rjeczalik/fs/file"),
38 create(w, "src/github.com/rjeczalik/fs/cmd/gotree/file"),
39 create(w, "src/github.com/rjeczalik/fs/cmd/dir/"),
40 create(w, "src/github.com/rjeczalik/fs/cmd/gotree/dir/"),
41 noevent(write(w, "src/github.com/rjeczalik/fs/file", []byte("XD"))),
42 noevent(create(w, "src/github.com/anotherdir/")),
45 w.RecursiveRewatch("src/github.com/rjeczalik", "src/github.com/rjeczalik", Create, Create)
49 create(w, "src/github.com/rjeczalik/1"),
50 create(w, "src/github.com/rjeczalik/2/"),
51 noevent(create(w, "src/github.com/rjeczalik/fs/cmd/1")),
52 noevent(create(w, "src/github.com/rjeczalik/fs/1/")),
53 noevent(write(w, "src/github.com/rjeczalik/fs/file", []byte("XD"))),
56 w.Rewatch("src/github.com/rjeczalik", Create, Create)
60 // TODO(rjeczalik): move to watcher_test.go after #5
61 func TestIsDirCreateEvent(t *testing.T) {
62 w := NewWatcherTest(t, "testdata/vfs.txt")
67 create(w, "src/github.com/jszwec/"),
69 create(w, "src/github.com/jszwec/gojunitxml/"),
71 create(w, "src/github.com/jszwec/gojunitxml/README.md"),
73 create(w, "src/github.com/jszwec/gojunitxml/LICENSE"),
75 create(w, "src/github.com/jszwec/gojunitxml/cmd/"),
86 fn := func(i int, _ WCase, ei EventInfo) error {
89 return fmt.Errorf("received EventInfo does not implement isDirer")
91 switch ok, err := d.isDir(); {
95 return fmt.Errorf("want ok=%v; got %v", dirs[i], ok)
101 w.ExpectAnyFunc(cases[:], fn)