Browse Source

e2e: test put command with '--ignore-value' flag

Gyu-Ho Lee 9 years ago
parent
commit
5dffa38fb2
1 changed files with 31 additions and 2 deletions
  1. 31 2
      e2e/ctl_v3_kv_test.go

+ 31 - 2
e2e/ctl_v3_kv_test.go

@@ -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)) }
@@ -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"}}
@@ -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")
 }