Documentation ¶
Index ¶
- Variables
- type Case
- type Fail
- type Failer
- type HTMLAsserter
- func (ha *HTMLAsserter) AssertAll(selector string) *HTMLAsserter
- func (ha *HTMLAsserter) Attr(n, exp string) *HTMLAsserter
- func (ha *HTMLAsserter) Check(c HTMLChecker) *HTMLAsserter
- func (ha *HTMLAsserter) Count(exp int) *HTMLAsserter
- func (ha *HTMLAsserter) Text(exp string) *HTMLAsserter
- func (ha *HTMLAsserter) TextMatch(expr string) *HTMLAsserter
- type HTMLChecker
- type HTMLCheckerFunc
- type RequestBuilder
- type ResponseAsserter
- func (ra *ResponseAsserter) BodySize(exp int) *ResponseAsserter
- func (ra *ResponseAsserter) Check(c ResponseChecker) *ResponseAsserter
- func (ra *ResponseAsserter) HTML() *HTMLAsserter
- func (ra *ResponseAsserter) Header(k, exp string) *ResponseAsserter
- func (ra *ResponseAsserter) Status(c int) *ResponseAsserter
- type ResponseChecker
- type ResponseCheckerFunc
Constants ¶
This section is empty.
Variables ¶
var ErrTestFail = errors.New("test fail")
ErrTestFail is thrown when the failer fails for testing
var TruncateBodyLength = 512
TruncateBodyLength is the length after which the rest of the response print will be ignored and replaced with ...
Functions ¶
This section is empty.
Types ¶
type Case ¶
type Case struct {
// contains filtered or unexported fields
}
Case represents a set of assertions for an http.Handler
func (*Case) GET ¶
func (c *Case) GET(p string) *RequestBuilder
GET will start the building of a GET request
func (*Case) POST ¶
func (c *Case) POST(p string) *RequestBuilder
POST will start the building of a POST request
type Fail ¶
type Fail struct { FF func(format string, args ...interface{}) // contains filtered or unexported fields }
Fail is a failer implementation that cals FF on fatalf
func NewStdFail ¶
NewStdFail will fail using the standard library tb interface
func NewTestFail ¶
NewTestFail gives a failer that will panic and write to a buffer
func (*Fail) WithRequest ¶
WithRequest will configure the fail in context of the request
func (*Fail) WithResponse ¶
func (f *Fail) WithResponse(w *httptest.ResponseRecorder) Failer
WithResponse will configure the fail in context of this response
type Failer ¶
type Failer interface { Fatalf(format string, args ...interface{}) WithRequest(*http.Request) Failer WithResponse(*httptest.ResponseRecorder) Failer WithHTML(sel *goquery.Selection) Failer Copy() Failer }
Failer is used to fail cases with extra context that should help the developer figure out what went wrong.
type HTMLAsserter ¶
HTMLAsserter asserts (parts of) an HTML document
func (*HTMLAsserter) AssertAll ¶
func (ha *HTMLAsserter) AssertAll(selector string) *HTMLAsserter
AssertAll will return a new asserter that allows for checking ALL elements that match the selector.
func (*HTMLAsserter) Attr ¶
func (ha *HTMLAsserter) Attr(n, exp string) *HTMLAsserter
Attr will assert of the attribute named 'n' has expected value 'exp'
func (*HTMLAsserter) Check ¶ added in v0.2.0
func (ha *HTMLAsserter) Check(c HTMLChecker) *HTMLAsserter
Check allows for checking the response using resuable custom logic
func (*HTMLAsserter) Count ¶
func (ha *HTMLAsserter) Count(exp int) *HTMLAsserter
Count asserts how many elements there are to be expected
func (*HTMLAsserter) Text ¶
func (ha *HTMLAsserter) Text(exp string) *HTMLAsserter
Text will assert that the text context of the selection equals 'exp'
func (*HTMLAsserter) TextMatch ¶
func (ha *HTMLAsserter) TextMatch(expr string) *HTMLAsserter
TextMatch will assert that the text in the selection matches the pattern
type HTMLChecker ¶ added in v0.2.0
HTMLChecker can be implemented to check HTML through custom logic
type HTMLCheckerFunc ¶ added in v0.2.0
HTMLCheckerFunc allows for casting a function to implement the HTMLChecker
type RequestBuilder ¶
type RequestBuilder struct {
// contains filtered or unexported fields
}
RequestBuilder allows building a request for a testcase
func (*RequestBuilder) EXPECT ¶
func (rb *RequestBuilder) EXPECT() *ResponseAsserter
EXPECT will create and perform the request on the case's http handler and return an asserter for the http response.
func (*RequestBuilder) WithFormData ¶
func (rb *RequestBuilder) WithFormData(pairs ...string) *RequestBuilder
WithFormData will set the requests' body to the form encoded shape of the provided key value pairs and set the content type to
func (*RequestBuilder) WithHeader ¶
func (rb *RequestBuilder) WithHeader(k, v string) *RequestBuilder
WithHeader sets a header value for the request building
func (*RequestBuilder) WithHeaders ¶
func (rb *RequestBuilder) WithHeaders(pairs ...string) *RequestBuilder
WithHeaders allows adding headers as string pairs
type ResponseAsserter ¶
type ResponseAsserter struct {
// contains filtered or unexported fields
}
ResponseAsserter allows for asserting an http response
func (*ResponseAsserter) BodySize ¶
func (ra *ResponseAsserter) BodySize(exp int) *ResponseAsserter
BodySize asserts the size of the response body
func (*ResponseAsserter) Check ¶ added in v0.2.0
func (ra *ResponseAsserter) Check(c ResponseChecker) *ResponseAsserter
Check allows for checking the response using resuable custom logic
func (*ResponseAsserter) HTML ¶
func (ra *ResponseAsserter) HTML() *HTMLAsserter
HTML will parse the response body as html and return an asserter for it
func (*ResponseAsserter) Header ¶
func (ra *ResponseAsserter) Header(k, exp string) *ResponseAsserter
Header asserts that the header 'k' equals 'exp'
func (*ResponseAsserter) Status ¶
func (ra *ResponseAsserter) Status(c int) *ResponseAsserter
Status asserts that the status equal c
type ResponseChecker ¶ added in v0.2.0
type ResponseChecker interface {
CheckResponse(f Failer, rec *httptest.ResponseRecorder)
}
ResponseChecker can be implemented to check responses through custom logic
type ResponseCheckerFunc ¶ added in v0.2.0
type ResponseCheckerFunc func(f Failer, rec *httptest.ResponseRecorder)
ResponseCheckerFunc allows casing a function to implement the ResponseChecker
func (ResponseCheckerFunc) CheckResponse ¶ added in v0.2.0
func (f ResponseCheckerFunc) CheckResponse(fail Failer, rec *httptest.ResponseRecorder)
CheckResponse implements ResponseChecker