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.
15 func icreate(w *W, path string) WCase {
16 cas := create(w, path)
17 cas.Events = append(cas.Events,
18 &Call{P: path, E: InCreate},
23 func iremove(w *W, path string) WCase {
24 cas := remove(w, path)
25 cas.Events = append(cas.Events,
26 &Call{P: path, E: InDelete},
31 func iopen(w *W, path string) WCase {
34 f, err := os.OpenFile(filepath.Join(w.root, path), os.O_RDWR, 0644)
36 w.Fatalf("OpenFile(%q)=%v", path, err)
38 if err := f.Close(); err != nil {
39 w.Fatalf("Close(%q)=%v", path, err)
43 &Call{P: path, E: InAccess},
44 &Call{P: path, E: InOpen},
45 &Call{P: path, E: InCloseNowrite},
50 func iread(w *W, path string, p []byte) WCase {
53 f, err := os.OpenFile(filepath.Join(w.root, path), os.O_RDWR, 0644)
55 w.Fatalf("OpenFile(%q)=%v", path, err)
57 if _, err := f.Read(p); err != nil {
58 w.Fatalf("Read(%q)=%v", path, err)
60 if err := f.Close(); err != nil {
61 w.Fatalf("Close(%q)=%v", path, err)
65 &Call{P: path, E: InAccess},
66 &Call{P: path, E: InOpen},
67 &Call{P: path, E: InModify},
68 &Call{P: path, E: InCloseNowrite},
73 func iwrite(w *W, path string, p []byte) WCase {
74 cas := write(w, path, p)
75 path = cas.Events[0].Path()
76 cas.Events = append(cas.Events,
77 &Call{P: path, E: InAccess},
78 &Call{P: path, E: InOpen},
79 &Call{P: path, E: InModify},
80 &Call{P: path, E: InCloseWrite},
85 func irename(w *W, path string) WCase {
89 file := filepath.Join(w.root, path)
90 if err := os.Rename(file, file+ext); err != nil {
91 w.Fatalf("Rename(%q, %q)=%v", path, path+ext, err)
95 &Call{P: path, E: InMovedFrom},
96 &Call{P: path + ext, E: InMovedTo},
97 &Call{P: path, E: InOpen},
98 &Call{P: path, E: InAccess},
99 &Call{P: path, E: InCreate},
104 var events = []Event{
119 func TestWatcherInotify(t *testing.T) {
120 w := NewWatcherTest(t, "testdata/vfs.txt", events...)
124 iopen(w, "src/github.com/rjeczalik/fs/fs.go"),
125 iwrite(w, "src/github.com/rjeczalik/fs/fs.go", []byte("XD")),
126 iread(w, "src/github.com/rjeczalik/fs/fs.go", []byte("XD")),
127 iremove(w, "src/github.com/ppknap/link/README.md"),
128 irename(w, "src/github.com/rjeczalik/fs/LICENSE"),
131 w.ExpectAny(cases[:])