Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Oct 2, 2024
1 parent ea2d444 commit d827600
Showing 1 changed file with 0 additions and 202 deletions.
202 changes: 0 additions & 202 deletions go/vt/vtctl/grpcvtctldserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,8 +1146,6 @@ func TestChangeTabletTags(t *testing.T) {
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1213,206 +1211,6 @@ func TestChangeTabletTags(t *testing.T) {
})
}

func TestChangeTabletTags(t *testing.T) {
t.Parallel()

tests := []struct {
name string
cells []string
tablet *topodatapb.Tablet
req *vtctldatapb.ChangeTabletTagsRequest
expected *vtctldatapb.ChangeTabletTagsResponse
shouldErr bool
}{
{
name: "success",
cells: []string{"zone1"},
tablet: &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "ks",
Shard: "0",
},
req: &vtctldatapb.ChangeTabletTagsRequest{
TabletAlias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Tags: map[string]string{
"test": t.Name(),
},
},
expected: &vtctldatapb.ChangeTabletTagsResponse{
AfterTags: map[string]string{
"test": t.Name(),
},
},
shouldErr: false,
},
{
name: "success with existing",
cells: []string{"zone1"},
tablet: &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "ks",
Shard: "0",
Tags: map[string]string{
"delete": "me",
"hello": "world!",
},
},
req: &vtctldatapb.ChangeTabletTagsRequest{
TabletAlias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Tags: map[string]string{
"delete": "",
"test": t.Name(),
},
},
expected: &vtctldatapb.ChangeTabletTagsResponse{
BeforeTags: map[string]string{
"delete": "me",
"hello": "world!",
},
AfterTags: map[string]string{
"hello": "world!",
"test": t.Name(),
},
},
shouldErr: false,
},
{
name: "success with replace",
cells: []string{"zone1"},
tablet: &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "ks",
Shard: "0",
Tags: map[string]string{
"hello": "world!",
},
},
req: &vtctldatapb.ChangeTabletTagsRequest{
TabletAlias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Tags: map[string]string{
"test": t.Name(),
},
Replace: true,
},
expected: &vtctldatapb.ChangeTabletTagsResponse{
BeforeTags: map[string]string{
"hello": "world!",
},
AfterTags: map[string]string{
"test": t.Name(),
},
},
shouldErr: false,
},
{
name: "tablet not found",
cells: []string{"zone1"},
tablet: &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 200,
},
Keyspace: "ks",
Shard: "0",
},
req: &vtctldatapb.ChangeTabletTagsRequest{
TabletAlias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Tags: map[string]string{
"test": t.Name(),
},
},
expected: nil,
shouldErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ts := memorytopo.NewServer(ctx, tt.cells...)
vtctld := testutil.NewVtctldServerWithTabletManagerClient(t, ts, &testutil.TabletManagerClient{
TopoServer: ts,
}, func(ts *topo.Server) vtctlservicepb.VtctldServer {
return NewVtctldServer(vtenv.NewTestEnv(), ts)
})

testutil.AddTablets(ctx, t, ts, &testutil.AddTabletOptions{
AlsoSetShardPrimary: true,
}, tt.tablet)

resp, err := vtctld.ChangeTabletTags(ctx, tt.req)
if tt.shouldErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
utils.MustMatch(t, tt.expected, resp)

tablet, err := ts.GetTablet(ctx, tt.req.TabletAlias)
assert.NoError(t, err)
utils.MustMatch(t, resp.AfterTags, tablet.Tags)
})
}

t.Run("tabletmanager failure", func(t *testing.T) {
t.Parallel()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ts := memorytopo.NewServer(ctx, "zone1")
vtctld := testutil.NewVtctldServerWithTabletManagerClient(t, ts, &testutil.TabletManagerClient{
TopoServer: nil,
}, func(ts *topo.Server) vtctlservicepb.VtctldServer {
return NewVtctldServer(vtenv.NewTestEnv(), ts)
})

testutil.AddTablet(ctx, t, ts, &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "ks",
Shard: "0",
Type: topodatapb.TabletType_REPLICA,
}, nil)

_, err := vtctld.ChangeTabletTags(ctx, &vtctldatapb.ChangeTabletTagsRequest{
TabletAlias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Tags: map[string]string{
"test": t.Name(),
},
})
assert.Error(t, err)
})
}

func TestChangeTabletType(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit d827600

Please sign in to comment.