Skip to content

Commit

Permalink
Rewrite legacy vtctl GetSchema test to use packaged fake tmclient
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Mason <[email protected]>
  • Loading branch information
ajm188 committed Jan 22, 2021
1 parent 77fbde7 commit 6e261be
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions go/vt/vtctl/endtoend/get_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package endtoend

import (
"context"
"fmt"
"testing"

"github.com/google/uuid"
Expand All @@ -14,7 +13,7 @@ import (
"vitess.io/vitess/go/vt/topo/memorytopo"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/vtctl"
"vitess.io/vitess/go/vt/vttablet/faketmclient"
"vitess.io/vitess/go/vt/vtctl/grpcvtctldserver/testutil"
"vitess.io/vitess/go/vt/vttablet/tmclient"
"vitess.io/vitess/go/vt/wrangler"

Expand All @@ -23,29 +22,6 @@ import (
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
)

type fakeTabletManagerClient struct {
tmclient.TabletManagerClient
schemas map[string]*tabletmanagerdatapb.SchemaDefinition
}

func newTMClient() *fakeTabletManagerClient {
return &fakeTabletManagerClient{
TabletManagerClient: faketmclient.NewFakeTabletManagerClient(),
schemas: map[string]*tabletmanagerdatapb.SchemaDefinition{},
}
}

func (c *fakeTabletManagerClient) GetSchema(ctx context.Context, tablet *topodatapb.Tablet, tablets []string, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error) {
key := topoproto.TabletAliasString(tablet.Alias)

schema, ok := c.schemas[key]
if !ok {
return nil, fmt.Errorf("no schemas for %s", key)
}

return schema, nil
}

func TestGetSchema(t *testing.T) {
ctx := context.Background()

Expand Down Expand Up @@ -162,8 +138,10 @@ func TestGetSchema(t *testing.T) {
},
}

tmc := newTMClient()
tmc.schemas[topoproto.TabletAliasString(tablet.Alias)] = sd
tmc := testutil.TabletManagerClient
tmc.Schemas[topoproto.TabletAliasString(tablet.Alias)] = sd

*tmclient.TabletManagerProtocol = testutil.TabletManagerClientProtocol

logger := logutil.NewMemoryLogger()

Expand Down

0 comments on commit 6e261be

Please sign in to comment.