Documentation ¶
Index ¶
- Constants
- func FrameRelay(t *testing.T, destination string, ...) (listenHostPort string, cancel func())
- func NewClient(opts *ChannelOpts) (*tchannel.Channel, error)
- func NewIncomingCall(callerName string) tchannel.IncomingCall
- func NewServer(opts *ChannelOpts) (*tchannel.Channel, error)
- func NowStub(funcVar *func() time.Time, initial time.Time) func(time.Duration)
- func RandBytes(n int) []byte
- func RegisterFunc(t *testing.T, ch *tchannel.Channel, name string, ...)
- func ResetNowStub(funcVar *func() time.Time)
- func ResetSleepStub(funcVar *func(time.Duration))
- func SetTimeout(t *testing.T, timeout time.Duration) func()
- func SleepStub(funcVar *func(time.Duration)) (<-chan time.Duration, chan<- struct{})
- func WaitFor(timeout time.Duration, f func() bool) bool
- func WaitWG(wg *sync.WaitGroup, timeout time.Duration) bool
- func WithServer(opts *ChannelOpts, f func(ch *tchannel.Channel, hostPort string)) error
- type ChannelOpts
- type FakeIncomingCall
Constants ¶
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 ¶
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 ¶
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 ResetSleepStub ¶
ResetSleepStub resets a Sleep stub.
func SetTimeout ¶
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 ¶
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 ¶
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 ¶
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.