Documentation
¶
Index ¶
- Constants
- type APITest
- func (a *APITest) BuildRequest() *http.Request
- func (a *APITest) Debug() *APITest
- func (a *APITest) Handler(handler http.Handler) *Request
- func (a *APITest) HttpClient(cli *http.Client) *APITest
- func (a *APITest) Mocks(mocks ...*Mock) *APITest
- func (a *APITest) Observe(observers ...Observe) *APITest
- func (a *APITest) ObserveMocks(observer Observe) *APITest
- func (a *APITest) RecorderHook(hook RecorderHook) *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
- type MockRequest
- func (r *MockRequest) Body(b string) *MockRequest
- func (r *MockRequest) Header(key, value string) *MockRequest
- func (r *MockRequest) Headers(headers map[string]string) *MockRequest
- func (r *MockRequest) Query(key, value 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) 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(auth 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) Delete(url string) *Request
- func (r *Request) Expect(t *testing.T) *Response
- func (r *Request) Get(url string) *Request
- func (r *Request) GetHost() string
- func (r *Request) Header(key, value string) *Request
- func (r *Request) Headers(headers map[string]string) *Request
- func (r *Request) Host(host string) *Request
- func (r *Request) Intercept(interceptor Intercept) *Request
- func (r *Request) JSON(b string) *Request
- func (r *Request) Method(method string) *Request
- func (r *Request) Patch(url string) *Request
- func (r *Request) Post(url string) *Request
- func (r *Request) Put(url 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) CookieNotPresent(cookieName string) *Response
- func (r *Response) CookiePresent(cookieName string) *Response
- func (r *Response) Cookies(cookies ...*Cookie) *Response
- func (r *Response) End()
- func (r *Response) Header(key, value string) *Response
- func (r *Response) Headers(headers map[string]string) *Response
- func (r *Response) Report(formatter ...ReportFormatter)
- func (r *Response) Status(s int) *Response
- 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) HttpClient ¶
HttpClient allows the developer to provide a custom http client when using mocks
func (*APITest) ObserveMocks ¶
ObserveMocks is a builder method for setting the mocks observers
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
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("not a client error. Status code=" + strconv.Itoa(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("not a server error. Status code=" + strconv.Itoa(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("not a client error. Status code=" + strconv.Itoa(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 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) Delete ¶
func (m *Mock) Delete(u string) *MockRequest
func (*Mock) Get ¶
func (m *Mock) Get(u string) *MockRequest
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) Body ¶
func (r *MockRequest) Body(b string) *MockRequest
func (*MockRequest) Header ¶
func (r *MockRequest) Header(key, value 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) 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) 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 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) BasicAuth ¶
BasicAuth is a builder method to sets basic auth on the request. The credentials should be provided delimited by a colon, e.g. "username:password"
func (*Request) Cookie ¶
Cookie is a convenience method for setting a single request cookies by name and value
func (*Request) Delete ¶
Delete is a convenience method for setting the request as http.MethodDelete
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) 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) Report ¶
func (r *Response) Report(formatter ...ReportFormatter)
type SequenceDiagramFormatter ¶
type SequenceDiagramFormatter struct {
// contains filtered or unexported fields
}
func NewSequenceDiagramFormatter ¶
func NewSequenceDiagramFormatter(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