mock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ContextType

type ContextType struct {
	context.EMFContext
	// contains filtered or unexported fields
}

ContextType is the EMF Context type that will be sent to each Handler on a request

func NewMockContext

func NewMockContext(
	method string,
	path string,
	body interface{},
	errorsYaml string,
	t *testing.T,
	opts ...Option,
) (mc *ContextType, err error)

NewMockContext is a variadic constructor for a MockContext.

func (*ContextType) AddRequestFunction

func (mc *ContextType) AddRequestFunction(
	method, component, path string,

	f func(input interface{}) (statusCode int, output interface{}),
)

AddRequestFunction is a method to enable a new Mock Request for this context

func (*ContextType) AddRequestInterface

func (mc *ContextType) AddRequestInterface(
	method, component, path string,

	response interface{},
)

AddRequestInterface is a method to enable a new Mock Request for this context

func (*ContextType) AddRequestMap

func (mc *ContextType) AddRequestMap(
	method, component, path string,

	response map[string]interface{},
)

AddRequestMap is a method to enable a new Mock Request for this context

func (*ContextType) AddRequestStatusCode

func (mc *ContextType) AddRequestStatusCode(
	method, component, path string, statusCode int,

	response interface{},
)

AddRequestStatusCode is a method to enable a new Mock Request and facilitate making c.Requester fail

func (*ContextType) DecodeResult

func (mc *ContextType) DecodeResult(output interface{}) (err error)

DecodeResult is a method to decode the recorded HTTP Response into the provided struct pointer

func (*ContextType) GetRequests

func (mc *ContextType) GetRequests() map[string]interface{}

GetRequests is a method to return the map of all Mock Requests for this Context

func (*ContextType) MockRecorder

func (mc *ContextType) MockRecorder() *httptest.ResponseRecorder

MockRecorder is a method to fetch the *httptest.ResponseRecorder pointer which exposes the http response

func (*ContextType) MockRequest

func (mc *ContextType) MockRequest() *http.Request

MockRequest is a method to fetch the *http.Request pointer which defines the input request

func (*ContextType) MockResponse

func (mc *ContextType) MockResponse() *http.Response

MockResponse is a method to fetch the ResponseRecorder.Result object to expose the http response

func (*ContextType) Requester

func (mc *ContextType) Requester(
	method string,
	component string,
	path string,
	input interface{},
	output interface{},
) (err error)

Requester : This method is called by the Handler that consumes this MockContext object. When the Handler calls Requester, it will pull from the Mock Request map, which is manipulated using the AddRequestXXX functions.

func (*ContextType) ResultMap

func (mc *ContextType) ResultMap() map[string]interface{}

ResultMap returns the recorded HTTP Response Body as a map[string]interface{} and fails the test on Error

func (*ContextType) SetRequests

func (mc *ContextType) SetRequests(requests map[string]interface{})

SetRequests is a method to set the map of all Mock Requests for this Context

type MockClient

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

MockClient is a simple tool to encapsulate the old MockRequest functionality into an http.Client

func (*MockClient) Do

func (client *MockClient) Do(req *http.Request) (res *http.Response, err error)

Do implements the http.Client interface and uses a request map for hard-coded request-to-response mapping

type Option

type Option func(*ContextType)

Option provides the client a callback that is used to dynamically specify attributes for a EMFContext.

func SetConfigMap

func SetConfigMap(configMap map[string]interface{}) Option

SetConfigMap is used to add fields to the Config object being used for a MockContext

func WithClaims

func WithClaims(mapClaims jwt.MapClaims) Option

WithClaims is used for specifying the HTTP Client for the Requester to use.

Jump to

Keyboard shortcuts

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