vitess.io/vitess@v0.16.2/go/vt/vtadmin/vtctldclient/fakevtctldclient/vtctldclient.go (about)

     1  /*
     2  Copyright 2021 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package fakevtctldclient
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"sort"
    23  	"strings"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  	"google.golang.org/grpc"
    27  
    28  	"vitess.io/vitess/go/vt/topo/topoproto"
    29  	"vitess.io/vitess/go/vt/vtctl/vtctldclient"
    30  
    31  	topodatapb "vitess.io/vitess/go/vt/proto/topodata"
    32  	vschemapb "vitess.io/vitess/go/vt/proto/vschema"
    33  	vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
    34  )
    35  
    36  // VtctldClient provides a partial mock implementation of the
    37  // vtctldclient.VtctldClient interface for use in testing.
    38  type VtctldClient struct {
    39  	vtctldclient.VtctldClient
    40  
    41  	CreateKeyspaceShouldErr bool
    42  	CreateShardShouldErr    bool
    43  	DeleteKeyspaceShouldErr bool
    44  	// Keyed by _sorted_ <ks/shard> list string joined by commas.
    45  	DeleteShardsResults map[string]error
    46  	// Keyed by _sorted_ TabletAlias list string joined by commas.
    47  	DeleteTabletsResults          map[string]error
    48  	EmergencyReparentShardResults map[string]struct {
    49  		Response *vtctldatapb.EmergencyReparentShardResponse
    50  		Error    error
    51  	}
    52  	FindAllShardsInKeyspaceResults map[string]struct {
    53  		Response *vtctldatapb.FindAllShardsInKeyspaceResponse
    54  		Error    error
    55  	}
    56  	GetBackupsResults map[string]struct {
    57  		Response *vtctldatapb.GetBackupsResponse
    58  		Error    error
    59  	}
    60  	GetCellInfoNamesResults *struct {
    61  		Response *vtctldatapb.GetCellInfoNamesResponse
    62  		Error    error
    63  	}
    64  	GetCellInfoResults map[string]struct {
    65  		Response *vtctldatapb.GetCellInfoResponse
    66  		Error    error
    67  	}
    68  	GetCellsAliasesResults *struct {
    69  		Response *vtctldatapb.GetCellsAliasesResponse
    70  		Error    error
    71  	}
    72  	GetKeyspaceResults map[string]struct {
    73  		Response *vtctldatapb.GetKeyspaceResponse
    74  		Error    error
    75  	}
    76  	GetKeyspacesResults *struct {
    77  		Keyspaces []*vtctldatapb.Keyspace
    78  		Error     error
    79  	}
    80  	GetSchemaResults map[string]struct {
    81  		Response *vtctldatapb.GetSchemaResponse
    82  		Error    error
    83  	}
    84  	GetSrvVSchemaResults map[string]struct {
    85  		Response *vtctldatapb.GetSrvVSchemaResponse
    86  		Error    error
    87  	}
    88  	GetVSchemaResults map[string]struct {
    89  		Response *vtctldatapb.GetVSchemaResponse
    90  		Error    error
    91  	}
    92  	GetWorkflowsResults map[string]struct {
    93  		Response *vtctldatapb.GetWorkflowsResponse
    94  		Error    error
    95  	}
    96  	PingTabletResults           map[string]error
    97  	PlannedReparentShardResults map[string]struct {
    98  		Response *vtctldatapb.PlannedReparentShardResponse
    99  		Error    error
   100  	}
   101  	RefreshStateResults         map[string]error
   102  	ReloadSchemaKeyspaceResults map[string]struct {
   103  		Response *vtctldatapb.ReloadSchemaKeyspaceResponse
   104  		Error    error
   105  	}
   106  	ReloadSchemaResults map[string]struct {
   107  		Response *vtctldatapb.ReloadSchemaResponse
   108  		Error    error
   109  	}
   110  	ReloadSchemaShardResults map[string]struct {
   111  		Response *vtctldatapb.ReloadSchemaShardResponse
   112  		Error    error
   113  	}
   114  	ReparentTabletResults map[string]struct {
   115  		Response *vtctldatapb.ReparentTabletResponse
   116  		Error    error
   117  	}
   118  	RunHealthCheckResults            map[string]error
   119  	SetWritableResults               map[string]error
   120  	ShardReplicationPositionsResults map[string]struct {
   121  		Response *vtctldatapb.ShardReplicationPositionsResponse
   122  		Error    error
   123  	}
   124  	StartReplicationResults           map[string]error
   125  	StopReplicationResults            map[string]error
   126  	TabletExternallyReparentedResults map[string]struct {
   127  		Response *vtctldatapb.TabletExternallyReparentedResponse
   128  		Error    error
   129  	}
   130  	ValidateKeyspaceResults map[string]struct {
   131  		Response *vtctldatapb.ValidateKeyspaceResponse
   132  		Error    error
   133  	}
   134  	ValidateSchemaKeyspaceResults map[string]struct {
   135  		Response *vtctldatapb.ValidateSchemaKeyspaceResponse
   136  		Error    error
   137  	}
   138  	ValidateVersionKeyspaceResults map[string]struct {
   139  		Response *vtctldatapb.ValidateVersionKeyspaceResponse
   140  		Error    error
   141  	}
   142  }
   143  
   144  // Compile-time type assertion to make sure we haven't overriden a method
   145  // incorrectly.
   146  var _ vtctldclient.VtctldClient = (*VtctldClient)(nil)
   147  
   148  // Close is part of the vtctldclient.VtctldClient interface.
   149  func (fake *VtctldClient) Close() error { return nil }
   150  
   151  // CreateKeyspace is part of the vtctldclient.VtctldClient interface.
   152  func (fake *VtctldClient) CreateKeyspace(ctx context.Context, req *vtctldatapb.CreateKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.CreateKeyspaceResponse, error) {
   153  	if fake.CreateKeyspaceShouldErr {
   154  		return nil, fmt.Errorf("%w: CreateKeyspace error", assert.AnError)
   155  	}
   156  
   157  	ks := &topodatapb.Keyspace{
   158  		ServedFroms:  req.ServedFroms,
   159  		KeyspaceType: req.Type,
   160  		BaseKeyspace: req.BaseKeyspace,
   161  		SnapshotTime: req.SnapshotTime,
   162  	}
   163  
   164  	return &vtctldatapb.CreateKeyspaceResponse{
   165  		Keyspace: &vtctldatapb.Keyspace{
   166  			Name:     req.Name,
   167  			Keyspace: ks,
   168  		},
   169  	}, nil
   170  }
   171  
   172  // CreateShard is part of the vtctldclient.VtctldClient interface.
   173  func (fake *VtctldClient) CreateShard(cxt context.Context, req *vtctldatapb.CreateShardRequest, opts ...grpc.CallOption) (*vtctldatapb.CreateShardResponse, error) {
   174  	if fake.CreateShardShouldErr {
   175  		return nil, fmt.Errorf("%w: CreateShard error", assert.AnError)
   176  	}
   177  
   178  	return &vtctldatapb.CreateShardResponse{
   179  		Keyspace: &vtctldatapb.Keyspace{
   180  			Name:     req.Keyspace,
   181  			Keyspace: &topodatapb.Keyspace{},
   182  		},
   183  		Shard: &vtctldatapb.Shard{
   184  			Keyspace: req.Keyspace,
   185  			Name:     req.ShardName,
   186  			Shard:    &topodatapb.Shard{},
   187  		},
   188  	}, nil
   189  }
   190  
   191  // DeleteKeyspace is part of the vtctldclient.VtctldClient interface.
   192  func (fake *VtctldClient) DeleteKeyspace(ctx context.Context, req *vtctldatapb.DeleteKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.DeleteKeyspaceResponse, error) {
   193  	if fake.DeleteKeyspaceShouldErr {
   194  		return nil, fmt.Errorf("%w: DeleteKeyspace error", assert.AnError)
   195  	}
   196  
   197  	return &vtctldatapb.DeleteKeyspaceResponse{}, nil
   198  }
   199  
   200  // DeleteShards is part of the vtctldclient.VtctldClient interface.
   201  func (fake *VtctldClient) DeleteShards(ctx context.Context, req *vtctldatapb.DeleteShardsRequest, opts ...grpc.CallOption) (*vtctldatapb.DeleteShardsResponse, error) {
   202  	if fake.DeleteShardsResults == nil {
   203  		return nil, fmt.Errorf("%w: DeleteShardsResults not set on fake vtctldclient", assert.AnError)
   204  	}
   205  
   206  	shards := make([]string, len(req.Shards))
   207  	for i, shard := range req.Shards {
   208  		shards[i] = fmt.Sprintf("%s/%s", shard.Keyspace, shard.Name)
   209  	}
   210  	sort.Strings(shards)
   211  	key := strings.Join(shards, ",")
   212  
   213  	if err, ok := fake.DeleteShardsResults[key]; ok {
   214  		if err != nil {
   215  			return nil, err
   216  		}
   217  
   218  		return &vtctldatapb.DeleteShardsResponse{}, nil
   219  	}
   220  
   221  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   222  }
   223  
   224  // DeleteTablets is part of the vtctldclient.VtctldClient interface.
   225  func (fake *VtctldClient) DeleteTablets(ctx context.Context, req *vtctldatapb.DeleteTabletsRequest, opts ...grpc.CallOption) (*vtctldatapb.DeleteTabletsResponse, error) {
   226  	if fake.DeleteTabletsResults == nil {
   227  		return nil, fmt.Errorf("%w: DeleteTabletsResults not set on fake vtctldclient", assert.AnError)
   228  	}
   229  
   230  	aliases := topoproto.TabletAliasList(req.TabletAliases)
   231  	sort.Sort(aliases)
   232  	key := strings.Join(aliases.ToStringSlice(), ",")
   233  
   234  	if err, ok := fake.DeleteTabletsResults[key]; ok {
   235  		if err != nil {
   236  			return nil, err
   237  		}
   238  
   239  		return &vtctldatapb.DeleteTabletsResponse{}, nil
   240  	}
   241  
   242  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   243  }
   244  
   245  // EmergencyReparentShard is part of the vtctldclient.VtctldClient interface.
   246  func (fake *VtctldClient) EmergencyReparentShard(ctx context.Context, req *vtctldatapb.EmergencyReparentShardRequest, opts ...grpc.CallOption) (*vtctldatapb.EmergencyReparentShardResponse, error) {
   247  	if fake.EmergencyReparentShardResults == nil {
   248  		return nil, fmt.Errorf("%w: EmergencyReparentShardResults not set on fake vtctldclient", assert.AnError)
   249  	}
   250  
   251  	key := fmt.Sprintf("%s/%s", req.Keyspace, req.Shard)
   252  	if result, ok := fake.EmergencyReparentShardResults[key]; ok {
   253  		return result.Response, result.Error
   254  	}
   255  
   256  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   257  }
   258  
   259  // FindAllShardsInKeyspace is part of the vtctldclient.VtctldClient interface.
   260  func (fake *VtctldClient) FindAllShardsInKeyspace(ctx context.Context, req *vtctldatapb.FindAllShardsInKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.FindAllShardsInKeyspaceResponse, error) {
   261  	if fake.FindAllShardsInKeyspaceResults == nil {
   262  		return nil, fmt.Errorf("%w: FindAllShardsInKeyspaceResults not set on fake vtctldclient", assert.AnError)
   263  	}
   264  
   265  	if result, ok := fake.FindAllShardsInKeyspaceResults[req.Keyspace]; ok {
   266  		return result.Response, result.Error
   267  	}
   268  
   269  	return nil, fmt.Errorf("%w: no result set for keyspace %s", assert.AnError, req.Keyspace)
   270  }
   271  
   272  // GetBackups is part of the vtctldclient.VtctldClient interface.
   273  func (fake *VtctldClient) GetBackups(ctx context.Context, req *vtctldatapb.GetBackupsRequest, opts ...grpc.CallOption) (*vtctldatapb.GetBackupsResponse, error) {
   274  	if fake.GetBackupsResults == nil {
   275  		return nil, fmt.Errorf("%w: GetBackupsResults not set on fake vtctldclient", assert.AnError)
   276  	}
   277  
   278  	key := fmt.Sprintf("%s/%s", req.Keyspace, req.Shard)
   279  	if result, ok := fake.GetBackupsResults[key]; ok {
   280  		return result.Response, result.Error
   281  	}
   282  
   283  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   284  }
   285  
   286  // GetCellInfo is part of the vtctldclient.VtctldClient interface.
   287  func (fake *VtctldClient) GetCellInfo(ctx context.Context, req *vtctldatapb.GetCellInfoRequest, opts ...grpc.CallOption) (*vtctldatapb.GetCellInfoResponse, error) {
   288  	if fake.GetCellInfoResults == nil {
   289  		return nil, fmt.Errorf("%w: GetCellInfoResults not set on fake vtctldclient", assert.AnError)
   290  	}
   291  
   292  	if result, ok := fake.GetCellInfoResults[req.Cell]; ok {
   293  		return result.Response, result.Error
   294  	}
   295  
   296  	return nil, fmt.Errorf("%w: GetCellInfoResults no result set for %s", assert.AnError, req.Cell)
   297  }
   298  
   299  // GetCellInfoNames is part of the vtctldclient.VtctldClient interface.
   300  func (fake *VtctldClient) GetCellInfoNames(ctx context.Context, req *vtctldatapb.GetCellInfoNamesRequest, opts ...grpc.CallOption) (*vtctldatapb.GetCellInfoNamesResponse, error) {
   301  	if fake.GetCellInfoNamesResults == nil {
   302  		return nil, fmt.Errorf("%w: GetCellInfoNamesResults not set on fake vtctldclient", assert.AnError)
   303  	}
   304  
   305  	return fake.GetCellInfoNamesResults.Response, fake.GetCellInfoNamesResults.Error
   306  }
   307  
   308  // GetCellsAliases is part of the vtctldclient.VtctldClient interface.
   309  func (fake *VtctldClient) GetCellsAliases(ctx context.Context, req *vtctldatapb.GetCellsAliasesRequest, opts ...grpc.CallOption) (*vtctldatapb.GetCellsAliasesResponse, error) {
   310  	if fake.GetCellsAliasesResults == nil {
   311  		return nil, fmt.Errorf("%w: GetCellsAliasesResults not set on fake vtctldclient", assert.AnError)
   312  	}
   313  
   314  	return fake.GetCellsAliasesResults.Response, fake.GetCellsAliasesResults.Error
   315  }
   316  
   317  // GetKeyspace is part of the vtctldclient.VtctldClient interface.
   318  func (fake *VtctldClient) GetKeyspace(ctx context.Context, req *vtctldatapb.GetKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.GetKeyspaceResponse, error) {
   319  	if fake.GetKeyspaceResults == nil {
   320  		return nil, fmt.Errorf("%w: GetKeyspaceResults not set on fake vtctldclient", assert.AnError)
   321  	}
   322  
   323  	if result, ok := fake.GetKeyspaceResults[req.Keyspace]; ok {
   324  		return result.Response, result.Error
   325  	}
   326  
   327  	return nil, fmt.Errorf("%w: no result set for keyspace %s", assert.AnError, req.Keyspace)
   328  }
   329  
   330  // GetKeyspaces is part of the vtctldclient.VtctldClient interface.
   331  func (fake *VtctldClient) GetKeyspaces(ctx context.Context, req *vtctldatapb.GetKeyspacesRequest, opts ...grpc.CallOption) (*vtctldatapb.GetKeyspacesResponse, error) {
   332  	if fake.GetKeyspacesResults == nil {
   333  		return nil, fmt.Errorf("%w: GetKeyspacesResults not set on fake vtctldclient", assert.AnError)
   334  	}
   335  
   336  	if fake.GetKeyspacesResults.Error != nil {
   337  		return nil, fake.GetKeyspacesResults.Error
   338  	}
   339  
   340  	return &vtctldatapb.GetKeyspacesResponse{
   341  		Keyspaces: fake.GetKeyspacesResults.Keyspaces,
   342  	}, nil
   343  }
   344  
   345  // GetSchema is part of the vtctldclient.VtctldClient interface.
   346  func (fake *VtctldClient) GetSchema(ctx context.Context, req *vtctldatapb.GetSchemaRequest, opts ...grpc.CallOption) (*vtctldatapb.GetSchemaResponse, error) {
   347  	if fake.GetSchemaResults == nil {
   348  		return nil, fmt.Errorf("%w: GetSchemaResults not set on fake vtctldclient", assert.AnError)
   349  	}
   350  
   351  	if req.TabletAlias == nil {
   352  		return nil, fmt.Errorf("%w: req.TabletAlias == nil", assert.AnError)
   353  	}
   354  
   355  	key := topoproto.TabletAliasString(req.TabletAlias)
   356  
   357  	if result, ok := fake.GetSchemaResults[key]; ok {
   358  		return result.Response, result.Error
   359  	}
   360  
   361  	return nil, fmt.Errorf("%w: no result set for tablet alias %s", assert.AnError, key)
   362  }
   363  
   364  // GetSrvVSchema is part of the vtctldclient.VtctldClient interface.
   365  func (fake *VtctldClient) GetSrvVSchema(ctx context.Context, req *vtctldatapb.GetSrvVSchemaRequest, opts ...grpc.CallOption) (*vtctldatapb.GetSrvVSchemaResponse, error) {
   366  	if fake.GetSrvVSchemaResults == nil {
   367  		return nil, fmt.Errorf("%w: GetSrvVSchemaResults not set on fake vtctldclient", assert.AnError)
   368  	}
   369  
   370  	if result, ok := fake.GetSrvVSchemaResults[req.Cell]; ok {
   371  		return result.Response, result.Error
   372  	}
   373  
   374  	return nil, fmt.Errorf("%w: no result set for key %s", assert.AnError, req.Cell)
   375  }
   376  
   377  // GetSrvVSchemas is part of the vtctldclient.VtctldClient interface.
   378  func (fake *VtctldClient) GetSrvVSchemas(ctx context.Context, req *vtctldatapb.GetSrvVSchemasRequest, opts ...grpc.CallOption) (resp *vtctldatapb.GetSrvVSchemasResponse, err error) {
   379  	resp = &vtctldatapb.GetSrvVSchemasResponse{
   380  		SrvVSchemas: map[string]*vschemapb.SrvVSchema{},
   381  	}
   382  
   383  	cells := req.Cells
   384  	if len(req.Cells) == 0 {
   385  		for cell := range fake.GetSrvVSchemaResults {
   386  			cells = append(cells, cell)
   387  		}
   388  	}
   389  
   390  	for _, cell := range cells {
   391  		r, err := fake.GetSrvVSchema(ctx, &vtctldatapb.GetSrvVSchemaRequest{Cell: cell}, opts...)
   392  		if err != nil {
   393  			return nil, err
   394  		}
   395  
   396  		resp.SrvVSchemas[cell] = r.SrvVSchema
   397  	}
   398  
   399  	return resp, nil
   400  }
   401  
   402  // GetVSchema is part of the vtctldclient.VtctldClient interface.
   403  func (fake *VtctldClient) GetVSchema(ctx context.Context, req *vtctldatapb.GetVSchemaRequest, opts ...grpc.CallOption) (*vtctldatapb.GetVSchemaResponse, error) {
   404  	if fake.GetVSchemaResults == nil {
   405  		return nil, fmt.Errorf("%w: GetVSchemaResults not set on fake vtctldclient", assert.AnError)
   406  	}
   407  
   408  	if result, ok := fake.GetVSchemaResults[req.Keyspace]; ok {
   409  		return result.Response, result.Error
   410  	}
   411  
   412  	return nil, fmt.Errorf("%w: no result set for keyspace %s", assert.AnError, req.Keyspace)
   413  }
   414  
   415  // GetWorkflows is part of the vtctldclient.VtctldClient interface.
   416  func (fake *VtctldClient) GetWorkflows(ctx context.Context, req *vtctldatapb.GetWorkflowsRequest, opts ...grpc.CallOption) (*vtctldatapb.GetWorkflowsResponse, error) {
   417  	if fake.GetWorkflowsResults == nil {
   418  		return nil, fmt.Errorf("%w: GetWorkflowsResults not set on fake vtctldclient", assert.AnError)
   419  	}
   420  
   421  	if result, ok := fake.GetWorkflowsResults[req.Keyspace]; ok {
   422  		return result.Response, result.Error
   423  	}
   424  
   425  	return nil, fmt.Errorf("%w: no result set for keyspace %s", assert.AnError, req.Keyspace)
   426  }
   427  
   428  // PingTablet is part of the vtctldclient.VtctldClient interface.
   429  func (fake *VtctldClient) PingTablet(ctx context.Context, req *vtctldatapb.PingTabletRequest, opts ...grpc.CallOption) (*vtctldatapb.PingTabletResponse, error) {
   430  	if fake.PingTabletResults == nil {
   431  		return nil, fmt.Errorf("%w: PingTabletResults not set on fake vtctldclient", assert.AnError)
   432  	}
   433  
   434  	key := topoproto.TabletAliasString(req.TabletAlias)
   435  	if err, ok := fake.PingTabletResults[key]; ok {
   436  		if err != nil {
   437  			return nil, err
   438  		}
   439  
   440  		return &vtctldatapb.PingTabletResponse{}, nil
   441  	}
   442  
   443  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   444  }
   445  
   446  // PlannedReparentShard is part of the vtctldclient.VtctldClient interface.
   447  func (fake *VtctldClient) PlannedReparentShard(ctx context.Context, req *vtctldatapb.PlannedReparentShardRequest, opts ...grpc.CallOption) (*vtctldatapb.PlannedReparentShardResponse, error) {
   448  	if fake.PlannedReparentShardResults == nil {
   449  		return nil, fmt.Errorf("%w: PlannedReparentShardResults not set on fake vtctldclient", assert.AnError)
   450  	}
   451  
   452  	key := fmt.Sprintf("%s/%s", req.Keyspace, req.Shard)
   453  	if result, ok := fake.PlannedReparentShardResults[key]; ok {
   454  		return result.Response, result.Error
   455  	}
   456  
   457  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   458  }
   459  
   460  // RefreshState is part of the vtctldclient.VtctldClient interface.
   461  func (fake *VtctldClient) RefreshState(ctx context.Context, req *vtctldatapb.RefreshStateRequest, opts ...grpc.CallOption) (*vtctldatapb.RefreshStateResponse, error) {
   462  	if fake.RefreshStateResults == nil {
   463  		return nil, fmt.Errorf("%w: RefreshStateResults not set on fake vtctldclient", assert.AnError)
   464  	}
   465  
   466  	key := topoproto.TabletAliasString(req.TabletAlias)
   467  	if err, ok := fake.RefreshStateResults[key]; ok {
   468  		if err != nil {
   469  			return nil, err
   470  		}
   471  
   472  		return &vtctldatapb.RefreshStateResponse{}, nil
   473  	}
   474  
   475  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   476  }
   477  
   478  // ReloadSchema is part of the vtctldclient.VtctldClient interface.
   479  func (fake *VtctldClient) ReloadSchema(ctx context.Context, req *vtctldatapb.ReloadSchemaRequest, opts ...grpc.CallOption) (*vtctldatapb.ReloadSchemaResponse, error) {
   480  	if fake.ReloadSchemaResults == nil {
   481  		return nil, fmt.Errorf("%w: ReloadSchemaResults not set on fake vtctldclient", assert.AnError)
   482  	}
   483  
   484  	key := topoproto.TabletAliasString(req.TabletAlias)
   485  	if result, ok := fake.ReloadSchemaResults[key]; ok {
   486  		return result.Response, result.Error
   487  	}
   488  
   489  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   490  }
   491  
   492  // ReloadSchemaKeyspace is part of the vtctldclient.VtctldClient interface.
   493  func (fake *VtctldClient) ReloadSchemaKeyspace(ctx context.Context, req *vtctldatapb.ReloadSchemaKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.ReloadSchemaKeyspaceResponse, error) {
   494  	if fake.ReloadSchemaKeyspaceResults == nil {
   495  		return nil, fmt.Errorf("%w: ReloadSchemaKeyspaceResults not set on fake vtctldclient", assert.AnError)
   496  	}
   497  
   498  	if result, ok := fake.ReloadSchemaKeyspaceResults[req.Keyspace]; ok {
   499  		return result.Response, result.Error
   500  	}
   501  
   502  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, req.Keyspace)
   503  }
   504  
   505  // ReloadSchemaShard is part of the vtctldclient.VtctldClient interface.
   506  func (fake *VtctldClient) ReloadSchemaShard(ctx context.Context, req *vtctldatapb.ReloadSchemaShardRequest, opts ...grpc.CallOption) (*vtctldatapb.ReloadSchemaShardResponse, error) {
   507  	if fake.ReloadSchemaShardResults == nil {
   508  		return nil, fmt.Errorf("%w: ReloadSchemaShardResults not set on fake vtctldclient", assert.AnError)
   509  	}
   510  
   511  	key := fmt.Sprintf("%s/%s", req.Keyspace, req.Shard)
   512  	if result, ok := fake.ReloadSchemaShardResults[key]; ok {
   513  		return result.Response, result.Error
   514  	}
   515  
   516  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   517  }
   518  
   519  // ReparentTablet is part of the vtctldclient.VtctldClient interface.
   520  func (fake *VtctldClient) ReparentTablet(ctx context.Context, req *vtctldatapb.ReparentTabletRequest, opts ...grpc.CallOption) (*vtctldatapb.ReparentTabletResponse, error) {
   521  	if fake.ReparentTabletResults == nil {
   522  		return nil, fmt.Errorf("%w: ReparentTabletResults not set on fake vtctldclient", assert.AnError)
   523  	}
   524  
   525  	key := topoproto.TabletAliasString(req.Tablet)
   526  	if result, ok := fake.ReparentTabletResults[key]; ok {
   527  		return result.Response, result.Error
   528  	}
   529  
   530  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   531  }
   532  
   533  // RunHealthCheck is part of the vtctldclient.VtctldClient interface.
   534  func (fake *VtctldClient) RunHealthCheck(ctx context.Context, req *vtctldatapb.RunHealthCheckRequest, opts ...grpc.CallOption) (*vtctldatapb.RunHealthCheckResponse, error) {
   535  	if fake.RunHealthCheckResults == nil {
   536  		return nil, fmt.Errorf("%w: RunHealthCheckResults not set on fake vtctldclient", assert.AnError)
   537  	}
   538  
   539  	key := topoproto.TabletAliasString(req.TabletAlias)
   540  	if err, ok := fake.RunHealthCheckResults[key]; ok {
   541  		if err != nil {
   542  			return nil, err
   543  		}
   544  
   545  		return &vtctldatapb.RunHealthCheckResponse{}, nil
   546  	}
   547  
   548  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   549  }
   550  
   551  // SetWritable is part of the vtctldclient.VtctldClient interface.
   552  func (fake *VtctldClient) SetWritable(ctx context.Context, req *vtctldatapb.SetWritableRequest, opts ...grpc.CallOption) (*vtctldatapb.SetWritableResponse, error) {
   553  	if fake.SetWritableResults == nil {
   554  		return nil, fmt.Errorf("%w: SetWritableResults not set on fake vtctldclient", assert.AnError)
   555  	}
   556  
   557  	key := topoproto.TabletAliasString(req.TabletAlias)
   558  	if err, ok := fake.SetWritableResults[key]; ok {
   559  		if err != nil {
   560  			return nil, err
   561  		}
   562  
   563  		return &vtctldatapb.SetWritableResponse{}, nil
   564  	}
   565  
   566  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   567  }
   568  
   569  // ShardReplicationPositions is part of the vtctldclient.VtctldClient interface.
   570  func (fake *VtctldClient) ShardReplicationPositions(ctx context.Context, req *vtctldatapb.ShardReplicationPositionsRequest, opts ...grpc.CallOption) (*vtctldatapb.ShardReplicationPositionsResponse, error) {
   571  	if fake.ShardReplicationPositionsResults == nil {
   572  		return nil, fmt.Errorf("%w: ShardReplicationPositionsResults not set on fake vtctldclient", assert.AnError)
   573  	}
   574  
   575  	key := fmt.Sprintf("%s/%s", req.Keyspace, req.Shard)
   576  	if result, ok := fake.ShardReplicationPositionsResults[key]; ok {
   577  		return result.Response, result.Error
   578  	}
   579  
   580  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   581  }
   582  
   583  // StartReplication is part of the vtctldclient.VtctldClient interface.
   584  func (fake *VtctldClient) StartReplication(ctx context.Context, req *vtctldatapb.StartReplicationRequest, opts ...grpc.CallOption) (*vtctldatapb.StartReplicationResponse, error) {
   585  	if fake.StartReplicationResults == nil {
   586  		return nil, fmt.Errorf("%w: StartReplicationResults not set on fake vtctldclient", assert.AnError)
   587  	}
   588  
   589  	key := topoproto.TabletAliasString(req.TabletAlias)
   590  	if err, ok := fake.StartReplicationResults[key]; ok {
   591  		if err != nil {
   592  			return nil, err
   593  		}
   594  
   595  		return &vtctldatapb.StartReplicationResponse{}, nil
   596  	}
   597  
   598  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   599  }
   600  
   601  // StopReplication is part of the vtctldclient.VtctldClient interface.
   602  func (fake *VtctldClient) StopReplication(ctx context.Context, req *vtctldatapb.StopReplicationRequest, opts ...grpc.CallOption) (*vtctldatapb.StopReplicationResponse, error) {
   603  	if fake.StopReplicationResults == nil {
   604  		return nil, fmt.Errorf("%w: StopReplicationResults not set on fake vtctldclient", assert.AnError)
   605  	}
   606  
   607  	key := topoproto.TabletAliasString(req.TabletAlias)
   608  	if err, ok := fake.StopReplicationResults[key]; ok {
   609  		if err != nil {
   610  			return nil, err
   611  		}
   612  
   613  		return &vtctldatapb.StopReplicationResponse{}, nil
   614  	}
   615  
   616  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   617  }
   618  
   619  // TabletExternallyReparented is part of the vtctldclient.VtctldClient interface.
   620  func (fake *VtctldClient) TabletExternallyReparented(ctx context.Context, req *vtctldatapb.TabletExternallyReparentedRequest, opts ...grpc.CallOption) (*vtctldatapb.TabletExternallyReparentedResponse, error) {
   621  	if fake.TabletExternallyReparentedResults == nil {
   622  		return nil, fmt.Errorf("%w: TabletExternallyReparentedResults not set on fake vtctldclient", assert.AnError)
   623  	}
   624  
   625  	key := topoproto.TabletAliasString(req.Tablet)
   626  	if result, ok := fake.TabletExternallyReparentedResults[key]; ok {
   627  		return result.Response, result.Error
   628  	}
   629  
   630  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   631  }
   632  
   633  // ValidateKeyspace is part of the vtctldclient.VtctldClient interface.
   634  func (fake *VtctldClient) ValidateKeyspace(ctx context.Context, req *vtctldatapb.ValidateKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.ValidateKeyspaceResponse, error) {
   635  	if fake.ValidateKeyspaceResults == nil {
   636  		return nil, fmt.Errorf("%w: ValidateKeyspaceResults not set on fake vtctldclient", assert.AnError)
   637  	}
   638  
   639  	key := req.Keyspace
   640  	if result, ok := fake.ValidateKeyspaceResults[key]; ok {
   641  		return result.Response, result.Error
   642  	}
   643  
   644  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   645  }
   646  
   647  // ValidateSchemaKeyspace is part of the vtctldclient.VtctldClient interface.
   648  func (fake *VtctldClient) ValidateSchemaKeyspace(ctx context.Context, req *vtctldatapb.ValidateSchemaKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.ValidateSchemaKeyspaceResponse, error) {
   649  	if fake.ValidateSchemaKeyspaceResults == nil {
   650  		return nil, fmt.Errorf("%w: ValidateSchemaKeyspaceResults not set on fake vtctldclient", assert.AnError)
   651  	}
   652  
   653  	key := req.Keyspace
   654  	if result, ok := fake.ValidateSchemaKeyspaceResults[key]; ok {
   655  		return result.Response, result.Error
   656  	}
   657  
   658  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   659  }
   660  
   661  // ValidateVersionKeyspace is part of the vtctldclient.VtctldClient interface.
   662  func (fake *VtctldClient) ValidateVersionKeyspace(ctx context.Context, req *vtctldatapb.ValidateVersionKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.ValidateVersionKeyspaceResponse, error) {
   663  	if fake.ValidateVersionKeyspaceResults == nil {
   664  		return nil, fmt.Errorf("%w: ValidateVersionKeyspaceResults not set on fake vtctldclient", assert.AnError)
   665  	}
   666  
   667  	key := req.Keyspace
   668  	if result, ok := fake.ValidateVersionKeyspaceResults[key]; ok {
   669  		return result.Response, result.Error
   670  	}
   671  
   672  	return nil, fmt.Errorf("%w: no result set for %s", assert.AnError, key)
   673  }