mock

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDeliberate occurs when a unit test simulates an error.
	ErrDeliberate = errors.New("deliberate error occurred")
)

Functions

This section is empty.

Types

type HTTPClientMock

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

HTTPClientMock represents a mocked HTTP client.

func NewHTTPClientMock

func NewHTTPClientMock(options ...Option) *HTTPClientMock

NewHTTPClientMock creates a new instance of a mocked HTTP client.

func (*HTTPClientMock) Count

func (h *HTTPClientMock) Count(path string) int

Count returns number of times the specified path was hit.

func (*HTTPClientMock) Do

func (h *HTTPClientMock) Do(request *http.Request) (*http.Response, error)

Do sends an HTTP request to the mocked server.

func (*HTTPClientMock) SetResponse

func (h *HTTPClientMock) SetResponse(path string, response *http.Response)

SetResponse sets the response you expect to be returned from the server once the specified path is hit.

type Option

type Option func(*Options)

Option represents an optional configuration function for mocked clients.

func ForceToFail

func ForceToFail(force bool) Option

ForceToFail if enabled, it forces the mocked HTTP requests to fail.

func WhenCalled

func WhenCalled(callback func(*http.Request)) Option

WhenCalled sets a callback which will be called once an HTTP request is being sent to the server.

type Options

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

Options mocked client configurations.

Jump to

Keyboard shortcuts

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