From 78e382cb6b687c5de1e0d0f7c090da86f904a0d3 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sun, 1 Dec 2013 17:35:22 -0500 Subject: [PATCH] test add watcher prefix test --- store/event_history.go | 8 +++++++- store/watcher_test.go | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/store/event_history.go b/store/event_history.go index d61d54d60..8ca9e8f50 100644 --- a/store/event_history.go +++ b/store/event_history.go @@ -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 diff --git a/store/watcher_test.go b/store/watcher_test.go index 386fec440..3afd44c75 100644 --- a/store/watcher_test.go +++ b/store/watcher_test.go @@ -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") + } + }