Documentation
¶
Index ¶
- Constants
- type APITest
- func (a *APITest) BuildRequest() *http.Request
- func (a *APITest) Debug() *APITest
- func (a *APITest) Delete(url string) *Request
- func (a *APITest) Get(url string) *Request
- func (a *APITest) Handler(handler http.Handler) *APITest
- func (a *APITest) HttpClient(cli *http.Client) *APITest
- 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) Post(url string) *Request
- func (a *APITest) Put(url string) *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
- 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 Event
- type FinalResponse
- type HTMLTemplateModel
- type HttpRequest
- type HttpResponse
- type InboundRequest
- type Intercept
- type LogEntry
- type Matcher
- type MessageRequest
- type MessageResponse
- type Mock
- func (m *Mock) Debug() *Mock
- func (m *Mock) Delete(u string) *MockRequest
- func (m *Mock) Get(u string) *MockRequest
- func (m *Mock) HttpClient(cli *http.Client) *Mock
- func (m *Mock) Method(method string) *MockRequest
- func (m *Mock) Patch(u string) *MockRequest
- func (m *Mock) Post(u string) *MockRequest
- func (m *Mock) Put(u string) *MockRequest
- type MockRequest
- func (r *MockRequest) AddMatcher(matcher Matcher) *MockRequest
- func (r *MockRequest) Body(b string) *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) 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) Query(key, value 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) Body(body string) *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() func()
- func (r *MockResponse) Header(key string, value string) *MockResponse
- func (r *MockResponse) Headers(headers map[string]string) *MockResponse
- func (r *MockResponse) Status(statusCode int) *MockResponse
- func (r *MockResponse) Times(times int) *MockResponse
- 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) 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) Cookie(name, value string) *Request
- func (r *Request) Cookies(c ...*Cookie) *Request
- func (r *Request) Expect(t *testing.T) *Response
- func (r *Request) Header(key, value string) *Request
- func (r *Request) Headers(headers map[string]string) *Request
- func (r *Request) JSON(b 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
- type Response
- func (r *Response) Assert(fn func(*http.Response, *http.Request) error) *Response
- func (r *Response) Body(b string) *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 Transport
- type WebSequenceDiagramDSL
Constants ¶
const Template = `` /* 2256-byte string literal not displayed */
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 (*APITest) BuildRequest ¶
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) Get ¶ added in v1.0.3
Get is a convenience method for setting the request as http.MethodGet
func (*APITest) HttpClient ¶
HttpClient allows the developer to provide a custom http client when using mocks
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) Post ¶ added in v1.0.3
Post is a convenience method for setting the request as http.MethodPost
func (*APITest) Put ¶ added in v1.0.3
Put is a convenience method for setting the request as http.MethodPut
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
Reporter 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 errors.New(fmt.Sprintf("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 errors.New(fmt.Sprintf("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 errors.New(fmt.Sprintf("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
}
func (*Cookie) ToHttpCookie ¶
type FinalResponse ¶
type FinalResponse struct {
// contains filtered or unexported fields
}
type HTMLTemplateModel ¶
type HTMLTemplateModel struct { Title string SubTitle string StatusCode int BadgeClass string LogEntries []LogEntry WebSequenceDSL string MetaJSON template.JS }
func NewHTMLTemplateModel ¶
func NewHTMLTemplateModel(r *Recorder) (HTMLTemplateModel, error)
type HttpRequest ¶
func (HttpRequest) GetTime ¶
func (r HttpRequest) GetTime() time.Time
type HttpResponse ¶
func (HttpResponse) GetTime ¶
func (r HttpResponse) GetTime() time.Time
type InboundRequest ¶
type InboundRequest struct {
// contains filtered or unexported fields
}
type Intercept ¶
Intercept will be called before the request is made. Updates to the request will be reflected in the test
type LogEntry ¶
func NewHttpRequestLogEntry ¶ added in v1.0.6
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 }
func (MessageRequest) GetTime ¶
func (r MessageRequest) GetTime() time.Time
type MessageResponse ¶
type MessageResponse struct { Source string Target string Header string Body string Timestamp time.Time }
func (MessageResponse) GetTime ¶
func (r MessageResponse) GetTime() time.Time
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
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
func (*Mock) Get ¶
func (m *Mock) Get(u string) *MockRequest
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
func (*Mock) Patch ¶
func (m *Mock) Patch(u string) *MockRequest
func (*Mock) Post ¶
func (m *Mock) Post(u string) *MockRequest
func (*Mock) Put ¶
func (m *Mock) Put(u string) *MockRequest
type MockRequest ¶
type MockRequest struct {
// contains filtered or unexported fields
}
func (*MockRequest) AddMatcher ¶ added in v1.1.0
func (r *MockRequest) AddMatcher(matcher Matcher) *MockRequest
func (*MockRequest) Body ¶
func (r *MockRequest) Body(b string) *MockRequest
func (*MockRequest) Cookie ¶ added in v1.1.5
func (r *MockRequest) Cookie(name, value string) *MockRequest
func (*MockRequest) CookieNotPresent ¶ added in v1.1.5
func (r *MockRequest) CookieNotPresent(name string) *MockRequest
func (*MockRequest) CookiePresent ¶ added in v1.1.5
func (r *MockRequest) CookiePresent(name string) *MockRequest
func (*MockRequest) Header ¶
func (r *MockRequest) Header(key, value string) *MockRequest
func (*MockRequest) HeaderNotPresent ¶ added in v1.2.1
func (r *MockRequest) HeaderNotPresent(key string) *MockRequest
func (*MockRequest) HeaderPresent ¶ added in v1.2.1
func (r *MockRequest) HeaderPresent(key string) *MockRequest
func (*MockRequest) Headers ¶
func (r *MockRequest) Headers(headers map[string]string) *MockRequest
func (*MockRequest) Query ¶
func (r *MockRequest) Query(key, value string) *MockRequest
func (*MockRequest) QueryNotPresent ¶ added in v1.2.1
func (r *MockRequest) QueryNotPresent(key string) *MockRequest
func (*MockRequest) QueryParams ¶
func (r *MockRequest) QueryParams(queryParams map[string]string) *MockRequest
func (*MockRequest) QueryPresent ¶
func (r *MockRequest) QueryPresent(key string) *MockRequest
func (*MockRequest) RespondWith ¶
func (r *MockRequest) RespondWith() *MockResponse
type MockResponse ¶
type MockResponse struct {
// contains filtered or unexported fields
}
func (*MockResponse) Body ¶
func (r *MockResponse) Body(body string) *MockResponse
func (*MockResponse) Cookie ¶
func (r *MockResponse) Cookie(name, value string) *MockResponse
func (*MockResponse) Cookies ¶
func (r *MockResponse) Cookies(cookie ...*Cookie) *MockResponse
func (*MockResponse) End ¶
func (r *MockResponse) End() *Mock
func (*MockResponse) EndStandalone ¶ added in v1.2.0
func (r *MockResponse) EndStandalone() func()
func (*MockResponse) Header ¶
func (r *MockResponse) Header(key string, value string) *MockResponse
func (*MockResponse) Headers ¶
func (r *MockResponse) Headers(headers map[string]string) *MockResponse
func (*MockResponse) Status ¶
func (r *MockResponse) Status(statusCode int) *MockResponse
func (*MockResponse) Times ¶
func (r *MockResponse) Times(times int) *MockResponse
type Recorder ¶
func NewTestRecorder ¶
func NewTestRecorder() *Recorder
func (*Recorder) AddHttpRequest ¶
func (r *Recorder) AddHttpRequest(req HttpRequest) *Recorder
func (*Recorder) AddHttpResponse ¶
func (r *Recorder) AddHttpResponse(req HttpResponse) *Recorder
func (*Recorder) AddMessageRequest ¶
func (r *Recorder) AddMessageRequest(m MessageRequest) *Recorder
func (*Recorder) AddMessageResponse ¶
func (r *Recorder) AddMessageResponse(m MessageResponse) *Recorder
func (*Recorder) AddSubTitle ¶
func (*Recorder) ResponseStatus ¶
type RecorderHook ¶
type RecorderHook func(*Recorder)
type ReportFormatter ¶
type ReportFormatter interface {
Format(*Recorder)
}
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) 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) JSON ¶
JSON is a convenience method for setting the request body and content type header as "application/json"
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) 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 SequenceDiagramFormatter ¶
type SequenceDiagramFormatter struct {
// contains filtered or unexported fields
}
func SequenceDiagram ¶ added in v1.0.2
func SequenceDiagram(path ...string) *SequenceDiagramFormatter
func (*SequenceDiagramFormatter) Format ¶
func (r *SequenceDiagramFormatter) Format(recorder *Recorder)
type WebSequenceDiagramDSL ¶
type WebSequenceDiagramDSL struct {
// contains filtered or unexported fields
}
func (*WebSequenceDiagramDSL) AddRequestRow ¶
func (r *WebSequenceDiagramDSL) AddRequestRow(source string, target string, description string)
func (*WebSequenceDiagramDSL) AddResponseRow ¶
func (r *WebSequenceDiagramDSL) AddResponseRow(source string, target string, description string)
func (*WebSequenceDiagramDSL) ToString ¶
func (r *WebSequenceDiagramDSL) ToString() string