testutils

package
v0.0.0-...-a1a640b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2015 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultServerName = "testService"
	DefaultClientName = "testService-client"
)

Default service names for the test channels.

Variables

This section is empty.

Functions

func FrameRelay

func FrameRelay(t *testing.T, destination string, relayFunc func(outgoing bool, f *tchannel.Frame) *tchannel.Frame) (listenHostPort string, cancel func())

FrameRelay sets up a relay that can modify frames using relayFunc.

func NewClient

func NewClient(opts *ChannelOpts) (*tchannel.Channel, error)

NewClient creates a TChannel that is not listening.

func NewIncomingCall

func NewIncomingCall(callerName string) tchannel.IncomingCall

NewIncomingCall creates an incoming call for tests.

func NewServer

func NewServer(opts *ChannelOpts) (*tchannel.Channel, error)

NewServer creates a TChannel that is listening and returns the channel.

func NowStub

func NowStub(funcVar *func() time.Time, initial time.Time) func(time.Duration)

NowStub replaces a function variable to time.Now with a function that allows the return values to be controller by the caller. The rerturned function is used to control the increment amount between calls.

func RandBytes

func RandBytes(n int) []byte

RandBytes returns n random byte slice that points to a shared random byte array. Since the underlying random array is shared, the returned byte slice must NOT be modified.

func RegisterFunc

func RegisterFunc(t *testing.T, ch *tchannel.Channel, name string,
	f func(ctx context.Context, args *raw.Args) (*raw.Res, error))

RegisterFunc registers a function as a handler for the given operation name.

func ResetNowStub

func ResetNowStub(funcVar *func() time.Time)

ResetNowStub resets a Now stub.

func ResetSleepStub

func ResetSleepStub(funcVar *func(time.Duration))

ResetSleepStub resets a Sleep stub.

func SetTimeout

func SetTimeout(t *testing.T, timeout time.Duration) func()

SetTimeout is used to fail tests after a timeout. It returns a function that should be run once the test is complete. The standard way is to use defer, e.g. defer SetTimeout(t, time.Second)()

func SleepStub

func SleepStub(funcVar *func(time.Duration)) (<-chan time.Duration, chan<- struct{})

SleepStub returns a function that can be used to stub time.Sleep, as well as two channels to control the sleep stub: .<-chan time.Duration which will contain arguments that the stub was called with. chan<- struct{} that should be written to when you want the Sleep to return.

func WaitFor

func WaitFor(timeout time.Duration, f func() bool) bool

WaitFor will retry f till it returns true for a maximum of timeout. It returns true if f returned true, false if timeout was hit.

func WaitWG

func WaitWG(wg *sync.WaitGroup, timeout time.Duration) bool

WaitWG waits for the given WaitGroup to be complete with a timeout and returns whether the WaitGroup completed within the timeout.

func WithServer

func WithServer(opts *ChannelOpts, f func(ch *tchannel.Channel, hostPort string)) error

WithServer sets up a TChannel that is listening and runs the given function with the channel.

Types

type ChannelOpts

type ChannelOpts struct {
	// ServiceName defaults to "testServer"
	ServiceName string

	// ProcessName defaults to ServiceName + "-[port]"
	ProcessName string

	// EnableLog defaults to false.
	EnableLog bool

	// StatsReporter specifies the StatsReporter to use.
	StatsReporter tchannel.StatsReporter

	// TraceReporter specified the TraceReporter to use.
	TraceReporter tchannel.TraceReporter

	// DefaultConnectionOptions specifies the channel's default connection options.
	DefaultConnectionOptions tchannel.ConnectionOptions
}

ChannelOpts contains options to create a test channel using WithServer

type FakeIncomingCall

type FakeIncomingCall struct {
	// CallerNameF is the calling service's name.
	CallerNameF string

	// ShardKeyF is the intended destination for this call.
	ShardKeyF string
}

FakeIncomingCall implements IncomingCall interface. Note: the F suffix for the fields is to clash with the method name.

func (*FakeIncomingCall) CallerName

func (f *FakeIncomingCall) CallerName() string

CallerName returns the caller name as specified in the fake call.

func (*FakeIncomingCall) ShardKey

func (f *FakeIncomingCall) ShardKey() string

ShardKey returns the shard key as specified in the fake call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL