From 3594ab94cfefa7488993ac14e7b410ee63b25d3d Mon Sep 17 00:00:00 2001 From: tangcong Date: Fri, 10 Apr 2020 00:09:46 +0800 Subject: [PATCH] e2e: add getCountOnlyTest testcase --- tests/e2e/ctl_v3_kv_test.go | 45 ++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/tests/e2e/ctl_v3_kv_test.go b/tests/e2e/ctl_v3_kv_test.go index e0e3c8c1fdc..3b705c618ea 100644 --- a/tests/e2e/ctl_v3_kv_test.go +++ b/tests/e2e/ctl_v3_kv_test.go @@ -41,9 +41,10 @@ func TestCtlV3GetPeerTLS(t *testing.T) { testCtl(t, getTest, withCfg(confi func TestCtlV3GetTimeout(t *testing.T) { testCtl(t, getTest, withDialTimeout(0)) } func TestCtlV3GetQuorum(t *testing.T) { testCtl(t, getTest, withQuorum()) } -func TestCtlV3GetFormat(t *testing.T) { testCtl(t, getFormatTest) } -func TestCtlV3GetRev(t *testing.T) { testCtl(t, getRevTest) } -func TestCtlV3GetKeysOnly(t *testing.T) { testCtl(t, getKeysOnlyTest) } +func TestCtlV3GetFormat(t *testing.T) { testCtl(t, getFormatTest) } +func TestCtlV3GetRev(t *testing.T) { testCtl(t, getRevTest) } +func TestCtlV3GetKeysOnly(t *testing.T) { testCtl(t, getKeysOnlyTest) } +func TestCtlV3GetCountOnly(t *testing.T) { testCtl(t, getCountOnlyTest) } func TestCtlV3Del(t *testing.T) { testCtl(t, delTest) } func TestCtlV3DelNoTLS(t *testing.T) { testCtl(t, delTest, withCfg(configNoTLS)) } @@ -235,6 +236,44 @@ func getKeysOnlyTest(cx ctlCtx) { } } +func getCountOnlyTest(cx ctlCtx) { + cmdArgs := append(cx.PrefixArgs(), []string{"get", "--count-only", "key", "--prefix", "--write-out=fields"}...) + if err := spawnWithExpects(cmdArgs, "\"Count\" : 0"); err != nil { + cx.t.Fatal(err) + } + if err := ctlV3Put(cx, "key", "val", ""); err != nil { + cx.t.Fatal(err) + } + cmdArgs = append(cx.PrefixArgs(), []string{"get", "--count-only", "key", "--prefix", "--write-out=fields"}...) + if err := spawnWithExpects(cmdArgs, "\"Count\" : 1"); err != nil { + cx.t.Fatal(err) + } + if err := ctlV3Put(cx, "key1", "val", ""); err != nil { + cx.t.Fatal(err) + } + if err := ctlV3Put(cx, "key1", "val", ""); err != nil { + cx.t.Fatal(err) + } + cmdArgs = append(cx.PrefixArgs(), []string{"get", "--count-only", "key", "--prefix", "--write-out=fields"}...) + if err := spawnWithExpects(cmdArgs, "\"Count\" : 2"); err != nil { + cx.t.Fatal(err) + } + if err := ctlV3Put(cx, "key2", "val", ""); err != nil { + cx.t.Fatal(err) + } + cmdArgs = append(cx.PrefixArgs(), []string{"get", "--count-only", "key", "--prefix", "--write-out=fields"}...) + if err := spawnWithExpects(cmdArgs, "\"Count\" : 3"); err != nil { + cx.t.Fatal(err) + } + expected := []string{ + "\"Count\" : 3", + } + cmdArgs = append(cx.PrefixArgs(), []string{"get", "--count-only", "key3", "--prefix", "--write-out=fields"}...) + if err := spawnWithExpects(cmdArgs, expected...); err == nil { + cx.t.Fatal(err) + } +} + func delTest(cx ctlCtx) { tests := []struct { puts []kv