httptest

package
v0.0.0-...-6fdf832 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockServer

func NewMockServer(rec MockRecorder, procedures ...MockServerProcedure) *httptest.Server

NewMockServer return a mock HTTP server to test requests

Types

type MockAssertion

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

MockAssertion represents a common assertion for requests

func (*MockAssertion) Body

func (m *MockAssertion) Body(uri, method string) [][]byte

Body returns request body

func (*MockAssertion) Headers

func (m *MockAssertion) Headers(uri, method string) []http.Header

Headers returns a slice of request headers

func (*MockAssertion) Hits

func (m *MockAssertion) Hits(uri, method string) int

Hits returns the number of hits for a uri and method

func (*MockAssertion) Record

func (m *MockAssertion) Record(r *http.Request)

Record records request hit information

func (*MockAssertion) Reset

func (m *MockAssertion) Reset() error

Reset sets all unexpected properties to their zero value

func (*MockAssertion) URL

func (m *MockAssertion) URL(uri, method string) (urlList []*url.URL)

URL returns the parsed URL so it can be inspected for query params

type MockRecorder

type MockRecorder interface {
	Record(r *http.Request)
}

MockRecorder provides a way to record request information from every successful request.

type MockResponse

type MockResponse struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
	BodyFn     func() []byte
	HeaderFn   func() http.Header
}

MockResponse represents a response for the mock server to serve

type MockServerProcedure

type MockServerProcedure struct {
	URI        string
	HTTPMethod string
	Response   MockResponse
	ResponseFn func() MockResponse
}

Jump to

Keyboard shortcuts

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