Skip to content

Commit

Permalink
tests passing
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Charis <alex.charis@shopify.com>
  • Loading branch information
Alex Charis committed Jun 4, 2021
1 parent 2b4ab4c commit 785c3b6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion go/vt/vtctl/grpcvtctldserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *VtctldServer) ApplyVSchema(ctx context.Context, req *vtctldatapb.ApplyV
vs = req.VSchema
}

if req.DryRun {
if req.DryRun { // we return what was passed in and parsed, rather than current
return &vtctldatapb.ApplyVSchemaResponse{VSchema: vs}, nil
}

Expand Down
52 changes: 38 additions & 14 deletions go/vt/vtctl/grpcvtctldserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,7 @@ func TestApplyVSchema(t *testing.T) {
},
exp: &vtctldatapb.ApplyVSchemaResponse{
VSchema: &vschemapb.Keyspace{
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"v1": {
Type: "hash",
},
},
Sharded: false,
},
},
shouldErr: false,
Expand All @@ -415,17 +410,33 @@ func TestApplyVSchema(t *testing.T) {
},
})

err := ts.SaveVSchema(ctx, tt.req.Keyspace, &vschemapb.Keyspace{
origVSchema := &vschemapb.Keyspace{
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"v1": {
Type: "hash",
},
},
})
}
err := ts.SaveVSchema(ctx, tt.req.Keyspace, origVSchema)
require.NoError(t, err)

origSrvVSchema, err := vtctld.GetSrvVSchema(ctx, &vtctldatapb.GetSrvVSchemaRequest{Cell: "zone1"})
origSrvVSchema := &vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"testkeyspace": {
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"v1": {
Type: "hash",
},
},
},
},
RoutingRules: &vschemapb.RoutingRules{
Rules: []*vschemapb.RoutingRule{},
},
}
err = ts.UpdateSrvVSchema(ctx, "zone1", origSrvVSchema)
require.NoError(t, err)

res, err := vtctld.ApplyVSchema(ctx, tt.req)
Expand All @@ -440,13 +451,26 @@ func TestApplyVSchema(t *testing.T) {
if tt.req.DryRun {
actual, err := ts.GetVSchema(ctx, tt.req.Keyspace)
require.NoError(t, err)
utils.MustMatch(t, res.VSchema, actual)
utils.MustMatch(t, origVSchema, actual)
}

if tt.req.SkipRebuild {
finalSrvVSchema, err := vtctld.GetSrvVSchema(ctx, &vtctldatapb.GetSrvVSchemaRequest{Cell: "zone1"})
require.NoError(t, err)
utils.MustMatch(t, origSrvVSchema.SrvVSchema, finalSrvVSchema.SrvVSchema)
finalSrvVSchema, err := ts.GetSrvVSchema(ctx, "zone1")
require.NoError(t, err)

if tt.req.SkipRebuild || tt.req.DryRun {
utils.MustMatch(t, origSrvVSchema, finalSrvVSchema)
} else {
changedSrvVSchema := &vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"testkeyspace": {
Sharded: false,
},
},
RoutingRules: &vschemapb.RoutingRules{
Rules: []*vschemapb.RoutingRule{},
},
}
utils.MustMatch(t, changedSrvVSchema, finalSrvVSchema)
}
})
}
Expand Down

0 comments on commit 785c3b6

Please sign in to comment.