mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
test add watcher prefix test
This commit is contained in:
parent
5097a2adee
commit
78e382cb6b
@ -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
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user