test add watcher prefix test

release-0.4
Xiang Li 2013-12-01 17:35:22 -05:00
parent 5097a2adee
commit 78e382cb6b
2 changed files with 27 additions and 1 deletions

View File

@ -66,7 +66,13 @@ func (eh *EventHistory) scan(key string, recursive bool, index uint64) (*Event,
ok := (e.Key == key)
if recursive {
ok = ok || strings.HasPrefix(e.Key, path.Join(key, "/"))
// add tailing slash
key := path.Clean(key)
if key[len(key)-1] != '/' {
key = key + "/"
}
ok = ok || strings.HasPrefix(e.Key, key)
}
if ok && index <= e.Index() { // make sure we bypass the smaller one

View File

@ -68,4 +68,24 @@ func TestWatcher(t *testing.T) {
t.Fatal("recv != send")
}
// ensure we are doing exact matching rather than prefix matching
c, _ = wh.watch("/fo", true, 1)
select {
case re = <-c:
t.Fatal("should not receive from channel:", re)
default:
// do nothing
}
e = newEvent(Create, "/fo/bar", 3)
wh.notify(e)
re = <-c
if e != re {
t.Fatal("recv != send")
}
}