OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / rjeczalik / notify / notify_test.go
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.
4
5 // +build darwin linux freebsd dragonfly netbsd openbsd windows solaris
6
7 package notify
8
9 import "testing"
10
11 func TestNotifyExample(t *testing.T) {
12         n := NewNotifyTest(t, "testdata/vfs.txt")
13         defer n.Close()
14
15         ch := NewChans(3)
16
17         // Watch-points can be set explicitly via Watch/Stop calls...
18         n.Watch("src/github.com/rjeczalik/fs", ch[0], Write)
19         n.Watch("src/github.com/pblaszczyk/qttu", ch[0], Write)
20         n.Watch("src/github.com/pblaszczyk/qttu/...", ch[1], Create)
21         n.Watch("src/github.com/rjeczalik/fs/cmd/...", ch[2], Remove)
22
23         cases := []NCase{
24                 // i=0
25                 {
26                         Event:    write(n.W(), "src/github.com/rjeczalik/fs/fs.go", []byte("XD")),
27                         Receiver: Chans{ch[0]},
28                 },
29                 // TODO(rjeczalik): #62
30                 // i=1
31                 // {
32                 //      Event:    write(n.W(), "src/github.com/pblaszczyk/qttu/README.md", []byte("XD")),
33                 //      Receiver: Chans{ch[0]},
34                 // },
35                 // i=2
36                 {
37                         Event:    write(n.W(), "src/github.com/rjeczalik/fs/cmd/gotree/go.go", []byte("XD")),
38                         Receiver: nil,
39                 },
40                 // i=3
41                 {
42                         Event:    create(n.W(), "src/github.com/pblaszczyk/qttu/src/.main.cc.swp"),
43                         Receiver: Chans{ch[1]},
44                 },
45                 // i=4
46                 {
47                         Event:    create(n.W(), "src/github.com/pblaszczyk/qttu/src/.main.cc.swo"),
48                         Receiver: Chans{ch[1]},
49                 },
50                 // i=5
51                 {
52                         Event:    remove(n.W(), "src/github.com/rjeczalik/fs/cmd/gotree/go.go"),
53                         Receiver: Chans{ch[2]},
54                 },
55         }
56
57         n.ExpectNotifyEvents(cases, ch)
58
59         // ...or using Call structures.
60         stops := [...]Call{
61                 // i=0
62                 {
63                         F: FuncStop,
64                         C: ch[0],
65                 },
66                 // i=1
67                 {
68                         F: FuncStop,
69                         C: ch[1],
70                 },
71         }
72
73         n.Call(stops[:]...)
74
75         cases = []NCase{
76                 // i=0
77                 {
78                         Event:    write(n.W(), "src/github.com/rjeczalik/fs/fs.go", []byte("XD")),
79                         Receiver: nil,
80                 },
81                 // i=1
82                 {
83                         Event:    write(n.W(), "src/github.com/pblaszczyk/qttu/README.md", []byte("XD")),
84                         Receiver: nil,
85                 },
86                 // i=2
87                 {
88                         Event:    create(n.W(), "src/github.com/pblaszczyk/qttu/src/.main.cc.swr"),
89                         Receiver: nil,
90                 },
91                 // i=3
92                 {
93                         Event:    remove(n.W(), "src/github.com/rjeczalik/fs/cmd/gotree/main.go"),
94                         Receiver: Chans{ch[2]},
95                 },
96         }
97
98         n.ExpectNotifyEvents(cases, ch)
99 }
100
101 func TestStop(t *testing.T) {
102         t.Skip("TODO(rjeczalik)")
103 }