mock

package
v0.0.0-...-5c9d632 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxWithMock

func CtxWithMock(ctx context.Context, mock ...*Mock) context.Context

func InitMockSetting

func InitMockSetting()

func WithHeader

func WithHeader(key, value string) simpleConditionOption

func WithJsonBodyFields

func WithJsonBodyFields(field string, value interface{}) simpleConditionOption

func WithMethod

func WithMethod(method string) simpleConditionOption

func WithPathReg

func WithPathReg(pathReg string) simpleConditionOption

func WithQuery

func WithQuery(key, value string) simpleConditionOption

Types

type Mock

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

func NewMock

func NewMock(con RequestCondition, resp *http.Response, err error) *Mock

func NewMockByPath

func NewMockByPath(path string, resp *http.Response, err error) *Mock

type MockResponseFilter

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

MockResponse will return mock response if find any suitable mock data if you want to test your code using httplib, you need this.

func NewMockResponseFilter

func NewMockResponseFilter() *MockResponseFilter

func (*MockResponseFilter) Clear

func (m *MockResponseFilter) Clear()

func (*MockResponseFilter) FilterChain

func (m *MockResponseFilter) FilterChain(next httplib.Filter) httplib.Filter

func (*MockResponseFilter) Mock

func (m *MockResponseFilter) Mock(cond RequestCondition, resp *http.Response, err error)

Mock add mock data If the cond.Match(...) = true, the resp and err will be returned

func (*MockResponseFilter) MockByPath

func (m *MockResponseFilter) MockByPath(path string, resp *http.Response, err error)

type RequestCondition

type RequestCondition interface {
	Match(ctx context.Context, req *httplib.BeegoHTTPRequest) bool
}

type SimpleCondition

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

reqCondition create condition - path: same path - pathReg: request path match pathReg - method: same method - Query parameters (key, value) - header (key, value) - Body json format, contains specific (key, value).

func NewSimpleCondition

func NewSimpleCondition(path string, opts ...simpleConditionOption) *SimpleCondition

func (*SimpleCondition) Match

type Stub

type Stub interface {
	Mock(cond RequestCondition, resp *http.Response, err error)
	Clear()
	MockByPath(path string, resp *http.Response, err error)
}

func StartMock

func StartMock() Stub

Jump to

Keyboard shortcuts

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