Documentation ¶
Index ¶
- type Client
- func (c *Client) Close()
- func (c *Client) Cookies() ([]*http.Cookie, error)
- func (c *Client) Host() string
- func (c *Client) New(t *testing.T) *Request
- func (c *Client) NewClient(filters ...RequestFilter) *http.Client
- func (c *Client) NewRequest(t *testing.T) *Request
- func (c *Client) NewWebsocket(t *testing.T, path string) *websocket.Conn
- func (c *Client) SetCookies(cookies []*http.Cookie) error
- func (c *Client) Url(urlpath string, params ...url.Values) string
- func (c *Client) WebsocketUrl(urlpath string, params ...url.Values) string
- type FilterTransport
- type Request
- func (r *Request) AssertContains(s string) bool
- func (r *Request) AssertContainsJSON(key string, value interface{}) bool
- func (r *Request) AssertContentType(contentType string) bool
- func (r *Request) AssertEmpty() bool
- func (r *Request) AssertExistHeader(name string) bool
- func (r *Request) AssertForbidden() bool
- func (r *Request) AssertHeader(name, value string) bool
- func (r *Request) AssertInternalError() bool
- func (r *Request) AssertMatch(re string) bool
- func (r *Request) AssertNotContains(s string) bool
- func (r *Request) AssertNotContainsJSON(key string) bool
- func (r *Request) AssertNotEmpty() bool
- func (r *Request) AssertNotExistHeader(name string) bool
- func (r *Request) AssertNotFound() bool
- func (r *Request) AssertNotMatch(re string) bool
- func (r *Request) AssertOK() bool
- func (r *Request) AssertStatus(status int) bool
- func (r *Request) Build(method, urlpath, contentType string, data ...interface{}) (request *http.Request, err error)
- func (r *Request) Delete(path, contentType string, data ...interface{})
- func (r *Request) DeleteForm(path string, data interface{})
- func (r *Request) DeleteJSON(path string, data interface{})
- func (r *Request) DeleteXML(path string, data interface{})
- func (r *Request) Get(path string, params ...url.Values)
- func (r *Request) GetJSON(path string, params ...url.Values)
- func (r *Request) GetXML(path string, params ...url.Values)
- func (r *Request) Head(path string, params ...url.Values)
- func (r *Request) NewMultipartRequest(method, path, filename string, file interface{}, fields ...map[string]string)
- func (r *Request) NewRequest(request *http.Request, filters ...RequestFilter)
- func (r *Request) NewSessionRequest(request *http.Request, filters ...RequestFilter)
- func (r *Request) Options(path string, params ...url.Values)
- func (r *Request) Patch(path, contentType string, data ...interface{})
- func (r *Request) PatchForm(path string, data interface{})
- func (r *Request) PatchJSON(path string, data interface{})
- func (r *Request) PatchXML(path string, data interface{})
- func (r *Request) Post(path, contentType string, data ...interface{})
- func (r *Request) PostForm(path string, data interface{})
- func (r *Request) PostJSON(path string, data interface{})
- func (r *Request) PostXML(path string, data interface{})
- func (r *Request) Put(path, contentType string, data ...interface{})
- func (r *Request) PutForm(path string, data interface{})
- func (r *Request) PutJSON(path string, data interface{})
- func (r *Request) PutXML(path string, data interface{})
- func (r *Request) Send(method, path, contentType string, data ...interface{})
- func (r *Request) WithCookies(cookies []*http.Cookie) *Request
- func (r *Request) WithHeader(key, value string) *Request
- func (r *Request) WithHttpHeader(header http.Header) *Request
- type RequestFilter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client defines request component of httptesting.
NOTE: Client is not safe for concurrency, please use client.New(t) after initialized.
func NewServer ¶
NewServer returns an initialized *Client along with mocked server for testing NOTE: You MUST call client.Close() for cleanup after testing.
func NewServerWithTLS ¶
func NewServerWithTLS(handler http.Handler, cert tls.Certificate) *Client
NewServerWithTLS returns an initialized *Client along with mocked server for testing NOTE: You MUST call client.Close() for cleanup after testing.
func NewWithTLS ¶
func NewWithTLS(host string, cert *x509.Certificate) *Client
NewWithTLS returns an initialized *Client with custom certificate.
func (*Client) Close ¶
func (c *Client) Close()
Close tries to
- close *httptest.Server created by NewServer or NewServerWithTLS
func (*Client) NewClient ¶ added in v1.1.0
func (c *Client) NewClient(filters ...RequestFilter) *http.Client
NewClient creates a http client with cookie and tls for the Client.
func (*Client) NewRequest ¶
New returns a *Request which has more customization!
func (*Client) NewWebsocket ¶
NewWebsocket creates a websocket connection to the given path and returns the connection
func (*Client) SetCookies ¶
SetCookies sets jar for the host
func (*Client) Url ¶
Url returns the abs http/isTLS URL of the resource, e.g. "http://127.0.0.1:9090/status". The scheme is set to isTLS if http.ssl is set to true in the configuration.
type FilterTransport ¶ added in v1.0.0
type FilterTransport struct {
// contains filtered or unexported fields
}
FilterTransport defines a custom http.Transport with filters and certs.
func NewFilterTransport ¶ added in v1.0.0
func NewFilterTransport(filters []RequestFilter, certs ...*x509.CertPool) *FilterTransport
type Request ¶
type Request struct { *Client Response *http.Response ResponseBody []byte // contains filtered or unexported fields }
Request defines http client for human usage.
func NewRequest ¶
NewRequest returns a new *Request with *Client
func (*Request) AssertContains ¶ added in v1.0.0
AssertContains asserts that the response body contains the string.
func (*Request) AssertContainsJSON ¶ added in v1.0.0
AssertContainsJSON asserts that the response body contains JSON value of the key.
func (*Request) AssertContentType ¶ added in v1.0.0
AssertContentType asserts that the response includes Content-Type header with value.
func (*Request) AssertEmpty ¶ added in v1.0.0
AssertEmpty asserts that the response body is empty.
func (*Request) AssertExistHeader ¶ added in v1.0.0
AssertExistHeader asserts that the response includes named header.
func (*Request) AssertForbidden ¶ added in v1.0.0
AssertForbidden asserts that the response status code is 403.
func (*Request) AssertHeader ¶ added in v1.0.0
AssertHeader asserts that the response includes named header with value.
func (*Request) AssertInternalError ¶ added in v1.0.0
AssertInternalError asserts that the response status code is 500.
func (*Request) AssertMatch ¶ added in v1.0.0
AssertMatch asserts that the response body matches the regular expression.
func (*Request) AssertNotContains ¶ added in v1.0.0
AssertNotContains asserts that the response body does not contain the string.
func (*Request) AssertNotContainsJSON ¶ added in v1.0.0
AssertNotContainsJSON asserts that the response body dose not contain JSON value of the key.
func (*Request) AssertNotEmpty ¶ added in v1.0.0
AssertNotEmpty asserts that the response body is not empty.
func (*Request) AssertNotExistHeader ¶ added in v1.0.0
AssertNotExistHeader asserts that the response does not include named header.
func (*Request) AssertNotFound ¶ added in v1.0.0
AssertNotFound asserts that the response status code is 404.
func (*Request) AssertNotMatch ¶ added in v1.0.0
AssertNotMatch asserts that the response body does not match the regular expression.
func (*Request) AssertStatus ¶ added in v1.0.0
AssertStatus asserts that the response status code is equal to value.
func (*Request) Delete ¶
Delete issues a DELETE request to the given path, sending request with specified Content-Type header, and stores the result in Response and ResponseBody if success.
func (*Request) DeleteForm ¶
DeleteForm issues a DELETE request to the given path with Content-Type: application/x-www-form-urlencoded header, and stores the result in Response and ResponseBody if success.
func (*Request) DeleteJSON ¶
DeleteJSON issues a DELETE request to the given path with Content-Type: application/json header, and stores the result in Response and ResponseBody if success. NOTE: It will encode data by json.Marshal before making request.
func (*Request) DeleteXML ¶
DeleteXML issues a DELETE request to the given path with Content-Type: text/xml header, and stores the result in Response and ResponseBody if success. NOTE: It will encode data by xml.Marshal before making request.
func (*Request) Get ¶
Get issues a GET request to the given path with Content-Type: text/html header, and stores the result in Response and ResponseBody if success.
func (*Request) GetJSON ¶
GetJSON issues a GET request to the given path with Content-Type: application/json header, and stores the result in Response and ResponseBody if success.
func (*Request) GetXML ¶
GetXML issues a GET request to the given path with Content-Type: text/xml header, and stores the result in Response and ResponseBody if success.
func (*Request) Head ¶
Head issues a HEAD request to the given path with Content-Type: text/html header, and stores the result in Response if success.
func (*Request) NewMultipartRequest ¶
func (r *Request) NewMultipartRequest(method, path, filename string, file interface{}, fields ...map[string]string)
NewMultipartRequest issues a multipart request for the method & fields given and read the response. If successful, the caller may examine the Response and ResponseBody properties.
func (*Request) NewRequest ¶
func (r *Request) NewRequest(request *http.Request, filters ...RequestFilter)
NewRequest issues any request and read the response. If successful, the caller may examine the Response and ResponseBody properties. NOTE: You have to manage session / cookie data manually.
func (*Request) NewSessionRequest ¶
func (r *Request) NewSessionRequest(request *http.Request, filters ...RequestFilter)
NewSessionRequest issues any request with session / cookie and read the response. If successful, the caller may examine the Response and ResponseBody properties. NOTE: Session data will be added to the request jar for requested host.
func (*Request) Options ¶
Options issues an OPTIONS request to the given path Content-Type: text/html header, and stores the result in Response if success.
func (*Request) Patch ¶
Patch issues a PATCH request to the given path with specified Content-Type header, and stores the result in Response and ResponseBody if success.
func (*Request) PatchForm ¶
PatchForm issues a PATCH request to the given path with Content-Type: application/x-www-form-urlencoded header, and stores the result in Response and ResponseBody if success.
func (*Request) PatchJSON ¶
PatchJSON issues a PATCH request to the given path with with Content-Type: application/json header, and stores the result in Response and ResponseBody if success. It will encode data by json.Marshal before making request.
func (*Request) PatchXML ¶
PatchXML issues a PATCH request to the given path with Content-Type: text/xml header, and stores the result in Response and ResponseBody if success. NOTE: It will encode data by xml.Marshal before making request.
func (*Request) Post ¶
Post issues a POST request to the given path with specified Content-Type header, and stores the result in Response and ResponseBody if success.
func (*Request) PostForm ¶
PostForm issues a POST request to the given path with Content-Type: application/x-www-form-urlencoded header, and stores the result in Response and ResponseBody if success.
func (*Request) PostJSON ¶
PostJSON issues a POST request to the given path with Content-Type: application/json header, and stores the result in Response and ResponseBody if success. NOTE: It will encode data by json.Marshal before making request.
func (*Request) PostXML ¶
PostXML issues a POST request to the given path with Content-Type: text/xml header, and stores the result in Response and ResponseBody if success. NOTE: It will encode data by xml.Marshal before making request.
func (*Request) Put ¶
Put issues a PUT request to the given path with specified Content-Type header, and stores the result in Response and ResponseBody if success.
func (*Request) PutForm ¶
PutForm issues a PUT request to the given path with Content-Type: application/x-www-form-urlencoded header, and stores the result in Response and ResponseBody if success.
func (*Request) PutJSON ¶
PutJSON issues a PUT request to the given path with Content-Type: application/json header, and stores the result in Response and ResponseBody if success. NOTE: It will encode data by json.Marshal before making request.
func (*Request) PutXML ¶
PutXML issues a PUT request to the given path with Content-Type: text/xml header, and stores the result in Response and ResponseBody if success. NOTE: It will encode data by xml.Marshal before making request.
func (*Request) Send ¶
Send issues a HTTP request to the given path with specified method and content type header, and stores the result in Response and ResponseBody if success. NOTE: It will encode data with json.Marshal for unsupported types and reset content type to application/json for the request.
func (*Request) WithCookies ¶ added in v1.0.0
WithCookie sets jar for client by replace for the request
func (*Request) WithHeader ¶
WithHeader sets http header by replace for the request
type RequestFilter ¶ added in v1.0.0
RequestFilter is a callback for http request injection.