Skip to content

Commit

Permalink
feat: create a function to call MoveTables from an external package
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed Aug 28, 2024
1 parent 773a216 commit e86ad02
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions go/test/endtoend/vreplication/wrappers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit e86ad02

Please sign in to comment.