Browse Source

e2e: test watch exec in v3 etcdctl

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
Gyu-Ho Lee 8 years ago
parent
commit
25222c22d9
3 changed files with 50 additions and 14 deletions
  1. 5 5
      e2e/ctl_v3_auth_test.go
  2. 5 4
      e2e/ctl_v3_make_mirror_test.go
  3. 40 5
      e2e/ctl_v3_watch_test.go

+ 5 - 5
e2e/ctl_v3_auth_test.go

@@ -780,32 +780,32 @@ func authTestWatch(cx ctlCtx) {
 		puts []kv
 		puts []kv
 		args []string
 		args []string
 
 
-		wkv  []kv
+		wkv  []kvExec
 		want bool
 		want bool
 	}{
 	}{
 		{ // watch 1 key, should be successful
 		{ // watch 1 key, should be successful
 			[]kv{{"key", "value"}},
 			[]kv{{"key", "value"}},
 			[]string{"key", "--rev", "1"},
 			[]string{"key", "--rev", "1"},
-			[]kv{{"key", "value"}},
+			[]kvExec{{key: "key", val: "value"}},
 			true,
 			true,
 		},
 		},
 		{ // watch 3 keys by range, should be successful
 		{ // watch 3 keys by range, should be successful
 			[]kv{{"key1", "val1"}, {"key3", "val3"}, {"key2", "val2"}},
 			[]kv{{"key1", "val1"}, {"key3", "val3"}, {"key2", "val2"}},
 			[]string{"key", "key3", "--rev", "1"},
 			[]string{"key", "key3", "--rev", "1"},
-			[]kv{{"key1", "val1"}, {"key2", "val2"}},
+			[]kvExec{{key: "key1", val: "val1"}, {key: "key2", val: "val2"}},
 			true,
 			true,
 		},
 		},
 
 
 		{ // watch 1 key, should not be successful
 		{ // watch 1 key, should not be successful
 			[]kv{},
 			[]kv{},
 			[]string{"key5", "--rev", "1"},
 			[]string{"key5", "--rev", "1"},
-			[]kv{},
+			[]kvExec{},
 			false,
 			false,
 		},
 		},
 		{ // watch 3 keys by range, should not be successful
 		{ // watch 3 keys by range, should not be successful
 			[]kv{},
 			[]kv{},
 			[]string{"key", "key6", "--rev", "1"},
 			[]string{"key", "key6", "--rev", "1"},
-			[]kv{},
+			[]kvExec{},
 			false,
 			false,
 		},
 		},
 	}
 	}

+ 5 - 4
e2e/ctl_v3_make_mirror_test.go

@@ -28,16 +28,17 @@ func makeMirrorTest(cx ctlCtx) {
 	var (
 	var (
 		flags  = []string{}
 		flags  = []string{}
 		kvs    = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
 		kvs    = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
+		kvs2   = []kvExec{{key: "key1", val: "val1"}, {key: "key2", val: "val2"}, {key: "key3", val: "val3"}}
 		prefix = "key"
 		prefix = "key"
 	)
 	)
-	testMirrorCommand(cx, flags, kvs, kvs, prefix, prefix)
+	testMirrorCommand(cx, flags, kvs, kvs2, prefix, prefix)
 }
 }
 
 
 func makeMirrorModifyDestPrefixTest(cx ctlCtx) {
 func makeMirrorModifyDestPrefixTest(cx ctlCtx) {
 	var (
 	var (
 		flags      = []string{"--prefix", "o_", "--dest-prefix", "d_"}
 		flags      = []string{"--prefix", "o_", "--dest-prefix", "d_"}
 		kvs        = []kv{{"o_key1", "val1"}, {"o_key2", "val2"}, {"o_key3", "val3"}}
 		kvs        = []kv{{"o_key1", "val1"}, {"o_key2", "val2"}, {"o_key3", "val3"}}
-		kvs2       = []kv{{"d_key1", "val1"}, {"d_key2", "val2"}, {"d_key3", "val3"}}
+		kvs2       = []kvExec{{key: "d_key1", val: "val1"}, {key: "d_key2", val: "val2"}, {key: "d_key3", val: "val3"}}
 		srcprefix  = "o_"
 		srcprefix  = "o_"
 		destprefix = "d_"
 		destprefix = "d_"
 	)
 	)
@@ -48,7 +49,7 @@ func makeMirrorNoDestPrefixTest(cx ctlCtx) {
 	var (
 	var (
 		flags      = []string{"--prefix", "o_", "--no-dest-prefix"}
 		flags      = []string{"--prefix", "o_", "--no-dest-prefix"}
 		kvs        = []kv{{"o_key1", "val1"}, {"o_key2", "val2"}, {"o_key3", "val3"}}
 		kvs        = []kv{{"o_key1", "val1"}, {"o_key2", "val2"}, {"o_key3", "val3"}}
-		kvs2       = []kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}}
+		kvs2       = []kvExec{{key: "key1", val: "val1"}, {key: "key2", val: "val2"}, {key: "key3", val: "val3"}}
 		srcprefix  = "o_"
 		srcprefix  = "o_"
 		destprefix = "key"
 		destprefix = "key"
 	)
 	)
@@ -56,7 +57,7 @@ func makeMirrorNoDestPrefixTest(cx ctlCtx) {
 	testMirrorCommand(cx, flags, kvs, kvs2, srcprefix, destprefix)
 	testMirrorCommand(cx, flags, kvs, kvs2, srcprefix, destprefix)
 }
 }
 
 
-func testMirrorCommand(cx ctlCtx, flags []string, sourcekvs, destkvs []kv, srcprefix, destprefix string) {
+func testMirrorCommand(cx ctlCtx, flags []string, sourcekvs []kv, destkvs []kvExec, srcprefix, destprefix string) {
 	// set up another cluster to mirror with
 	// set up another cluster to mirror with
 	mirrorcfg := configAutoTLS
 	mirrorcfg := configAutoTLS
 	mirrorcfg.clusterSize = 1
 	mirrorcfg.clusterSize = 1

+ 40 - 5
e2e/ctl_v3_watch_test.go

@@ -38,32 +38,62 @@ func TestCtlV3WatchInteractivePeerTLS(t *testing.T) {
 	testCtl(t, watchTest, withInteractive(), withCfg(configPeerTLS))
 	testCtl(t, watchTest, withInteractive(), withCfg(configPeerTLS))
 }
 }
 
 
+type kvExec struct {
+	key, val   string
+	execOutput string
+}
+
 func watchTest(cx ctlCtx) {
 func watchTest(cx ctlCtx) {
 	tests := []struct {
 	tests := []struct {
 		puts []kv
 		puts []kv
 		args []string
 		args []string
 
 
-		wkv []kv
+		wkv []kvExec
 	}{
 	}{
 		{ // watch 1 key
 		{ // watch 1 key
 			[]kv{{"sample", "value"}},
 			[]kv{{"sample", "value"}},
 			[]string{"sample", "--rev", "1"},
 			[]string{"sample", "--rev", "1"},
+			[]kvExec{{key: "sample", val: "value"}},
+		},
+		{ // watch 1 key with "echo watch event received"
+			[]kv{{"sample", "value"}},
+			[]string{"sample", "--rev", "1", "--", "echo", "watch event received"},
+			[]kvExec{{key: "sample", val: "value", execOutput: "watch event received"}},
+		},
+		{ // watch 1 key with "echo watch event received"
+			[]kv{{"sample", "value"}},
+			[]string{"--rev", "1", "sample", "--", "echo", "watch event received"},
+			[]kvExec{{key: "sample", val: "value", execOutput: "watch event received"}},
+		},
+		{ // watch 1 key with "echo \"Hello World!\""
 			[]kv{{"sample", "value"}},
 			[]kv{{"sample", "value"}},
+			[]string{"--rev", "1", "sample", "--", "echo", "\"Hello World!\""},
+			[]kvExec{{key: "sample", val: "value", execOutput: "Hello World!"}},
+		},
+		{ // watch 1 key with "echo watch event received"
+			[]kv{{"sample", "value"}},
+			[]string{"sample", "samplx", "--rev", "1", "--", "echo", "watch event received"},
+			[]kvExec{{key: "sample", val: "value", execOutput: "watch event received"}},
+		},
+		{ // watch 1 key with "echo watch event received"
+			[]kv{{"sample", "value"}},
+			[]string{"sample", "--rev", "1", "samplx", "--", "echo", "watch event received"},
+			[]kvExec{{key: "sample", val: "value", execOutput: "watch event received"}},
 		},
 		},
 		{ // watch 3 keys by prefix
 		{ // watch 3 keys by prefix
 			[]kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}},
 			[]kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}},
 			[]string{"key", "--rev", "1", "--prefix"},
 			[]string{"key", "--rev", "1", "--prefix"},
-			[]kv{{"key1", "val1"}, {"key2", "val2"}, {"key3", "val3"}},
+			[]kvExec{{key: "key1", val: "val1"}, {key: "key2", val: "val2"}, {key: "key3", val: "val3"}},
 		},
 		},
 		{ // watch by revision
 		{ // watch by revision
 			[]kv{{"etcd", "revision_1"}, {"etcd", "revision_2"}, {"etcd", "revision_3"}},
 			[]kv{{"etcd", "revision_1"}, {"etcd", "revision_2"}, {"etcd", "revision_3"}},
 			[]string{"etcd", "--rev", "2"},
 			[]string{"etcd", "--rev", "2"},
-			[]kv{{"etcd", "revision_2"}, {"etcd", "revision_3"}},
+			[]kvExec{{key: "etcd", val: "revision_2"}, {key: "etcd", val: "revision_3"}},
 		},
 		},
 		{ // watch 3 keys by range
 		{ // watch 3 keys by range
 			[]kv{{"key1", "val1"}, {"key3", "val3"}, {"key2", "val2"}},
 			[]kv{{"key1", "val1"}, {"key3", "val3"}, {"key2", "val2"}},
 			[]string{"key", "key3", "--rev", "1"},
 			[]string{"key", "key3", "--rev", "1"},
-			[]kv{{"key1", "val1"}, {"key2", "val2"}},
+			[]kvExec{{key: "key1", val: "val1"}, {key: "key2", val: "val2"}},
 		},
 		},
 	}
 	}
 
 
@@ -97,7 +127,7 @@ func setupWatchArgs(cx ctlCtx, args []string) []string {
 	return cmdArgs
 	return cmdArgs
 }
 }
 
 
-func ctlV3Watch(cx ctlCtx, args []string, kvs ...kv) error {
+func ctlV3Watch(cx ctlCtx, args []string, kvs ...kvExec) error {
 	cmdArgs := setupWatchArgs(cx, args)
 	cmdArgs := setupWatchArgs(cx, args)
 
 
 	proc, err := spawnCmd(cmdArgs)
 	proc, err := spawnCmd(cmdArgs)
@@ -119,6 +149,11 @@ func ctlV3Watch(cx ctlCtx, args []string, kvs ...kv) error {
 		if _, err = proc.Expect(elem.val); err != nil {
 		if _, err = proc.Expect(elem.val); err != nil {
 			return err
 			return err
 		}
 		}
+		if elem.execOutput != "" {
+			if _, err = proc.Expect(elem.execOutput); err != nil {
+				return err
+			}
+		}
 	}
 	}
 	return proc.Stop()
 	return proc.Stop()
 }
 }