-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
48 lines (44 loc) · 1.21 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package sniffy_test
import (
"path/filepath"
"time"
"github.com/alihammad-gist/sniffy"
"testing"
)
func TestRecurWatch(t *testing.T) {
dir := getDir()
ops := []Op{
Op{filepath.Join(dir, "root.tree"), sniffy.Remove},
Op{filepath.Join(dir, "l1d3/global.log"), sniffy.Write},
Op{filepath.Join(dir, "l1d3/l2d2/pre.xstream"), sniffy.Rename},
Op{filepath.Join(dir, "l1d2/l2d2/vars.less"), sniffy.Remove},
Op{filepath.Join(dir, "l1d2/l2d2/vars.less"), sniffy.Create},
Op{filepath.Join(dir, "l1d1/l2d2/l3d1"), sniffy.Create},
Op{filepath.Join(dir, "l1d1/l2d2/l3d1/tree.log"), sniffy.Create},
Op{filepath.Join(dir, "l1d1/l2d2/l3d1/tree.log"), sniffy.Remove},
}
for _, xOp := range ops {
trans := sniffy.Transmitter()
w, err := sniffy.NewWatcher(trans)
if err != nil {
t.Log(err)
t.Fail()
}
w.AddDir(dir)
triggerOperation(xOp.path, xOp.op)
select {
case e := <-trans.Events:
if e.Name != xOp.path || e.Op != xOp.op {
t.Log("Expected", xOp.path, xOp.op, "Actual", e.Name, e.Op)
t.Fail()
}
case err := <-w.Errors:
t.Log("Watch Error", err, xOp.path, xOp.op)
t.Fail()
case <-time.After(WaitDuration):
t.Log("Timedout", xOp.path, xOp.op)
t.Fail()
}
w.Close()
}
}