forked from fsnotify/fsevents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsevents_test.go
53 lines (44 loc) · 811 Bytes
/
fsevents_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
49
50
51
52
53
// +build darwin
package fsevents
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
)
func TestBasicExample(t *testing.T) {
path, err := ioutil.TempDir("", "fsexample")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(path)
dev, err := DeviceForPath(path)
if err != nil {
t.Fatal(err)
}
es := &EventStream{
Paths: []string{path},
Latency: 500 * time.Millisecond,
Device: dev,
Flags: FileEvents,
}
es.Start()
wait := make(chan Event)
go func() {
//fmt.Println("test it here")
for msg := range es.Events {
for _, event := range msg {
t.Logf("Event: %#v", event)
wait <- event
es.Stop()
return
}
}
}()
err = ioutil.WriteFile(filepath.Join(path, "example.txt"), []byte("example"), 0700)
if err != nil {
t.Fatal(err)
}
<-wait
}