From eb327c690bba0b0874ab0ddad01bda41da955cbb Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Sun, 28 Feb 2016 23:11:17 -0800 Subject: [PATCH] clientv3: support watcher ranges --- clientv3/integration/watch_test.go | 14 ++++++++++++++ clientv3/op.go | 4 ---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/clientv3/integration/watch_test.go b/clientv3/integration/watch_test.go index 0aac17255..32a6b6896 100644 --- a/clientv3/integration/watch_test.go +++ b/clientv3/integration/watch_test.go @@ -157,6 +157,20 @@ func testWatchMultiWatcher(t *testing.T, wctx *watchctx) { } } +// TestWatchRange tests watcher creates ranges +func TestWatchRange(t *testing.T) { + runWatchTest(t, testWatchReconnInit) +} + +func testWatchRange(t *testing.T, wctx *watchctx) { + if wctx.ch = wctx.w.Watch(context.TODO(), "a", clientv3.WithRange("c")); wctx.ch == nil { + t.Fatalf("expected non-nil channel") + } + putAndWatch(t, wctx, "a", "a") + putAndWatch(t, wctx, "b", "b") + putAndWatch(t, wctx, "bar", "bar") +} + // TestWatchReconnRequest tests the send failure path when requesting a watcher. func TestWatchReconnRequest(t *testing.T) { runWatchTest(t, testWatchReconnRequest) diff --git a/clientv3/op.go b/clientv3/op.go index 99830eb46..49071b523 100644 --- a/clientv3/op.go +++ b/clientv3/op.go @@ -15,8 +15,6 @@ package clientv3 import ( - "reflect" - pb "github.com/coreos/etcd/etcdserver/etcdserverpb" "github.com/coreos/etcd/lease" ) @@ -119,8 +117,6 @@ func opWatch(key string, opts ...OpOption) Op { ret := Op{t: tRange, key: []byte(key)} ret.applyOpts(opts) switch { - case ret.end != nil && !reflect.DeepEqual(ret.end, getPrefix(ret.key)): - panic("only supports single keys or prefixes") case ret.leaseID != 0: panic("unexpected lease in watch") case ret.limit != 0: