From e86ad02bacf4da4ec90d4eeb70507418819bc7cd Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Wed, 28 Aug 2024 18:42:52 +0530 Subject: [PATCH] feat: create a function to call MoveTables from an external package Signed-off-by: Manan Gupta --- .../endtoend/vreplication/wrappers_test.go | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/go/test/endtoend/vreplication/wrappers_test.go b/go/test/endtoend/vreplication/wrappers_test.go index 96c54b89fe8..baae1462d17 100644 --- a/go/test/endtoend/vreplication/wrappers_test.go +++ b/go/test/endtoend/vreplication/wrappers_test.go @@ -19,9 +19,11 @@ package vreplication import ( "math/rand/v2" "strconv" + "testing" "github.com/stretchr/testify/require" + "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/vt/log" binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" ) @@ -89,6 +91,25 @@ type iMoveTables interface { iWorkflow } +// NewExternalMoveTables is meant to be used outside this package for other test packages to run MoveTables. +func NewExternalMoveTables(t *testing.T, cluster *cluster.LocalProcessCluster, workflowName, targetKeyspace, sourceKeyspace, tables string) *VtctldMoveTables { + return &VtctldMoveTables{ + &moveTablesWorkflow{ + workflowInfo: &workflowInfo{ + vc: &VitessCluster{ + t: t, + VtctlClient: &cluster.VtctlclientProcess, + VtctldClient: &cluster.VtctldClientProcess, + }, + workflowName: workflowName, + targetKeyspace: targetKeyspace, + }, + sourceKeyspace: sourceKeyspace, + tables: tables, + }, + } +} + func newMoveTables(vc *VitessCluster, mt *moveTablesWorkflow, flavor workflowFlavor) iMoveTables { mt.vc = vc var mt2 iMoveTables @@ -203,7 +224,7 @@ func (v VtctldMoveTables) exec(args ...string) { args2 := []string{"MoveTables", "--workflow=" + v.workflowName, "--target-keyspace=" + v.targetKeyspace} args2 = append(args2, args...) var err error - if v.lastOutput, err = vc.VtctldClient.ExecuteCommandWithOutput(args2...); err != nil { + if v.lastOutput, err = v.vc.VtctldClient.ExecuteCommandWithOutput(args2...); err != nil { require.FailNowf(v.vc.t, "failed MoveTables action", "%v: %s", err, v.lastOutput) } } @@ -409,7 +430,7 @@ func (v VtctldReshard) exec(args ...string) { args2 := []string{"Reshard", "--workflow=" + v.workflowName, "--target-keyspace=" + v.targetKeyspace} args2 = append(args2, args...) var err error - if v.lastOutput, err = vc.VtctldClient.ExecuteCommandWithOutput(args2...); err != nil { + if v.lastOutput, err = v.vc.VtctldClient.ExecuteCommandWithOutput(args2...); err != nil { v.vc.t.Fatalf("failed to create Reshard workflow: %v: %s", err, v.lastOutput) } }