瀏覽代碼

Merge pull request #6492 from sinsharat/make-mirror_no_dest_test

etcdctlv3: test case: make-mirror no dest prefix
Gyu-Ho Lee 9 年之前
父節點
當前提交
0604fccfea
共有 1 個文件被更改,包括 55 次插入4 次删除
  1. 55 4
      e2e/ctl_v3_make_mirror_test.go

+ 55 - 4
e2e/ctl_v3_make_mirror_test.go

@@ -20,9 +20,9 @@ import (
 	"time"
 )
 
-func TestCtlV3MakeMirror(t *testing.T) { testCtl(t, makeMirrorTest) }
-
-func TestCtlV3MakeMirrorModifyPrefix(t *testing.T) { testCtl(t, makeMirrorModifyPrefixTest) }
+func TestCtlV3MakeMirror(t *testing.T)                 { testCtl(t, makeMirrorTest) }
+func TestCtlV3MakeMirrorModifyDestPrefix(t *testing.T) { testCtl(t, makeMirrorModifyDestPrefixTest) }
+func TestCtlV3MakeMirrorNoDestPrefix(t *testing.T)     { testCtl(t, makeMirrorNoDestPrefixTest) }
 
 func makeMirrorTest(cx ctlCtx) {
 	// set up another cluster to mirror with
@@ -73,7 +73,7 @@ func makeMirrorTest(cx ctlCtx) {
 	}
 }
 
-func makeMirrorModifyPrefixTest(cx ctlCtx) {
+func makeMirrorModifyDestPrefixTest(cx ctlCtx) {
 	// set up another cluster to mirror with
 	mirrorcfg := configAutoTLS
 	mirrorcfg.clusterSize = 1
@@ -123,3 +123,54 @@ func makeMirrorModifyPrefixTest(cx ctlCtx) {
 		cx.t.Fatal(err)
 	}
 }
+
+func makeMirrorNoDestPrefixTest(cx ctlCtx) {
+	// set up another cluster to mirror with
+	mirrorcfg := configAutoTLS
+	mirrorcfg.clusterSize = 1
+	mirrorcfg.basePort = 10000
+	mirrorctx := ctlCtx{
+		t:           cx.t,
+		cfg:         mirrorcfg,
+		dialTimeout: 7 * time.Second,
+	}
+
+	mirrorepc, err := newEtcdProcessCluster(&mirrorctx.cfg)
+	if err != nil {
+		cx.t.Fatalf("could not start etcd process cluster (%v)", err)
+	}
+	mirrorctx.epc = mirrorepc
+
+	defer func() {
+		if err = mirrorctx.epc.Close(); err != nil {
+			cx.t.Fatalf("error closing etcd processes (%v)", err)
+		}
+	}()
+
+	cmdArgs := append(cx.PrefixArgs(), "make-mirror", "--prefix", "o_", "--no-dest-prefix", fmt.Sprintf("localhost:%d", mirrorcfg.basePort))
+	proc, err := spawnCmd(cmdArgs)
+	if err != nil {
+		cx.t.Fatal(err)
+	}
+	defer func() {
+		err = proc.Stop()
+		if err != nil {
+			cx.t.Fatal(err)
+		}
+	}()
+
+	var kvs = []kv{{"o_key1", "val1"}, {"o_key2", "val2"}, {"o_key3", "val3"}}
+	for i := range kvs {
+		if err = ctlV3Put(cx, kvs[i].key, kvs[i].val, ""); err != nil {
+			cx.t.Fatal(err)
+		}
+	}
+	if err = ctlV3Get(cx, []string{"o_", "--prefix"}, kvs...); err != nil {
+		cx.t.Fatal(err)
+	}
+
+	var kvs2 = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
+	if err = ctlV3Watch(mirrorctx, []string{"key", "--rev", "1", "--prefix"}, kvs2...); err != nil {
+		cx.t.Fatal(err)
+	}
+}