Browse Source

clientv3: support watcher ranges

Anthony Romano 9 years ago
parent
commit
eb327c690b
2 changed files with 14 additions and 4 deletions
  1. 14 0
      clientv3/integration/watch_test.go
  2. 0 4
      clientv3/op.go

+ 14 - 0
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.
 // TestWatchReconnRequest tests the send failure path when requesting a watcher.
 func TestWatchReconnRequest(t *testing.T) {
 func TestWatchReconnRequest(t *testing.T) {
 	runWatchTest(t, testWatchReconnRequest)
 	runWatchTest(t, testWatchReconnRequest)

+ 0 - 4
clientv3/op.go

@@ -15,8 +15,6 @@
 package clientv3
 package clientv3
 
 
 import (
 import (
-	"reflect"
-
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
 	"github.com/coreos/etcd/lease"
 	"github.com/coreos/etcd/lease"
 )
 )
@@ -119,8 +117,6 @@ func opWatch(key string, opts ...OpOption) Op {
 	ret := Op{t: tRange, key: []byte(key)}
 	ret := Op{t: tRange, key: []byte(key)}
 	ret.applyOpts(opts)
 	ret.applyOpts(opts)
 	switch {
 	switch {
-	case ret.end != nil && !reflect.DeepEqual(ret.end, getPrefix(ret.key)):
-		panic("only supports single keys or prefixes")
 	case ret.leaseID != 0:
 	case ret.leaseID != 0:
 		panic("unexpected lease in watch")
 		panic("unexpected lease in watch")
 	case ret.limit != 0:
 	case ret.limit != 0: