diff --git a/go/vt/vtctl/workflow/server.go b/go/vt/vtctl/workflow/server.go index ccace56cda3..c3dd8622d91 100644 --- a/go/vt/vtctl/workflow/server.go +++ b/go/vt/vtctl/workflow/server.go @@ -1720,6 +1720,21 @@ func (s *Server) VDiffCreate(ctx context.Context, req *vtctldatapb.VDiffCreateRe tabletTypesStr = discovery.InOrderHint + tabletTypesStr } + // This is a pointer so there's no ZeroValue in the message + // and an older v18 client will not provide it. + if req.MaxDiffDuration == nil { + req.MaxDiffDuration = &vttimepb.Duration{} + } + // The other vttime.Duration vars should not be nil as the + // client should always provide them, but we check anyway to + // be safe. + if req.FilteredReplicationWaitTime == nil { + req.FilteredReplicationWaitTime = &vttimepb.Duration{} + } + if req.WaitUpdateInterval == nil { + req.WaitUpdateInterval = &vttimepb.Duration{} + } + options := &tabletmanagerdatapb.VDiffOptions{ PickerOptions: &tabletmanagerdatapb.VDiffPickerOptions{ TabletTypes: tabletTypesStr, diff --git a/go/vt/vtctl/workflow/server_test.go b/go/vt/vtctl/workflow/server_test.go index 5057f0cd88a..8aaacf53833 100644 --- a/go/vt/vtctl/workflow/server_test.go +++ b/go/vt/vtctl/workflow/server_test.go @@ -27,16 +27,17 @@ import ( "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/mysql/config" - "vitess.io/vitess/go/vt/sqlparser" - "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/test/utils" + "vitess.io/vitess/go/vt/sqlparser" + "vitess.io/vitess/go/vt/topo/memorytopo" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/vttablet/tmclient" binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" querypb "vitess.io/vitess/go/vt/proto/query" topodatapb "vitess.io/vitess/go/vt/proto/topodata" + vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" ) type fakeTMC struct { @@ -167,3 +168,36 @@ func TestCheckReshardingJournalExistsOnTablet(t *testing.T) { }) } } + +// TestVDiffCreate performs some basic tests of the VDiffCreate function +// to ensure that it behaves as expected given a specific request. +func TestVDiffCreate(t *testing.T) { + ctx := context.Background() + ts := memorytopo.NewServer(ctx, "cell") + tmc := &fakeTMC{} + s := NewServer(ts, tmc, collations.MySQL8(), sqlparser.NewTestParser(), config.DefaultMySQLVersion) + + tests := []struct { + name string + req *vtctldatapb.VDiffCreateRequest + wantErr string + }{ + { + name: "no values", + req: &vtctldatapb.VDiffCreateRequest{}, + wantErr: "node doesn't exist: keyspaces/shards", // We did not provide any keyspace or shard + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := s.VDiffCreate(ctx, tt.req) + if tt.wantErr != "" { + require.EqualError(t, err, tt.wantErr) + return + } + require.NoError(t, err) + require.NotNil(t, got) + require.NotEmpty(t, got.UUID) + }) + } +}