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

This commit is contained in:
Gyu-Ho Lee 2016-12-05 12:41:26 -08:00
parent e03850c4ac
commit 5dffa38fb2

View File

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