Documentation
¶
Index ¶
- Variables
- func DoHTTP(ctx context.Context, h http.Handler, req *http.Request) *http.Response
- func Equal(t *testing.T, a, b interface{})
- func ErrorHasMessage(t *testing.T, err error, msg string)
- func GQLError(t *testing.T, r *simplejson.JSON, errMsg string)
- func HTTPGet(t *testing.T, h http.Handler, path string, params map[string]string, ...)
- func HTTPGetError(t *testing.T, h http.Handler, code int, path string, params map[string]string)
- func HTTPPost(t *testing.T, h http.Handler, path string, params map[string]string, ...)
- func HTTPPostError(t *testing.T, h http.Handler, code int, path string, params map[string]string, ...)
- func JSONEqual(t *testing.T, actual interface{}, expected interface{})
- func JSONGet(t *testing.T, j *simplejson.JSON, path []string) *simplejson.JSON
- func JSONHasStr(t *testing.T, actual interface{}, needle string)
- func JSONText(t *testing.T, actual interface{}, expected string, opts ...JSONOpt)
- func NewRequest(method, path string) *http.Request
- func StrEqual(t *testing.T, a, b string)
- type FormDataField
- type HTTPParams
- func (p HTTPParams) Delete() HTTPParams
- func (p HTTPParams) Do(t *testing.T, h http.Handler)
- func (p HTTPParams) ExpectCode(c int) HTTPParams
- func (p HTTPParams) File(fieldName, fileName string, fileContent []byte) HTTPParams
- func (p HTTPParams) FormData(fields map[string]FormDataField) HTTPParams
- func (p HTTPParams) JSON(j interface{}) HTTPParams
- func (p HTTPParams) ModifyRequest(modifier func(*http.Request)) HTTPParams
- func (p HTTPParams) Post() HTTPParams
- func (p HTTPParams) Put() HTTPParams
- func (p HTTPParams) QueryParam(key, value string) HTTPParams
- func (p HTTPParams) QueryParams(vs map[string]string) HTTPParams
- func (p HTTPParams) RedirectTo(s *string) HTTPParams
- func (p HTTPParams) Return(r interface{}) HTTPParams
- func (p HTTPParams) SetContext(ctx context.Context) HTTPParams
- func (p HTTPParams) SetFormBody(v url.Values) HTTPParams
- func (p HTTPParams) SetHeader(header http.Header) HTTPParams
- func (p HTTPParams) SetHost(host string) HTTPParams
- func (p HTTPParams) Visit(path string) HTTPParams
- func (p HTTPParams) WithCookieJar(jar *cookiejar.Jar) HTTPParams
- type JSONOpt
- type RequestSummary
Constants ¶
This section is empty.
Variables ¶
var Contains = assert.Contains
Contains is assert.Contains.
var NoError = assert.NoError
NoError is assert.NoError.
var NotEmpty = assert.NotEmpty
NotEmpty is assert.NotEmpty.
var NotEqual = assert.NotEqual
NotEqual is assert.NotEqual.
var True = assert.True
True is assert.True.
Functions ¶
func ErrorHasMessage ¶
ErrorHasMessage asserts err.Error() contains a msg as substring.
func GQLError ¶
func GQLError(t *testing.T, r *simplejson.JSON, errMsg string)
GQLError asserts the given graphql result contains some error message.
func HTTPGet ¶
func HTTPGet(t *testing.T, h http.Handler, path string, params map[string]string, result interface{})
HTTPGet is a convenient method for HTTP. Prefer to use HTTP direclty in new code.
func HTTPGetError ¶
HTTPGetError is a convenient method for HTTP. Prefer to use HTTP direclty in new code.
func HTTPPost ¶
func HTTPPost(t *testing.T, h http.Handler, path string, params map[string]string, body, result interface{})
HTTPPost is a convenient method for HTTP. Prefer to use HTTP direclty in new code.
func HTTPPostError ¶
func HTTPPostError(t *testing.T, h http.Handler, code int, path string, params map[string]string, body, result interface{})
HTTPPostError is a convenient method for HTTP. Prefer to use HTTP direclty in new code.
func JSONGet ¶
func JSONGet(t *testing.T, j *simplejson.JSON, path []string) *simplejson.JSON
JSONGet extract values at path, if nil, failed.
func JSONHasStr ¶
JSONHasStr asserts the object when converted to json, contains given string. Most useful for error assertion.
func NewRequest ¶
NewRequest creates an HTTP request.
Types ¶
type FormDataField ¶
FormDataField specifies a single form data field.
type HTTPParams ¶
type HTTPParams struct { Method string Path string Query map[string]string FormValues map[string]string ExpectedCode int Body bytes.Buffer ContentType string Result interface{} CookieJar *cookiejar.Jar Host string FinalPath *string Header http.Header RequestModifier func(*http.Request) Ctx context.Context }
HTTPParams encode optional params for HTTP method.
func (HTTPParams) Do ¶
func (p HTTPParams) Do(t *testing.T, h http.Handler)
Do makes a http request and verify some common behavior.
func (HTTPParams) ExpectCode ¶
func (p HTTPParams) ExpectCode(c int) HTTPParams
ExpectCode sets the expected status code.
func (HTTPParams) File ¶
func (p HTTPParams) File(fieldName, fileName string, fileContent []byte) HTTPParams
File attaches a file to the request.
func (HTTPParams) FormData ¶
func (p HTTPParams) FormData(fields map[string]FormDataField) HTTPParams
FormData attaches form data.
func (HTTPParams) JSON ¶
func (p HTTPParams) JSON(j interface{}) HTTPParams
JSON attaches a json body to the request.
func (HTTPParams) ModifyRequest ¶
func (p HTTPParams) ModifyRequest(modifier func(*http.Request)) HTTPParams
ModifyRequest sets request modifier.
func (HTTPParams) QueryParam ¶
func (p HTTPParams) QueryParam(key, value string) HTTPParams
QueryParam sets a single query param.
func (HTTPParams) QueryParams ¶
func (p HTTPParams) QueryParams(vs map[string]string) HTTPParams
QueryParams sets multipe query params.
func (HTTPParams) RedirectTo ¶
func (p HTTPParams) RedirectTo(s *string) HTTPParams
RedirectTo returns the final path after redirections.
func (HTTPParams) Return ¶
func (p HTTPParams) Return(r interface{}) HTTPParams
Return sets the result.
func (HTTPParams) SetContext ¶
func (p HTTPParams) SetContext(ctx context.Context) HTTPParams
func (HTTPParams) SetFormBody ¶
func (p HTTPParams) SetFormBody(v url.Values) HTTPParams
SetFormBody attach a post form to the request.
func (HTTPParams) SetHeader ¶
func (p HTTPParams) SetHeader(header http.Header) HTTPParams
SetHeader sets header in request.
func (HTTPParams) SetHost ¶
func (p HTTPParams) SetHost(host string) HTTPParams
SetHost set host in request.
func (HTTPParams) WithCookieJar ¶
func (p HTTPParams) WithCookieJar(jar *cookiejar.Jar) HTTPParams
WithCookieJar access cookies from the jar.
type JSONOpt ¶
type JSONOpt struct {
IgnoreArrayOrder []string
}
JSONOpt is options for comparing JSON.
type RequestSummary ¶
RequestSummary is a summary of http.Request.
func NewRequestSummary ¶
func NewRequestSummary(req *http.Request) RequestSummary
NewRequestSummary creates a RequestSummary.