Skip to content

Commit

Permalink
[grpcvtctldclient] Fix vtctld server initialization in grpcvtctldclie…
Browse files Browse the repository at this point in the history
…nt/client_test.go (vitessio#9906)

* Fix vtctld server initialization grpcvtctldclient/client_test.go

Signed-off-by: Sara Bee <855595+doeg@users.noreply.github.com>

* 🔪 duplicate import

Signed-off-by: Sara Bee <855595+doeg@users.noreply.github.com>
  • Loading branch information
doeg authored Mar 18, 2022
1 parent 6e5572b commit fdf848f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions go/vt/vtctl/grpcvtctldclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,24 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/utils"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/memorytopo"
"vitess.io/vitess/go/vt/vtctl/grpcvtctldserver"
"vitess.io/vitess/go/vt/vtctl/grpcvtctldserver/testutil"
"vitess.io/vitess/go/vt/vtctl/vtctldclient"

topodatapb "vitess.io/vitess/go/vt/proto/topodata"
"vitess.io/vitess/go/vt/proto/vtctldata"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
vtctlservicepb "vitess.io/vitess/go/vt/proto/vtctlservice"
)

func TestFindAllShardsInKeyspace(t *testing.T) {
ctx := context.Background()
ts := memorytopo.NewServer("cell1")
vtctld := grpcvtctldserver.NewVtctldServer(ts)
vtctld := testutil.NewVtctldServerWithTabletManagerClient(t, ts, nil, func(ts *topo.Server) vtctlservicepb.VtctldServer {
return grpcvtctldserver.NewVtctldServer(ts)
})

testutil.WithTestServer(t, vtctld, func(t *testing.T, client vtctldclient.VtctldClient) {
ks := &vtctldatapb.Keyspace{
Expand Down Expand Up @@ -67,7 +71,7 @@ func TestFindAllShardsInKeyspace(t *testing.T) {
},
}

assert.Equal(t, expected, resp.Shards)
utils.MustMatch(t, expected, resp.Shards)

client.Close()
_, err = client.FindAllShardsInKeyspace(ctx, &vtctldatapb.FindAllShardsInKeyspaceRequest{Keyspace: ks.Name})
Expand All @@ -79,11 +83,13 @@ func TestGetKeyspace(t *testing.T) {
ctx := context.Background()

ts := memorytopo.NewServer("cell1")
vtctld := grpcvtctldserver.NewVtctldServer(ts)
vtctld := testutil.NewVtctldServerWithTabletManagerClient(t, ts, nil, func(ts *topo.Server) vtctlservicepb.VtctldServer {
return grpcvtctldserver.NewVtctldServer(ts)
})

testutil.WithTestServer(t, vtctld, func(t *testing.T, client vtctldclient.VtctldClient) {
expected := &vtctldatapb.GetKeyspaceResponse{
Keyspace: &vtctldata.Keyspace{
Keyspace: &vtctldatapb.Keyspace{
Name: "testkeyspace",
Keyspace: &topodatapb.Keyspace{
ShardingColumnName: "col1",
Expand All @@ -94,7 +100,7 @@ func TestGetKeyspace(t *testing.T) {

resp, err := client.GetKeyspace(ctx, &vtctldatapb.GetKeyspaceRequest{Keyspace: expected.Keyspace.Name})
assert.NoError(t, err)
assert.Equal(t, expected, resp)
utils.MustMatch(t, expected, resp)

client.Close()
_, err = client.GetKeyspace(ctx, &vtctldatapb.GetKeyspaceRequest{})
Expand All @@ -106,7 +112,9 @@ func TestGetKeyspaces(t *testing.T) {
ctx := context.Background()

ts := memorytopo.NewServer("cell1")
vtctld := grpcvtctldserver.NewVtctldServer(ts)
vtctld := testutil.NewVtctldServerWithTabletManagerClient(t, ts, nil, func(ts *topo.Server) vtctlservicepb.VtctldServer {
return grpcvtctldserver.NewVtctldServer(ts)
})

testutil.WithTestServer(t, vtctld, func(t *testing.T, client vtctldclient.VtctldClient) {
resp, err := client.GetKeyspaces(ctx, &vtctldatapb.GetKeyspacesRequest{})
Expand All @@ -121,7 +129,7 @@ func TestGetKeyspaces(t *testing.T) {

resp, err = client.GetKeyspaces(ctx, &vtctldatapb.GetKeyspacesRequest{})
assert.NoError(t, err)
assert.Equal(t, []*vtctldatapb.Keyspace{expected}, resp.Keyspaces)
utils.MustMatch(t, []*vtctldatapb.Keyspace{expected}, resp.Keyspaces)

client.Close()
_, err = client.GetKeyspaces(ctx, &vtctldatapb.GetKeyspacesRequest{})
Expand Down

0 comments on commit fdf848f

Please sign in to comment.