etcd/file_system/watcher_test.go
2013-09-07 01:05:11 -04:00

56 lines
714 B
Go

package fileSystem
import (
"testing"
)
func TestWatch(t *testing.T) {
wh := newWatchHub(100)
c, err := wh.watch("/foo", true, 0)
if err != nil {
t.Fatal("%v", err)
}
select {
case <-c:
t.Fatal("should not receive from channel before send the event")
default:
// do nothing
}
e := newEvent(Set, "/foo/bar", 1, 0)
wh.notify(e)
re := <-c
if e != re {
t.Fatal("recv != send")
}
c, _ = wh.watch("/foo", false, 0)
e = newEvent(Set, "/foo/bar", 1, 0)
wh.notify(e)
select {
case <-c:
t.Fatal("should not receive from channel if not recursive")
default:
// do nothing
}
e = newEvent(Set, "/foo", 1, 0)
wh.notify(e)
re = <-c
if e != re {
t.Fatal("recv != send")
}
}