From 17496267be427e5934a816bdd73e4cbaefa3656c Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Thu, 1 Jun 2017 18:15:37 -0700 Subject: [PATCH] clientv3/integration: test compare on range --- clientv3/integration/txn_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/clientv3/integration/txn_test.go b/clientv3/integration/txn_test.go index 064be976dd9f..cbfc59e6716a 100644 --- a/clientv3/integration/txn_test.go +++ b/clientv3/integration/txn_test.go @@ -152,3 +152,30 @@ func TestTxnSuccess(t *testing.T) { t.Fatalf("unexpected Get response %v", resp) } } + +func TestTxnCompareRange(t *testing.T) { + defer testutil.AfterTest(t) + + clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + kv := clus.Client(0) + fooResp, err := kv.Put(context.TODO(), "foo/", "bar") + if err != nil { + t.Fatal(err) + } + if _, err = kv.Put(context.TODO(), "foo/a", "baz"); err != nil { + t.Fatal(err) + } + tresp, terr := kv.Txn(context.TODO()).If( + clientv3.Compare( + clientv3.CreateRevision("foo/"), "=", fooResp.Header.Revision). + WithPrefix(), + ).Commit() + if terr != nil { + t.Fatal(terr) + } + if tresp.Succeeded { + t.Fatal("expected prefix compare to false, got compares as true") + } +}