vitess.io/vitess@v0.16.2/go/vt/vtctl/fakevtctlclient/fakevtctlclient.go (about)

     1  /*
     2  Copyright 2019 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 fakevtctlclient contains a fake for the vtctlclient interface.
    18  package fakevtctlclient
    19  
    20  import (
    21  	"time"
    22  
    23  	"context"
    24  
    25  	"vitess.io/vitess/go/vt/logutil"
    26  	"vitess.io/vitess/go/vt/vtctl/vtctlclient"
    27  )
    28  
    29  // FakeVtctlClient is a fake which implements the vtctlclient interface.
    30  // The fake can be used to return a specific result for a given command.
    31  // If the command is not registered, an error will be thrown.
    32  type FakeVtctlClient struct {
    33  	*FakeLoggerEventStreamingClient
    34  }
    35  
    36  // NewFakeVtctlClient creates a FakeVtctlClient struct.
    37  func NewFakeVtctlClient() *FakeVtctlClient {
    38  	return &FakeVtctlClient{NewFakeLoggerEventStreamingClient()}
    39  }
    40  
    41  // FakeVtctlClientFactory always returns the current instance.
    42  func (f *FakeVtctlClient) FakeVtctlClientFactory(addr string) (vtctlclient.VtctlClient, error) {
    43  	return f, nil
    44  }
    45  
    46  // ExecuteVtctlCommand is part of the vtctlclient interface.
    47  func (f *FakeVtctlClient) ExecuteVtctlCommand(ctx context.Context, args []string, actionTimeout time.Duration) (logutil.EventStream, error) {
    48  	return f.FakeLoggerEventStreamingClient.StreamResult("" /* addr */, args)
    49  }
    50  
    51  // Close is part of the vtctlclient interface.
    52  func (f *FakeVtctlClient) Close() {}