Documentation ¶
Index ¶
- Constants
- type APITest
- func (a *APITest) Debug() *APITest
- func (a *APITest) Delete(url string) *Request
- func (a *APITest) Deletef(format string, args ...interface{}) *Request
- func (a *APITest) EnableMockResponseDelay() *APITest
- func (a *APITest) EnableNetworking(cli ...*http.Client) *APITest
- func (a *APITest) Get(url string) *Request
- func (a *APITest) Getf(format string, args ...interface{}) *Request
- func (a *APITest) Handler(handler http.Handler) *APITest
- func (a *APITest) HandlerFunc(handlerFunc http.HandlerFunc) *APITest
- func (a *APITest) HttpClient(cli *http.Client) *APITest
- func (a *APITest) HttpRequest(req *http.Request) *Request
- func (a *APITest) Intercept(interceptor Intercept) *APITest
- func (a *APITest) Meta(meta map[string]interface{}) *APITest
- func (a *APITest) Method(method string) *Request
- func (a *APITest) Mocks(mocks ...*Mock) *APITest
- func (a *APITest) Observe(observers ...Observe) *APITest
- func (a *APITest) ObserveMocks(observer Observe) *APITest
- func (a *APITest) Patch(url string) *Request
- func (a *APITest) Patchf(format string, args ...interface{}) *Request
- func (a *APITest) Post(url string) *Request
- func (a *APITest) Postf(format string, args ...interface{}) *Request
- func (a *APITest) Put(url string) *Request
- func (a *APITest) Putf(format string, args ...interface{}) *Request
- func (a *APITest) Recorder(recorder *Recorder) *APITest
- func (a *APITest) RecorderHook(hook RecorderHook) *APITest
- func (a *APITest) Report(reporter ReportFormatter) *APITest
- func (a *APITest) Request() *Request
- func (a *APITest) Response() *Response
- func (a *APITest) Verifier(v Verifier) *APITest
- type Assert
- type Cookie
- func (cookie *Cookie) Domain(domain string) *Cookie
- func (cookie *Cookie) Expires(expires time.Time) *Cookie
- func (cookie *Cookie) HttpOnly(httpOnly bool) *Cookie
- func (cookie *Cookie) MaxAge(maxAge int) *Cookie
- func (cookie *Cookie) Path(path string) *Cookie
- func (cookie *Cookie) Secure(secure bool) *Cookie
- func (cookie *Cookie) ToHttpCookie() *http.Cookie
- func (cookie *Cookie) Value(value string) *Cookie
- type DefaultVerifier
- func (a DefaultVerifier) Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func (a DefaultVerifier) Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool
- func (a DefaultVerifier) JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool
- func (a DefaultVerifier) NoError(t TestingT, err error, msgAndArgs ...interface{}) bool
- func (a DefaultVerifier) True(t TestingT, value bool, msgAndArgs ...interface{}) bool
- type Event
- type FinalResponse
- type GraphQLRequestBody
- type HttpRequest
- type HttpResponse
- type InboundRequest
- type Intercept
- type Matcher
- type MessageRequest
- type MessageResponse
- type Mock
- func (m *Mock) Debug() *Mock
- func (m *Mock) Delete(u string) *MockRequest
- func (m *Mock) Deletef(format string, args ...interface{}) *MockRequest
- func (m *Mock) Get(u string) *MockRequest
- func (m *Mock) Getf(format string, args ...interface{}) *MockRequest
- func (m *Mock) Head(u string) *MockRequest
- func (m *Mock) HttpClient(cli *http.Client) *Mock
- func (m *Mock) Matches(req *http.Request) []error
- func (m *Mock) Method(method string) *MockRequest
- func (m *Mock) Patch(u string) *MockRequest
- func (m *Mock) Patchf(format string, args ...interface{}) *MockRequest
- func (m *Mock) Post(u string) *MockRequest
- func (m *Mock) Postf(format string, args ...interface{}) *MockRequest
- func (m *Mock) Put(u string) *MockRequest
- func (m *Mock) Putf(format string, args ...interface{}) *MockRequest
- type MockRequest
- func (r *MockRequest) AddMatcher(matcher Matcher) *MockRequest
- func (r *MockRequest) BasicAuth(username, password string) *MockRequest
- func (r *MockRequest) Body(b string) *MockRequest
- func (r *MockRequest) BodyFromFile(f string) *MockRequest
- func (r *MockRequest) BodyRegexp(b string) *MockRequest
- func (r *MockRequest) Bodyf(format string, args ...interface{}) *MockRequest
- func (r *MockRequest) Cookie(name, value string) *MockRequest
- func (r *MockRequest) CookieNotPresent(name string) *MockRequest
- func (r *MockRequest) CookiePresent(name string) *MockRequest
- func (r *MockRequest) FormData(key string, values ...string) *MockRequest
- func (r *MockRequest) FormDataNotPresent(key string) *MockRequest
- func (r *MockRequest) FormDataPresent(key string) *MockRequest
- func (r *MockRequest) Header(key, value string) *MockRequest
- func (r *MockRequest) HeaderNotPresent(key string) *MockRequest
- func (r *MockRequest) HeaderPresent(key string) *MockRequest
- func (r *MockRequest) Headers(headers map[string]string) *MockRequest
- func (r *MockRequest) JSON(v interface{}) *MockRequest
- func (r *MockRequest) Query(key, value string) *MockRequest
- func (r *MockRequest) QueryCollection(queryParams map[string][]string) *MockRequest
- func (r *MockRequest) QueryNotPresent(key string) *MockRequest
- func (r *MockRequest) QueryParams(queryParams map[string]string) *MockRequest
- func (r *MockRequest) QueryPresent(key string) *MockRequest
- func (r *MockRequest) RespondWith() *MockResponse
- type MockResponse
- func (r *MockResponse) AnyTimes() *MockResponse
- func (r *MockResponse) Body(body string) *MockResponse
- func (r *MockResponse) BodyFromFile(f string) *MockResponse
- func (r *MockResponse) Bodyf(format string, args ...interface{}) *MockResponse
- func (r *MockResponse) Cookie(name, value string) *MockResponse
- func (r *MockResponse) Cookies(cookie ...*Cookie) *MockResponse
- func (r *MockResponse) End() *Mock
- func (r *MockResponse) EndStandalone(other ...*Mock) func()
- func (r *MockResponse) FixedDelay(delay int64) *MockResponse
- func (r *MockResponse) Header(key string, value string) *MockResponse
- func (r *MockResponse) Headers(headers map[string]string) *MockResponse
- func (r *MockResponse) JSON(v interface{}) *MockResponse
- func (r *MockResponse) Status(statusCode int) *MockResponse
- func (r *MockResponse) Timeout() *MockResponse
- func (r *MockResponse) Times(times int) *MockResponse
- type NoopVerifier
- func (n NoopVerifier) Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func (n NoopVerifier) Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool
- func (n NoopVerifier) JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool
- func (n NoopVerifier) NoError(t TestingT, err error, msgAndArgs ...interface{}) bool
- func (n NoopVerifier) True(t TestingT, v bool, msgAndArgs ...interface{}) bool
- type Observe
- type Recorder
- func (r *Recorder) AddHttpRequest(req HttpRequest) *Recorder
- func (r *Recorder) AddHttpResponse(req HttpResponse) *Recorder
- func (r *Recorder) AddMessageRequest(m MessageRequest) *Recorder
- func (r *Recorder) AddMessageResponse(m MessageResponse) *Recorder
- func (r *Recorder) AddMeta(meta map[string]interface{}) *Recorder
- func (r *Recorder) AddSubTitle(subTitle string) *Recorder
- func (r *Recorder) AddTitle(title string) *Recorder
- func (r *Recorder) Reset()
- func (r *Recorder) ResponseStatus() (int, error)
- type RecorderHook
- type ReportFormatter
- type Request
- func (r *Request) BasicAuth(username, password string) *Request
- func (r *Request) Body(b string) *Request
- func (r *Request) BodyFromFile(f string) *Request
- func (r *Request) Bodyf(format string, args ...interface{}) *Request
- func (r *Request) ContentType(contentType string) *Request
- func (r *Request) Cookie(name, value string) *Request
- func (r *Request) Cookies(c ...*Cookie) *Request
- func (r *Request) Expect(t TestingT) *Response
- func (r *Request) FormData(name string, values ...string) *Request
- func (r *Request) GraphQLQuery(query string, variables ...map[string]interface{}) *Request
- func (r *Request) GraphQLRequest(body GraphQLRequestBody) *Request
- func (r *Request) Header(key, value string) *Request
- func (r *Request) Headers(headers map[string]string) *Request
- func (r *Request) JSON(v interface{}) *Request
- func (r *Request) JSONFromFile(f string) *Request
- func (r *Request) MultipartFile(name string, ff ...string) *Request
- func (r *Request) MultipartFormData(name string, values ...string) *Request
- func (r *Request) Query(key, value string) *Request
- func (r *Request) QueryCollection(q map[string][]string) *Request
- func (r *Request) QueryParams(params map[string]string) *Request
- func (r *Request) URL(url string) *Request
- func (r *Request) URLf(format string, args ...interface{}) *Request
- func (r *Request) WithContext(ctx context.Context) *Request
- type Response
- func (r *Response) Assert(fn func(*http.Response, *http.Request) error) *Response
- func (r *Response) Body(b string) *Response
- func (r *Response) BodyFromFile(f string) *Response
- func (r *Response) Bodyf(format string, args ...interface{}) *Response
- func (r *Response) Cookie(name, value string) *Response
- func (r *Response) CookieNotPresent(cookieName string) *Response
- func (r *Response) CookiePresent(cookieName string) *Response
- func (r *Response) Cookies(cookies ...*Cookie) *Response
- func (r *Response) End() Result
- func (r *Response) Header(key, value string) *Response
- func (r *Response) HeaderNotPresent(name string) *Response
- func (r *Response) HeaderPresent(name string) *Response
- func (r *Response) Headers(headers map[string]string) *Response
- func (r *Response) Status(s int) *Response
- type Result
- type SequenceDiagramFormatter
- type StandaloneMocks
- type TestingT
- type Transport
- type UnmatchedMock
- type Verifier
Constants ¶
const ConsumerDefaultName = "cli"
ConsumerDefaultName default consumer name
const SystemUnderTestDefaultName = "sut"
SystemUnderTestDefaultName default name for system under test
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APITest ¶
type APITest struct {
// contains filtered or unexported fields
}
APITest is the top level struct holding the test spec
func Handler ¶ added in v1.5.4
Handler is a convenience method for creating a new apitest with a handler
func HandlerFunc ¶ added in v1.5.4
func HandlerFunc(handlerFunc http.HandlerFunc) *APITest
HandlerFunc is a convenience method for creating a new apitest with a handler func
func (*APITest) Debug ¶
Debug logs to the console the http wire representation of all http interactions that are intercepted by apitest. This includes the inbound request to the application under test, the response returned by the application and any interactions that are intercepted by the mock server.
func (*APITest) Delete ¶ added in v1.0.3
Delete is a convenience method for setting the request as http.MethodDelete
func (*APITest) Deletef ¶ added in v1.4.14
Deletef is a convenience method that adds formatting support to Delete
func (*APITest) EnableMockResponseDelay ¶ added in v1.5.0
EnableMockResponseDelay turns on mock response delays (defaults to OFF)
func (*APITest) EnableNetworking ¶ added in v1.3.0
EnableNetworking will enable networking for provided clients
func (*APITest) Get ¶ added in v1.0.3
Get is a convenience method for setting the request as http.MethodGet
func (*APITest) Getf ¶ added in v1.4.14
Getf is a convenience method that adds formatting support to Get
func (*APITest) HandlerFunc ¶ added in v1.4.5
func (a *APITest) HandlerFunc(handlerFunc http.HandlerFunc) *APITest
HandlerFunc defines the http handler that is invoked when the test is run
func (*APITest) HttpClient ¶
HttpClient allows the developer to provide a custom http client when using mocks
func (*APITest) HttpRequest ¶ added in v1.5.11
HttpRequest defines the native `http.Request`
func (*APITest) Intercept ¶ added in v1.0.3
Intercept is a builder method for setting the request interceptor
func (*APITest) Meta ¶ added in v1.0.2
Meta provides a hook to add custom meta data to the test which can be picked up when defining a custom reporter
func (*APITest) Method ¶ added in v1.0.3
Method is a builder method for setting the http method of the request
func (*APITest) ObserveMocks ¶
ObserveMocks is a builder method for setting the mocks observers
func (*APITest) Patch ¶ added in v1.0.3
Patch is a convenience method for setting the request as http.MethodPatch
func (*APITest) Patchf ¶ added in v1.4.14
Patchf is a convenience method that adds formatting support to Patch
func (*APITest) Post ¶ added in v1.0.3
Post is a convenience method for setting the request as http.MethodPost
func (*APITest) Postf ¶ added in v1.4.14
Postf is a convenience method that adds formatting support to Post
func (*APITest) Put ¶ added in v1.0.3
Put is a convenience method for setting the request as http.MethodPut
func (*APITest) Putf ¶ added in v1.4.14
Putf is a convenience method that adds formatting support to Put
func (*APITest) RecorderHook ¶
func (a *APITest) RecorderHook(hook RecorderHook) *APITest
RecorderHook allows the consumer to provider a function that will receive the recorder instance before the test runs. This can be used to inject custom events which can then be rendered in diagrams Deprecated: use Recorder() instead
func (*APITest) Report ¶ added in v1.0.2
func (a *APITest) Report(reporter ReportFormatter) *APITest
Report provides a hook to add custom formatting to the output of the test
type Assert ¶
Assert is a user defined custom assertion function
var IsClientError Assert = func(response *http.Response, request *http.Request) error { if response.StatusCode >= 400 && response.StatusCode < 500 { return nil } return fmt.Errorf("not a client error. Status code=%d", response.StatusCode) }
IsClientError is a convenience function to assert on a range of client error status codes
var IsServerError Assert = func(response *http.Response, request *http.Request) error { if response.StatusCode >= 500 { return nil } return fmt.Errorf("not a server error. Status code=%d", response.StatusCode) }
IsServerError is a convenience function to assert on a range of server error status codes
var IsSuccess Assert = func(response *http.Response, request *http.Request) error { if response.StatusCode >= 200 && response.StatusCode < 400 { return nil } return fmt.Errorf("not success. Status code=%d", response.StatusCode) }
IsSuccess is a convenience function to assert on a range of happy path status codes
type Cookie ¶
type Cookie struct {
// contains filtered or unexported fields
}
Cookie used to represent an http cookie
func FromHTTPCookie ¶ added in v1.3.10
FromHTTPCookie transforms an http cookie into a Cookie
func (*Cookie) ToHttpCookie ¶
ToHttpCookie transforms the Cookie to an http cookie
type DefaultVerifier ¶ added in v1.5.7
type DefaultVerifier struct{}
DefaultVerifier is a verifier that uses some code from https://github.com/stretchr/testify to perform assertions
func (DefaultVerifier) Equal ¶ added in v1.5.7
func (a DefaultVerifier) Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
func (DefaultVerifier) Fail ¶ added in v1.5.7
func (a DefaultVerifier) Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool
Fail reports a failure
func (DefaultVerifier) JSONEq ¶ added in v1.5.7
func (a DefaultVerifier) JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool
JSONEq asserts that two JSON strings are equivalent
type FinalResponse ¶
type FinalResponse struct {
// contains filtered or unexported fields
}
FinalResponse used to wrap the final response with a timestamp
type GraphQLRequestBody ¶ added in v1.4.10
type GraphQLRequestBody struct { Query string `json:"query"` Variables map[string]interface{} `json:"variables,omitempty"` OperationName string `json:"operationName,omitempty"` }
GraphQLRequestBody represents the POST request body as per the GraphQL spec
type HttpRequest ¶
HttpRequest represents an http request
func (HttpRequest) GetTime ¶
func (r HttpRequest) GetTime() time.Time
GetTime gets the time of the HttpRequest interaction
type HttpResponse ¶
HttpResponse represents an http response
func (HttpResponse) GetTime ¶
func (r HttpResponse) GetTime() time.Time
GetTime gets the time of the HttpResponse interaction
type InboundRequest ¶
type InboundRequest struct {
// contains filtered or unexported fields
}
InboundRequest used to wrap the incoming request with a timestamp
type Intercept ¶
Intercept will be called before the request is made. Updates to the request will be reflected in the test
type Matcher ¶
type Matcher func(*http.Request, *MockRequest) error
Matcher type accepts the actual request and a mock request to match against. Will return an error that describes why there was a mismatch if the inputs do not match or nil if they do.
type MessageRequest ¶
type MessageRequest struct { Source string Target string Header string Body string Timestamp time.Time }
MessageRequest represents a request interaction
func (MessageRequest) GetTime ¶
func (r MessageRequest) GetTime() time.Time
GetTime gets the time of the MessageRequest interaction
type MessageResponse ¶
type MessageResponse struct { Source string Target string Header string Body string Timestamp time.Time }
MessageResponse represents a response interaction
func (MessageResponse) GetTime ¶
func (r MessageResponse) GetTime() time.Time
GetTime gets the time of the MessageResponse interaction
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock represents the entire interaction for a mock to be used for testing
func NewMock ¶
func NewMock() *Mock
NewMock create a new mock, ready for configuration using the builder pattern
func (*Mock) Debug ¶ added in v1.2.0
Debug is used to set debug mode for mocks in standalone mode. This is overridden by the debug setting in the `APITest` struct
func (*Mock) Delete ¶
func (m *Mock) Delete(u string) *MockRequest
Delete configures the mock to match http method DELETE
func (*Mock) Deletef ¶ added in v1.4.15
func (m *Mock) Deletef(format string, args ...interface{}) *MockRequest
Deletef configures the mock to match http method DELETE and supports formatting
func (*Mock) Get ¶
func (m *Mock) Get(u string) *MockRequest
Get configures the mock to match http method GET
func (*Mock) Getf ¶ added in v1.4.15
func (m *Mock) Getf(format string, args ...interface{}) *MockRequest
Getf configures the mock to match http method GET and supports formatting
func (*Mock) Head ¶ added in v1.4.1
func (m *Mock) Head(u string) *MockRequest
Head configures the mock to match http method HEAD
func (*Mock) HttpClient ¶ added in v1.2.0
HttpClient allows the developer to provide a custom http client when using mocks
func (*Mock) Method ¶
func (m *Mock) Method(method string) *MockRequest
Method configures mock to match given http method
func (*Mock) Patch ¶
func (m *Mock) Patch(u string) *MockRequest
Patch configures the mock to match http method PATCH
func (*Mock) Patchf ¶ added in v1.4.15
func (m *Mock) Patchf(format string, args ...interface{}) *MockRequest
Patchf configures the mock to match http method PATCH and supports formatting
func (*Mock) Post ¶
func (m *Mock) Post(u string) *MockRequest
Post configures the mock to match http method POST
func (*Mock) Postf ¶ added in v1.4.15
func (m *Mock) Postf(format string, args ...interface{}) *MockRequest
Postf configures the mock to match http method POST and supports formatting
func (*Mock) Put ¶
func (m *Mock) Put(u string) *MockRequest
Put configures the mock to match http method PUT
func (*Mock) Putf ¶ added in v1.4.15
func (m *Mock) Putf(format string, args ...interface{}) *MockRequest
Putf configures the mock to match http method PUT and supports formatting
type MockRequest ¶
type MockRequest struct {
// contains filtered or unexported fields
}
MockRequest represents the http request side of a mock interaction
func (*MockRequest) AddMatcher ¶ added in v1.1.0
func (r *MockRequest) AddMatcher(matcher Matcher) *MockRequest
AddMatcher configures the mock request to match using a custom matcher
func (*MockRequest) BasicAuth ¶ added in v1.4.6
func (r *MockRequest) BasicAuth(username, password string) *MockRequest
BasicAuth configures the mock request to match the given basic auth parameters
func (*MockRequest) Body ¶
func (r *MockRequest) Body(b string) *MockRequest
Body configures the mock request to match the given body
func (*MockRequest) BodyFromFile ¶ added in v1.4.0
func (r *MockRequest) BodyFromFile(f string) *MockRequest
BodyFromFile configures the mock request to match the given body from a file
func (*MockRequest) BodyRegexp ¶ added in v1.5.6
func (r *MockRequest) BodyRegexp(b string) *MockRequest
BodyRegexp configures the mock request to match the given body using the regexp matcher
func (*MockRequest) Bodyf ¶ added in v1.4.15
func (r *MockRequest) Bodyf(format string, args ...interface{}) *MockRequest
Bodyf configures the mock request to match the given body. Supports formatting the body
func (*MockRequest) Cookie ¶ added in v1.1.5
func (r *MockRequest) Cookie(name, value string) *MockRequest
Cookie configures the mock request to match a cookie
func (*MockRequest) CookieNotPresent ¶ added in v1.1.5
func (r *MockRequest) CookieNotPresent(name string) *MockRequest
CookieNotPresent configures the mock request to match when a cookie is not present
func (*MockRequest) CookiePresent ¶ added in v1.1.5
func (r *MockRequest) CookiePresent(name string) *MockRequest
CookiePresent configures the mock request to match when a cookie is present, regardless of value
func (*MockRequest) FormData ¶ added in v1.3.3
func (r *MockRequest) FormData(key string, values ...string) *MockRequest
FormData configures the mock request to math the given form data
func (*MockRequest) FormDataNotPresent ¶ added in v1.3.3
func (r *MockRequest) FormDataNotPresent(key string) *MockRequest
FormDataNotPresent configures the mock request to match when the form data is not present
func (*MockRequest) FormDataPresent ¶ added in v1.3.3
func (r *MockRequest) FormDataPresent(key string) *MockRequest
FormDataPresent configures the mock request to match when the form data is present, regardless of values
func (*MockRequest) Header ¶
func (r *MockRequest) Header(key, value string) *MockRequest
Header configures the mock request to match the given header
func (*MockRequest) HeaderNotPresent ¶ added in v1.2.1
func (r *MockRequest) HeaderNotPresent(key string) *MockRequest
HeaderNotPresent configures the mock request to match when the header is not present
func (*MockRequest) HeaderPresent ¶ added in v1.2.1
func (r *MockRequest) HeaderPresent(key string) *MockRequest
HeaderPresent configures the mock request to match when this header is present, regardless of value
func (*MockRequest) Headers ¶
func (r *MockRequest) Headers(headers map[string]string) *MockRequest
Headers configures the mock request to match the given headers
func (*MockRequest) JSON ¶ added in v1.5.2
func (r *MockRequest) JSON(v interface{}) *MockRequest
JSON is a convenience method for setting the mock request body
func (*MockRequest) Query ¶
func (r *MockRequest) Query(key, value string) *MockRequest
Query configures the mock request to match a query param
func (*MockRequest) QueryCollection ¶ added in v1.4.6
func (r *MockRequest) QueryCollection(queryParams map[string][]string) *MockRequest
QueryCollection configures the mock request to match a number of repeating query params, e.g. ?a=1&a=2&a=3
func (*MockRequest) QueryNotPresent ¶ added in v1.2.1
func (r *MockRequest) QueryNotPresent(key string) *MockRequest
QueryNotPresent configures the mock request to match when the query param is not present
func (*MockRequest) QueryParams ¶
func (r *MockRequest) QueryParams(queryParams map[string]string) *MockRequest
QueryParams configures the mock request to match a number of query params
func (*MockRequest) QueryPresent ¶
func (r *MockRequest) QueryPresent(key string) *MockRequest
QueryPresent configures the mock request to match when a query param is present, regardless of value
func (*MockRequest) RespondWith ¶
func (r *MockRequest) RespondWith() *MockResponse
RespondWith finalises the mock request phase of set up and allowing the definition of response attributes to be defined
type MockResponse ¶
type MockResponse struct {
// contains filtered or unexported fields
}
MockResponse represents the http response side of a mock interaction
func (*MockResponse) AnyTimes ¶ added in v1.5.17
func (r *MockResponse) AnyTimes() *MockResponse
AnyTimes respond any number of times
func (*MockResponse) Body ¶
func (r *MockResponse) Body(body string) *MockResponse
Body sets the mock response body
func (*MockResponse) BodyFromFile ¶ added in v1.4.0
func (r *MockResponse) BodyFromFile(f string) *MockResponse
BodyFromFile defines the mock response body from a file
func (*MockResponse) Bodyf ¶ added in v1.4.15
func (r *MockResponse) Bodyf(format string, args ...interface{}) *MockResponse
Bodyf sets the mock response body. Supports formatting
func (*MockResponse) Cookie ¶
func (r *MockResponse) Cookie(name, value string) *MockResponse
Cookie respond with the given cookie
func (*MockResponse) Cookies ¶
func (r *MockResponse) Cookies(cookie ...*Cookie) *MockResponse
Cookies respond with the given cookies
func (*MockResponse) End ¶
func (r *MockResponse) End() *Mock
End finalise the response definition phase in order for the mock to be used
func (*MockResponse) EndStandalone ¶ added in v1.2.0
func (r *MockResponse) EndStandalone(other ...*Mock) func()
EndStandalone finalises the response definition of standalone mocks
func (*MockResponse) FixedDelay ¶ added in v1.5.0
func (r *MockResponse) FixedDelay(delay int64) *MockResponse
FixedDelay will return the response after the given number of milliseconds. APITest::EnableMockResponseDelay must be set for this to take effect. If Timeout is set this has no effect.
func (*MockResponse) Header ¶
func (r *MockResponse) Header(key string, value string) *MockResponse
Header respond with the given header
func (*MockResponse) Headers ¶
func (r *MockResponse) Headers(headers map[string]string) *MockResponse
Headers respond with the given headers
func (*MockResponse) JSON ¶ added in v1.5.2
func (r *MockResponse) JSON(v interface{}) *MockResponse
JSON is a convenience method for setting the mock response body
func (*MockResponse) Status ¶
func (r *MockResponse) Status(statusCode int) *MockResponse
Status respond with the given status
func (*MockResponse) Timeout ¶ added in v1.4.11
func (r *MockResponse) Timeout() *MockResponse
Timeout forces the mock to return a http timeout
func (*MockResponse) Times ¶
func (r *MockResponse) Times(times int) *MockResponse
Times respond the given number of times, if AnyTimes is set this has no effect
type NoopVerifier ¶ added in v1.3.8
type NoopVerifier struct{}
NoopVerifier is a verifier that does not perform verification
func (NoopVerifier) Equal ¶ added in v1.3.8
func (n NoopVerifier) Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
Equal does not perform any assertion and always returns true
func (NoopVerifier) Fail ¶ added in v1.3.8
func (n NoopVerifier) Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool
Fail does not perform any assertion and always returns true
func (NoopVerifier) JSONEq ¶ added in v1.3.8
func (n NoopVerifier) JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool
JSONEq does not perform any assertion and always returns true
type Recorder ¶
Recorder represents all of the report data
func (*Recorder) AddHttpRequest ¶
func (r *Recorder) AddHttpRequest(req HttpRequest) *Recorder
AddHttpRequest add an http request to recorder
func (*Recorder) AddHttpResponse ¶
func (r *Recorder) AddHttpResponse(req HttpResponse) *Recorder
AddHttpResponse add an HttpResponse to the recorder
func (*Recorder) AddMessageRequest ¶
func (r *Recorder) AddMessageRequest(m MessageRequest) *Recorder
AddMessageRequest add a MessageRequest to the recorder
func (*Recorder) AddMessageResponse ¶
func (r *Recorder) AddMessageResponse(m MessageResponse) *Recorder
AddMessageResponse add a MessageResponse to the recorder
func (*Recorder) AddSubTitle ¶
AddSubTitle add a SubTitle to the recorder
func (*Recorder) Reset ¶ added in v1.2.2
func (r *Recorder) Reset()
Reset resets the recorder to default starting state
func (*Recorder) ResponseStatus ¶
ResponseStatus get response status of the recorder, returning an error when this wasn't possible
type RecorderHook ¶
type RecorderHook func(*Recorder)
RecorderHook used to implement a custom interaction recorder
type ReportFormatter ¶
type ReportFormatter interface { // Format formats the events received from the recorder Format(*Recorder) }
ReportFormatter represents the report formatter
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is the user defined request that will be invoked on the handler under test
func (*Request) BodyFromFile ¶ added in v1.4.0
BodyFromFile is a builder method to set the request body
func (*Request) ContentType ¶ added in v1.3.3
ContentType is a builder method to set the Content-Type header of the request
func (*Request) Cookie ¶
Cookie is a convenience method for setting a single request cookies by name and value
func (*Request) Expect ¶
Expect marks the request spec as complete and following code will define the expected response
func (*Request) FormData ¶ added in v1.3.3
FormData is a builder method to set the body form data Also sets the content type of the request to application/x-www-form-urlencoded
func (*Request) GraphQLQuery ¶ added in v1.4.10
GraphQLQuery is a convenience method for building a graphql POST request
func (*Request) GraphQLRequest ¶ added in v1.4.10
func (r *Request) GraphQLRequest(body GraphQLRequestBody) *Request
GraphQLRequest builds a graphql POST request
func (*Request) JSON ¶
JSON is a convenience method for setting the request body and content type header as "application/json". If v is not a string or []byte it will marshall the provided variable as json
func (*Request) JSONFromFile ¶ added in v1.4.0
JSONFromFile is a convenience method for setting the request body and content type header as "application/json"
func (*Request) MultipartFile ¶ added in v1.5.12
MultipartFile is a builder method to set the file in multipart form data Also sets the content type of the request to multipart/form-data
func (*Request) MultipartFormData ¶ added in v1.5.12
MultipartFormData is a builder method to set the field in multipart form data Also sets the content type of the request to multipart/form-data
func (*Request) QueryCollection ¶
QueryCollection is a builder method to set the request query parameters This can be used in combination with request.Query
func (*Request) QueryParams ¶
QueryParams is a builder method to set the request query parameters. This can be used in combination with request.QueryCollection
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is the user defined expected response from the application under test
func (*Response) Assert ¶
Assert allows the consumer to provide a user defined function containing their own custom assertions
func (*Response) BodyFromFile ¶ added in v1.4.0
BodyFromFile reads the given file and uses the content as the expected response body
func (*Response) Bodyf ¶ added in v1.4.14
Bodyf is the expected response body that supports a formatter
func (*Response) Cookie ¶ added in v1.0.12
Cookie is used to match on an individual cookie name/value pair in the expected response cookies
func (*Response) CookieNotPresent ¶
CookieNotPresent is used to assert that a cookie is not present in the response
func (*Response) CookiePresent ¶
CookiePresent is used to assert that a cookie is present in the response, regardless of its value
func (*Response) HeaderNotPresent ¶ added in v1.1.5
HeaderNotPresent is a builder method to set the request headers that should not be present in the response
func (*Response) HeaderPresent ¶ added in v1.1.5
HeaderPresent is a builder method to set the request headers that should be present in the response
type Result ¶ added in v1.1.5
Result provides the final result
func (Result) JSON ¶ added in v1.3.1
func (r Result) JSON(t interface{})
JSON unmarshal the result response body to a valid struct
func (Result) UnmatchedMocks ¶ added in v1.4.9
func (r Result) UnmatchedMocks() []UnmatchedMock
UnmatchedMocks returns any mocks that were not used, e.g. there was not a matching http Request for the mock
type SequenceDiagramFormatter ¶
type SequenceDiagramFormatter struct {
// contains filtered or unexported fields
}
SequenceDiagramFormatter implementation of a ReportFormatter
func SequenceDiagram ¶ added in v1.0.2
func SequenceDiagram(path ...string) *SequenceDiagramFormatter
SequenceDiagram produce a sequence diagram at the given path or .sequence by default
func (*SequenceDiagramFormatter) Format ¶
func (r *SequenceDiagramFormatter) Format(recorder *Recorder)
Format formats the events received by the recorder
type StandaloneMocks ¶ added in v1.3.2
type StandaloneMocks struct {
// contains filtered or unexported fields
}
StandaloneMocks for using mocks outside of API tests context
func NewStandaloneMocks ¶ added in v1.3.2
func NewStandaloneMocks(mocks ...*Mock) *StandaloneMocks
NewStandaloneMocks create a series of StandaloneMocks
func (*StandaloneMocks) Debug ¶ added in v1.3.2
func (r *StandaloneMocks) Debug() *StandaloneMocks
Debug switch on debugging mode
func (*StandaloneMocks) End ¶ added in v1.3.2
func (r *StandaloneMocks) End() func()
End finalises the mock, ready for use
func (*StandaloneMocks) HttpClient ¶ added in v1.3.2
func (r *StandaloneMocks) HttpClient(cli *http.Client) *StandaloneMocks
HttpClient use the given http client
type TestingT ¶ added in v1.5.2
type TestingT interface { Errorf(format string, args ...interface{}) Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) }
TestingT is an interface to wrap the native *testing.T interface, this allows integration with GinkgoT() interface GinkgoT interface defined in https://github.com/onsi/ginkgo/blob/55c858784e51c26077949c81b6defb6b97b76944/ginkgo_dsl.go#L91
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport wraps components used to observe and manipulate the real request and response objects
func (*Transport) Hijack ¶
func (r *Transport) Hijack()
Hijack replace the transport implementation of the interaction under test in order to observe, mock and inject expectations
type UnmatchedMock ¶ added in v1.4.9
UnmatchedMock exposes some information about mocks that failed to match a request
type Verifier ¶ added in v1.3.8
type Verifier interface { Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool True(t TestingT, value bool, msgAndArgs ...interface{}) bool JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool NoError(t TestingT, err error, msgAndArgs ...interface{}) bool }
Verifier is the assertion interface allowing consumers to inject a custom assertion implementation. It also allows failure scenarios to be tested within apitest