Skip to content

Commit

Permalink
e2e: test put command with '--ignore-value' flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuho committed Jan 13, 2017
1 parent e03850c commit 5dffa38
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions e2e/ctl_v3_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestCtlV3PutTimeout(t *testing.T) { testCtl(t, putTest, withDialTimeo
func TestCtlV3PutClientTLSFlagByEnv(t *testing.T) {
testCtl(t, putTest, withCfg(configClientTLS), withFlagByEnv())
}
func TestCtlV3PutIgnoreValue(t *testing.T) { testCtl(t, putTestIgnoreValue) }

func TestCtlV3Get(t *testing.T) { testCtl(t, getTest) }
func TestCtlV3GetNoTLS(t *testing.T) { testCtl(t, getTest, withCfg(configNoTLS)) }
Expand Down Expand Up @@ -62,6 +63,21 @@ func putTest(cx ctlCtx) {
}
}

func putTestIgnoreValue(cx ctlCtx) {
if err := ctlV3Put(cx, "foo", "bar", ""); err != nil {
cx.t.Fatal(err)
}
if err := ctlV3Get(cx, []string{"foo"}, kv{"foo", "bar"}); err != nil {
cx.t.Fatal(err)
}
if err := ctlV3Put(cx, "foo", "", "", "--ignore-value"); err != nil {
cx.t.Fatal(err)
}
if err := ctlV3Get(cx, []string{"foo"}, kv{"foo", "bar"}); err != nil {
cx.t.Fatal(err)
}
}

func getTest(cx ctlCtx) {
var (
kvs = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
Expand Down Expand Up @@ -227,11 +243,24 @@ func delTest(cx ctlCtx) {
}
}

func ctlV3Put(cx ctlCtx, key, value, leaseID string) error {
cmdArgs := append(cx.PrefixArgs(), "put", key, value)
func ctlV3Put(cx ctlCtx, key, value, leaseID string, flags ...string) error {
skipValue := false
for _, f := range flags {
if f == "--ignore-value" {
skipValue = true
break
}
}
cmdArgs := append(cx.PrefixArgs(), "put", key)
if !skipValue {
cmdArgs = append(cmdArgs, value)
}
if leaseID != "" {
cmdArgs = append(cmdArgs, "--lease", leaseID)
}
if len(flags) != 0 {
cmdArgs = append(cmdArgs, flags...)
}
return spawnWithExpect(cmdArgs, "OK")
}

Expand Down

0 comments on commit 5dffa38

Please sign in to comment.