Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed Sep 22, 2024
1 parent 0367d05 commit 2b91279
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions go/vt/vtctl/workflow/materializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ func (mz *materializer) deploySchema() error {
for _, ts := range mz.ms.TableSettings {
if td := hasTargetTable[ts.TargetTable]; td != nil {
// Table already exists. Let's be sure that it doesn't already have data.
// We exclude multi-tenant migrations as the target tables are expected
// to frequently have data from previously migrated tenants.
// We exclude multi-tenant migrations from this check as the target tables
// are expected to frequently have data from previously migrated tenants.
if !mz.IsMultiTenantMigration() && td.RowCount > 0 {
return vterrors.Errorf(vtrpcpb.Code_FAILED_PRECONDITION,
"target table %s exists in the %s keyspace and is not empty", td.Name, target.Keyspace())
Expand Down
8 changes: 5 additions & 3 deletions go/vt/vtctl/workflow/materializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,13 +1175,16 @@ func TestCreateLookupVindexCreateDDL(t *testing.T) {
setStartingVschema()
}()
}
outms, _, _, _, err := env.ws.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, tcase.specs, false)
outms, _, _, cancelFunc, err := env.ws.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, tcase.specs, false)
if tcase.err != "" {
require.Error(t, err)
require.Contains(t, err.Error(), tcase.err, "prepareCreateLookup(%s) err: %v, does not contain %v", tcase.description, err, tcase.err)
return
}
require.NoError(t, err)
// All of these test cases create a table and thus change the target
// vschema.
require.NotNil(t, cancelFunc)
want := strings.Split(tcase.out, "\n")
got := strings.Split(outms.TableSettings[0].CreateDdl, "\n")
require.Equal(t, want, got, tcase.description)
Expand Down Expand Up @@ -1655,15 +1658,14 @@ func TestCreateLookupVindexTargetVSchema(t *testing.T) {
t.Fatal(err)
}

_, _, got, cancelFunc, err := env.ws.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, specs, false)
_, _, got, _, err := env.ws.prepareCreateLookup(ctx, "workflow", ms.SourceKeyspace, specs, false)
if tcase.err != "" {
if err == nil || !strings.Contains(err.Error(), tcase.err) {
t.Errorf("prepareCreateLookup(%s) err: %v, must contain %v", tcase.description, err, tcase.err)
}
continue
}
require.NoError(t, err)
require.NotNil(t, cancelFunc)
utils.MustMatch(t, tcase.out, got, tcase.description)
}
}
Expand Down

0 comments on commit 2b91279

Please sign in to comment.