Documentation
¶
Index ¶
- type APIMock
- type CallVerifier
- type HTTPCall
- type Invocation
- func (call *Invocation) GetPayload() []byte
- func (call *Invocation) GetRequest() *http.Request
- func (call *Invocation) ReadJSONPayload(obj any)
- func (call *Invocation) WithHeader(name string, expectedValues ...string) *Invocation
- func (call *Invocation) WithPayload(expected []byte) *Invocation
- func (call *Invocation) WithQueryValue(name string, value string) *Invocation
- func (call *Invocation) WithQueryValues(values map[string]string) *Invocation
- func (call *Invocation) WithQueryValuesExactly(values map[string]string) *Invocation
- func (call *Invocation) WithStringPayload(expected string) *Invocation
- func (call *Invocation) WithUrlEncodedFormPayload() *InvocationRequestForm
- func (call *Invocation) WithoutHeader(name string) *Invocation
- type InvocationRequestForm
- func (form InvocationRequestForm) Get(s string) string
- func (form InvocationRequestForm) WithValue(key string, value string) InvocationRequestForm
- func (form InvocationRequestForm) WithValues(expectedValues map[string]string) InvocationRequestForm
- func (form InvocationRequestForm) WithValuesExactly(expectedValues map[string]string) InvocationRequestForm
- type StubBuilder
- func (stub *StubBuilder) With(handler http.HandlerFunc) *APIMock
- func (stub *StubBuilder) WithBody(statusCode int, body []byte, contentType string) *APIMock
- func (stub *StubBuilder) WithDelay(delay time.Duration) *StubBuilder
- func (stub *StubBuilder) WithJSON(statusCode int, content interface{}) *APIMock
- func (stub *StubBuilder) WithStatusCode(statusCode int) *APIMock
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIMock ¶ added in v0.1.1
type APIMock struct {
// contains filtered or unexported fields
}
APIMock is a representation of a mocked API. It allows to stub HTTP calls and verify invocations.
func (*APIMock) Close ¶ added in v0.1.1
func (mockedAPI *APIMock) Close()
Close stops the underlying server.
type CallVerifier ¶ added in v0.1.0
type CallVerifier struct {
// contains filtered or unexported fields
}
CallVerifier is a helper to verify invocations of a specific HTTP call
func (*CallVerifier) HasBeenCalled ¶ added in v0.1.0
func (verifier *CallVerifier) HasBeenCalled(expectedCallsCount int) []*Invocation
HasBeenCalled asserts that the HTTP call has been made the expected number of times. It returns all invocations of the call.
func (*CallVerifier) HasBeenCalledOnce ¶ added in v0.1.0
func (verifier *CallVerifier) HasBeenCalledOnce() *Invocation
HasBeenCalledOnce asserts that the HTTP call has been made exactly once then returns the invocation.
func (*CallVerifier) HasNotBeenCalled ¶ added in v0.5.0
func (verifier *CallVerifier) HasNotBeenCalled()
HasNotBeenCalled asserts that no HTTP call has been made.
type Invocation ¶
type Invocation struct {
// contains filtered or unexported fields
}
Invocation represents a single HTTP request made to the mock server.
func (*Invocation) GetPayload ¶ added in v0.1.0
func (call *Invocation) GetPayload() []byte
GetPayload returns the invocation request payload
func (*Invocation) GetRequest ¶ added in v0.1.0
func (call *Invocation) GetRequest() *http.Request
GetRequest returns the invocation request
func (*Invocation) ReadJSONPayload ¶ added in v0.1.1
func (call *Invocation) ReadJSONPayload(obj any)
ReadJSONPayload reads the invocation request payload and unmarshals it into the specified object
func (*Invocation) WithHeader ¶ added in v0.1.0
func (call *Invocation) WithHeader(name string, expectedValues ...string) *Invocation
WithHeader asserts that the invocation request contains the specified header
func (*Invocation) WithPayload ¶ added in v0.1.0
func (call *Invocation) WithPayload(expected []byte) *Invocation
WithPayload asserts that the invocation request contains the specified payload
func (*Invocation) WithQueryValue ¶ added in v1.0.0
func (call *Invocation) WithQueryValue(name string, value string) *Invocation
func (*Invocation) WithQueryValues ¶ added in v1.0.0
func (call *Invocation) WithQueryValues(values map[string]string) *Invocation
func (*Invocation) WithQueryValuesExactly ¶ added in v1.0.0
func (call *Invocation) WithQueryValuesExactly(values map[string]string) *Invocation
func (*Invocation) WithStringPayload ¶ added in v0.1.0
func (call *Invocation) WithStringPayload(expected string) *Invocation
WithStringPayload asserts that the invocation request contains the specified string payload
func (*Invocation) WithUrlEncodedFormPayload ¶ added in v0.3.0
func (call *Invocation) WithUrlEncodedFormPayload() *InvocationRequestForm
WithUrlEncodedFormPayload assert that the invocation content type is application/x-www-form-urlencoded then returns the form to be asserted.
func (*Invocation) WithoutHeader ¶ added in v0.1.0
func (call *Invocation) WithoutHeader(name string) *Invocation
WithoutHeader asserts that the invocation request does not contain the specified header
type InvocationRequestForm ¶ added in v0.3.0
type InvocationRequestForm struct {
// contains filtered or unexported fields
}
InvocationRequestForm represents a form payload of an HTTP request made to the mock server.
func (InvocationRequestForm) Get ¶ added in v1.0.0
func (form InvocationRequestForm) Get(s string) string
func (InvocationRequestForm) WithValue ¶ added in v1.0.0
func (form InvocationRequestForm) WithValue(key string, value string) InvocationRequestForm
func (InvocationRequestForm) WithValues ¶ added in v0.3.0
func (form InvocationRequestForm) WithValues(expectedValues map[string]string) InvocationRequestForm
WithValues asserts that the form contains at least the specified values
func (InvocationRequestForm) WithValuesExactly ¶ added in v0.3.0
func (form InvocationRequestForm) WithValuesExactly(expectedValues map[string]string) InvocationRequestForm
WithValuesExactly asserts that the form contains exactly the specified values
type StubBuilder ¶
type StubBuilder struct {
// contains filtered or unexported fields
}
StubBuilder is a helper to build stubs for a specific HTTP call
func (*StubBuilder) With ¶
func (stub *StubBuilder) With(handler http.HandlerFunc) *APIMock
With creates a new stub for the HTTP call with the specified handler
func (*StubBuilder) WithBody ¶ added in v0.2.0
func (stub *StubBuilder) WithBody(statusCode int, body []byte, contentType string) *APIMock
WithBody creates a new stub handler returning the specified status code and body content.
func (*StubBuilder) WithDelay ¶ added in v0.4.0
func (stub *StubBuilder) WithDelay(delay time.Duration) *StubBuilder
WithDelay adds a delay to the stub when called before it executes the corresponding handler
func (*StubBuilder) WithJSON ¶ added in v0.1.1
func (stub *StubBuilder) WithJSON(statusCode int, content interface{}) *APIMock
WithJSON creates a new stub handler returning the specified status code and JSON content. The response header "Content-Type" is set to "application/json".
func (*StubBuilder) WithStatusCode ¶ added in v0.1.0
func (stub *StubBuilder) WithStatusCode(statusCode int) *APIMock
WithStatusCode creates a new stub handler returning the specified status code