go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/wrangler/testlib Index | Files

package testlib

import "gopkg.in/src-d/go-vitess.v1/vt/wrangler/testlib"

Package testlib contains utility methods to include in unit tests to deal with topology common tasks, like fake tablets and action loops.

Index

Package Files

fake_tablet.go vtctl_pipe.go

type FakeTablet Uses

type FakeTablet struct {
    // Tablet and FakeMysqlDaemon are populated at NewFakeTablet time.
    // We also create the RPCServer, so users can register more services
    // before calling StartActionLoop().
    Tablet          *topodatapb.Tablet
    FakeMysqlDaemon *fakemysqldaemon.FakeMysqlDaemon
    RPCServer       *grpc.Server

    // The following fields are created when we start the event loop for
    // the tablet, and closed / cleared when we stop it.
    // The Listener is used by the gRPC server.
    Agent    *tabletmanager.ActionAgent
    Listener net.Listener

    // These optional fields are used if the tablet also needs to
    // listen on the 'vt' port.
    StartHTTPServer bool
    HTTPListener    net.Listener
    HTTPServer      *http.Server
}

FakeTablet keeps track of a fake tablet in memory. It has: - a Tablet record (used for creating the tablet, kept for user's information) - a FakeMysqlDaemon (used by the fake event loop) - a 'done' channel (used to terminate the fake event loop)

func NewFakeTablet Uses

func NewFakeTablet(t *testing.T, wr *wrangler.Wrangler, cell string, uid uint32, tabletType topodatapb.TabletType, db *fakesqldb.DB, options ...TabletOption) *FakeTablet

NewFakeTablet creates the test tablet in the topology. 'uid' has to be between 0 and 99. All the tablet info will be derived from that. Look at the implementation if you need values. Use TabletOption implementations if you need to change values at creation. 'db' can be nil if the test doesn't use a database at all.

func (*FakeTablet) StartActionLoop Uses

func (ft *FakeTablet) StartActionLoop(t *testing.T, wr *wrangler.Wrangler)

StartActionLoop will start the action loop for a fake tablet, using ft.FakeMysqlDaemon as the backing mysqld.

func (*FakeTablet) StopActionLoop Uses

func (ft *FakeTablet) StopActionLoop(t *testing.T)

StopActionLoop will stop the Action Loop for the given FakeTablet

func (*FakeTablet) Target Uses

func (ft *FakeTablet) Target() querypb.Target

Target returns the keyspace/shard/type info of this tablet as Target.

type TabletOption Uses

type TabletOption func(tablet *topodatapb.Tablet)

TabletOption is an interface for changing tablet parameters. It's a way to pass multiple parameters to NewFakeTablet without making it too cumbersome.

func ForceInitTablet Uses

func ForceInitTablet() TabletOption

ForceInitTablet is the tablet option to set the 'force' flag during InitTablet

func StartHTTPServer Uses

func StartHTTPServer() TabletOption

StartHTTPServer is the tablet option to start the HTTP server when starting a tablet.

func TabletKeyspaceShard Uses

func TabletKeyspaceShard(t *testing.T, keyspace, shard string) TabletOption

TabletKeyspaceShard is the option to set the tablet keyspace and shard

type VtctlPipe Uses

type VtctlPipe struct {
    // contains filtered or unexported fields
}

VtctlPipe is a vtctl server based on a topo server, and a client that is connected to it via gRPC.

func NewVtctlPipe Uses

func NewVtctlPipe(t *testing.T, ts *topo.Server) *VtctlPipe

NewVtctlPipe creates a new VtctlPipe based on the given topo server.

func (*VtctlPipe) Close Uses

func (vp *VtctlPipe) Close()

Close will stop listening and free up all resources.

func (*VtctlPipe) Run Uses

func (vp *VtctlPipe) Run(args []string) error

Run executes the provided command remotely, logs the output in the test logs, and returns the command error.

func (*VtctlPipe) RunAndOutput Uses

func (vp *VtctlPipe) RunAndOutput(args []string) (string, error)

RunAndOutput is similar to Run, but returns the output as a multi-line string instead of logging it.

func (*VtctlPipe) RunAndStreamOutput Uses

func (vp *VtctlPipe) RunAndStreamOutput(args []string) (logutil.EventStream, error)

RunAndStreamOutput returns the output of the vtctl command as a channel. When the channcel is closed, the command did finish.

Package testlib imports 29 packages (graph) and is imported by 2 packages. Updated 2019-06-13. Refresh now. Tools for package owners.