Skip to content

Commit

Permalink
Use vtctldclient impl in e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Sep 20, 2023
1 parent e17ef54 commit 2347de6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
10 changes: 5 additions & 5 deletions go/test/endtoend/vreplication/vdiff2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ func testWorkflow(t *testing.T, vc *VitessCluster, tc *testCase, cells []*Cell)
func testCLIErrors(t *testing.T, ksWorkflow, cells string) {
t.Run("Client error handling", func(t *testing.T) {
_, output := performVDiff2Action(t, ksWorkflow, cells, "badcmd", "", true)
require.Contains(t, output, "usage:")
require.Contains(t, output, "Usage:")
_, output = performVDiff2Action(t, ksWorkflow, cells, "create", "invalid_uuid", true)
require.Contains(t, output, "please provide a valid UUID")
require.Contains(t, output, "invalid UUID provided")
_, output = performVDiff2Action(t, ksWorkflow, cells, "resume", "invalid_uuid", true)
require.Contains(t, output, "can only resume a specific vdiff, please provide a valid UUID")
require.Contains(t, output, "invalid UUID provided")
_, output = performVDiff2Action(t, ksWorkflow, cells, "delete", "invalid_uuid", true)
require.Contains(t, output, "can only delete a specific vdiff, please provide a valid UUID")
require.Contains(t, output, "invalid UUID provided")
uuid, _ := performVDiff2Action(t, ksWorkflow, cells, "show", "last", false)
_, output = performVDiff2Action(t, ksWorkflow, cells, "create", uuid, true)
require.Contains(t, output, "already exists")
Expand Down Expand Up @@ -312,7 +312,7 @@ func testResume(t *testing.T, tc *testCase, cells string) {

// confirm that the VDiff was resumed, able to complete, and we compared the
// expected number of rows in total (original run and resume)
uuid, _ = performVDiff2Action(t, ksWorkflow, cells, "resume", uuid, false)
_, _ = performVDiff2Action(t, ksWorkflow, cells, "resume", uuid, false)
info := waitForVDiff2ToComplete(t, ksWorkflow, cells, uuid, ogTime)
require.False(t, info.HasMismatch)
require.Equal(t, expectedRows, info.RowsCompared)
Expand Down
24 changes: 16 additions & 8 deletions go/test/endtoend/vreplication/vdiff_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,27 @@ func doVdiff2(t *testing.T, keyspace, workflow, cells string, want *expectedVDif

func performVDiff2Action(t *testing.T, ksWorkflow, cells, action, actionArg string, expectError bool, extraFlags ...string) (uuid string, output string) {
var err error
args := []string{"VDiff", "--", "--tablet_types=primary", "--source_cell=" + cells, "--format=json"}
targetKeyspace, workflowName, ok := strings.Cut(ksWorkflow, ".")
require.True(t, ok, "invalid keyspace.workflow value: %s", ksWorkflow)

args := []string{"VDiff", "--target-keyspace", targetKeyspace, "--workflow", workflowName, "--format=json", action}
if strings.ToLower(action) == string(vdiff2.CreateAction) {
args = append(args, "--tablet-types=primary", "--source-cells="+cells)
}
if len(extraFlags) > 0 {
args = append(args, extraFlags...)
}
args = append(args, ksWorkflow, action, actionArg)
output, err = vc.VtctlClient.ExecuteCommandWithOutput(args...)
if actionArg != "" {
args = append(args, actionArg)
}
output, err = vc.VtctldClient.ExecuteCommandWithOutput(args...)
log.Infof("vdiff2 output: %+v (err: %+v)", output, err)
if !expectError {
require.Nil(t, err)
uuid = gjson.Get(output, "UUID").String()
if action != "delete" && !(action == "show" && actionArg == "all") { // a UUID is not required
require.NoError(t, err)
require.NotEmpty(t, uuid)
require.NoError(t, err)
ouuid := gjson.Get(output, "UUID").String()
if action == "create" || (action == "show" && actionArg != "all") { // A UUID is returned
require.NotEmpty(t, ouuid)
uuid = ouuid
}
}
return uuid, output
Expand Down

0 comments on commit 2347de6

Please sign in to comment.