mocks

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const CallsNoConstraint = -1

Variables

This section is empty.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDefinition

func NewDefinition(path string, constraints []verifier, strategy ReplyStrategy, callsConstraint int) *Definition

func (*Definition) EndRunningContext

func (d *Definition) EndRunningContext() []error

func (*Definition) Execute

func (d *Definition) Execute(w http.ResponseWriter, r *http.Request) []error

func (*Definition) ExecuteWithoutVerifying

func (d *Definition) ExecuteWithoutVerifying(w http.ResponseWriter, r *http.Request) []error

func (*Definition) ResetRunningContext

func (d *Definition) ResetRunningContext()

type Error

type Error struct {
	ServiceName string
	// contains filtered or unexported fields
}

func (*Error) Error

func (e *Error) Error() string

type Loader

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

func NewLoader

func NewLoader(mocks *Mocks) *Loader

func (*Loader) Load

func (l *Loader) Load(mocksDefinition map[string]interface{}) error

type Mocks

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

func New

func New(mocks ...*ServiceMock) *Mocks

func NewNop

func NewNop(serviceNames ...string) *Mocks

func (*Mocks) EndRunningContext

func (m *Mocks) EndRunningContext() []error

func (*Mocks) GetNames

func (m *Mocks) GetNames() []string

func (*Mocks) ResetDefinitions

func (m *Mocks) ResetDefinitions()

func (*Mocks) ResetRunningContext

func (m *Mocks) ResetRunningContext()

func (*Mocks) Service

func (m *Mocks) Service(serviceName string) *ServiceMock

func (*Mocks) SetMock

func (m *Mocks) SetMock(mock *ServiceMock)

func (*Mocks) Shutdown

func (m *Mocks) Shutdown()

Stops immediately, with no gracefully closing connections

func (*Mocks) ShutdownContext

func (m *Mocks) ShutdownContext(ctx context.Context) error

func (*Mocks) Start

func (m *Mocks) Start() error

type ReplyStrategy

type ReplyStrategy interface {
	HandleRequest(w http.ResponseWriter, r *http.Request) []error
}

func NewConstantReplyWithCode

func NewConstantReplyWithCode(content []byte, statusCode int, headers map[string]string) ReplyStrategy

func NewDropRequestReply

func NewDropRequestReply() ReplyStrategy

func NewFileReplyWithCode

func NewFileReplyWithCode(filename string, statusCode int, headers map[string]string) (ReplyStrategy, error)

func NewMethodVaryReply

func NewMethodVaryReply(variants map[string]*Definition) ReplyStrategy

func NewSequentialReply

func NewSequentialReply(strategies []*Definition) ReplyStrategy

func NewUriVaryReply

func NewUriVaryReply(basePath string, variants map[string]*Definition) ReplyStrategy

type RequestConstraintError

type RequestConstraintError struct {
	Constraint  verifier
	RequestDump []byte
	// contains filtered or unexported fields
}

func (*RequestConstraintError) Error

func (e *RequestConstraintError) Error() string

type ServiceMock

type ServiceMock struct {
	sync.RWMutex

	ServiceName string
	// contains filtered or unexported fields
}

func NewServiceMock

func NewServiceMock(serviceName string, mock *Definition) *ServiceMock

func (*ServiceMock) EndRunningContext

func (m *ServiceMock) EndRunningContext() []error

func (*ServiceMock) ResetDefinition

func (m *ServiceMock) ResetDefinition()

func (*ServiceMock) ResetRunningContext

func (m *ServiceMock) ResetRunningContext()

func (*ServiceMock) ServeHTTP

func (m *ServiceMock) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*ServiceMock) ServerAddr

func (m *ServiceMock) ServerAddr() string

func (*ServiceMock) SetDefinition

func (m *ServiceMock) SetDefinition(newDefinition *Definition)

func (*ServiceMock) ShutdownServer

func (m *ServiceMock) ShutdownServer(ctx context.Context) error

func (*ServiceMock) StartServer

func (m *ServiceMock) StartServer() error

func (*ServiceMock) StartServerWithAddr

func (m *ServiceMock) StartServerWithAddr(addr string) error

Jump to

Keyboard shortcuts

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