tgmock

package
v0.0.0-...-87e9d67 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package tgmock implements mock for tg.Invoker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	Handle(id int64, body bin.Encoder) (bin.Encoder, error)
}

Handler is a RPC call handler.

type HandlerFunc

type HandlerFunc func(id int64, body bin.Encoder) (bin.Encoder, error)

HandlerFunc is a function adapter for Handler.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(id int64, body bin.Encoder) (bin.Encoder, error)

Handle implements Handler.

type Invoker

type Invoker func(request bin.Encoder) (bin.Encoder, error)

Invoker implements tg.Invoker as function.

func (Invoker) Invoke

func (f Invoker) Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) error

Invoke implements tg.Invoker.

type Mock

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

Mock is a mock for tg.Invoker with testify/require support.

func New

func New(t TestingT, options ...Option) *Mock

New creates new Mock.

func NewRequire

func NewRequire(t TestingT) *Mock

NewRequire creates new Mock with "require" assertions.

func (*Mock) AllWereMet

func (i *Mock) AllWereMet() bool

AllWereMet returns true if all expected calls happened.

func (*Mock) Expect

func (i *Mock) Expect() *RequestBuilder

Expect creates builder of new expected call.

func (*Mock) ExpectCall

func (i *Mock) ExpectCall(body bin.Encoder) *RequestBuilder

ExpectCall creates builder of new expected call with given input.

func (*Mock) ExpectFunc

func (i *Mock) ExpectFunc(fn func(b bin.Encoder)) *RequestBuilder

ExpectFunc creates builder of new expected call with given input checker.

func (*Mock) Handler

func (i *Mock) Handler() HandlerFunc

Handler returns HandlerFunc of Mock.

func (*Mock) Invoke

func (i *Mock) Invoke(ctx context.Context, input bin.Encoder, output bin.Decoder) error

Invoke implements tg.Invoker.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures Mock.

func WithRequire

func WithRequire() Option

WithRequire configures mock to use "require" assertions.

type RequestBuilder

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

RequestBuilder is builder of expected RPC request.

func (*RequestBuilder) N

func (b *RequestBuilder) N(times int) *RequestBuilder

N sets count of expected calls.

func (*RequestBuilder) ThenErr

func (b *RequestBuilder) ThenErr(err error) *Mock

ThenErr adds call result to the end of call stack.

func (*RequestBuilder) ThenFalse

func (b *RequestBuilder) ThenFalse() *Mock

ThenFalse adds call tg.BoolFalse result to the end of call stack.

func (*RequestBuilder) ThenFlood

func (b *RequestBuilder) ThenFlood(arg int) *Mock

ThenFlood adds call result to the end of call stack.

func (*RequestBuilder) ThenMigrate

func (b *RequestBuilder) ThenMigrate(typ string, arg int) *Mock

ThenMigrate adds call result to the end of call stack.

func (*RequestBuilder) ThenRPCErr

func (b *RequestBuilder) ThenRPCErr(err *tgerr.Error) *Mock

ThenRPCErr adds call result to the end of call stack.

func (*RequestBuilder) ThenResult

func (b *RequestBuilder) ThenResult(body bin.Encoder) *Mock

ThenResult adds call result to the end of call stack.

func (*RequestBuilder) ThenTrue

func (b *RequestBuilder) ThenTrue() *Mock

ThenTrue adds call tg.BoolTrue result to the end of call stack.

func (*RequestBuilder) ThenUnregistered

func (b *RequestBuilder) ThenUnregistered() *Mock

ThenUnregistered adds call result to the end of call stack.

type TestingT

type TestingT interface {
	require.TestingT
	assert.TestingT
	Helper()
	Cleanup(cb func())
}

TestingT is simplified *testing.T interface.

Jump to

Keyboard shortcuts

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