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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
// Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
// +build darwin linux freebsd dragonfly netbsd openbsd windows solaris
package notify
import "testing"
func TestNotifyExample(t *testing.T) {
n := NewNotifyTest(t, "testdata/vfs.txt")
defer n.Close()
ch := NewChans(3)
// Watch-points can be set explicitly via Watch/Stop calls...
n.Watch("src/github.com/rjeczalik/fs", ch[0], Write)
n.Watch("src/github.com/pblaszczyk/qttu", ch[0], Write)
n.Watch("src/github.com/pblaszczyk/qttu/...", ch[1], Create)
n.Watch("src/github.com/rjeczalik/fs/cmd/...", ch[2], Remove)
cases := []NCase{
// i=0
{
Event: write(n.W(), "src/github.com/rjeczalik/fs/fs.go", []byte("XD")),
Receiver: Chans{ch[0]},
},
// TODO(rjeczalik): #62
// i=1
// {
// Event: write(n.W(), "src/github.com/pblaszczyk/qttu/README.md", []byte("XD")),
// Receiver: Chans{ch[0]},
// },
// i=2
{
Event: write(n.W(), "src/github.com/rjeczalik/fs/cmd/gotree/go.go", []byte("XD")),
Receiver: nil,
},
// i=3
{
Event: create(n.W(), "src/github.com/pblaszczyk/qttu/src/.main.cc.swp"),
Receiver: Chans{ch[1]},
},
// i=4
{
Event: create(n.W(), "src/github.com/pblaszczyk/qttu/src/.main.cc.swo"),
Receiver: Chans{ch[1]},
},
// i=5
{
Event: remove(n.W(), "src/github.com/rjeczalik/fs/cmd/gotree/go.go"),
Receiver: Chans{ch[2]},
},
}
n.ExpectNotifyEvents(cases, ch)
// ...or using Call structures.
stops := [...]Call{
// i=0
{
F: FuncStop,
C: ch[0],
},
// i=1
{
F: FuncStop,
C: ch[1],
},
}
n.Call(stops[:]...)
cases = []NCase{
// i=0
{
Event: write(n.W(), "src/github.com/rjeczalik/fs/fs.go", []byte("XD")),
Receiver: nil,
},
// i=1
{
Event: write(n.W(), "src/github.com/pblaszczyk/qttu/README.md", []byte("XD")),
Receiver: nil,
},
// i=2
{
Event: create(n.W(), "src/github.com/pblaszczyk/qttu/src/.main.cc.swr"),
Receiver: nil,
},
// i=3
{
Event: remove(n.W(), "src/github.com/rjeczalik/fs/cmd/gotree/main.go"),
Receiver: Chans{ch[2]},
},
}
n.ExpectNotifyEvents(cases, ch)
}
func TestStop(t *testing.T) {
t.Skip("TODO(rjeczalik)")
}
|