Documentation
¶
Index ¶
- type Client
- func (c *Client) AssertContains(s string)
- func (c *Client) AssertContainsJSON(key string, value interface{})
- func (c *Client) AssertContentType(contentType string)
- func (c *Client) AssertEmpty()
- func (c *Client) AssertExistHeader(name string)
- func (c *Client) AssertForbidden()
- func (c *Client) AssertHeader(name, value string)
- func (c *Client) AssertMatch(re string)
- func (c *Client) AssertNotContains(s string)
- func (c *Client) AssertNotContainsJSON(key string)
- func (c *Client) AssertNotEmpty()
- func (c *Client) AssertNotExistHeader(name string)
- func (c *Client) AssertNotFound()
- func (c *Client) AssertNotMatch(re string)
- func (c *Client) AssertOK()
- func (c *Client) AssertStatus(status int)
- func (c *Client) Build(method, urlpath, contentType string, data ...interface{}) (request *http.Request, err error)
- func (c *Client) Close()
- func (c *Client) Cookies() []*http.Cookie
- func (c *Client) Delete(t *testing.T, path, contentType string, data ...interface{})
- func (c *Client) DeleteForm(t *testing.T, path string, data interface{})
- func (c *Client) DeleteJSON(t *testing.T, path string, data interface{})
- func (c *Client) DeleteXML(t *testing.T, path string, data interface{})
- func (c *Client) Get(t *testing.T, path string, params ...url.Values)
- func (c *Client) GetJSON(t *testing.T, path string, params ...url.Values)
- func (c *Client) GetXML(t *testing.T, path string, params ...url.Values)
- func (c *Client) Head(t *testing.T, path string, params ...url.Values)
- func (c *Client) Host() string
- func (c *Client) New(t *testing.T) *Request
- func (c *Client) NewFilterRequest(t *testing.T, request *http.Request, filter TransportFilter)
- func (c *Client) NewMultipartRequest(t *testing.T, method, path, filename string, file interface{}, ...)
- func (c *Client) NewRequest(t *testing.T, request *http.Request)
- func (c *Client) NewSessionRequest(t *testing.T, request *http.Request)
- func (c *Client) NewWebsocket(t *testing.T, path string) *websocket.Conn
- func (c *Client) Options(t *testing.T, path string, params ...url.Values)
- func (c *Client) Patch(t *testing.T, path, contentType string, data ...interface{})
- func (c *Client) PatchForm(t *testing.T, path string, data interface{})
- func (c *Client) PatchJSON(t *testing.T, path string, data interface{})
- func (c *Client) PatchXML(t *testing.T, path string, data interface{})
- func (c *Client) Post(t *testing.T, path, contentType string, data ...interface{})
- func (c *Client) PostForm(t *testing.T, path string, data interface{})
- func (c *Client) PostJSON(t *testing.T, path string, data interface{})
- func (c *Client) PostXML(t *testing.T, path string, data interface{})
- func (c *Client) Put(t *testing.T, path, contentType string, data ...interface{})
- func (c *Client) PutForm(t *testing.T, path string, data interface{})
- func (c *Client) PutJSON(t *testing.T, path string, data interface{})
- func (c *Client) PutXML(t *testing.T, path string, data interface{})
- func (c *Client) Send(t *testing.T, method, path, contentType string, data ...interface{})
- func (c *Client) SetCookies(cookies []*http.Cookie)
- func (c *Client) Url(urlpath string) string
- func (c *Client) WebsocketUrl(urlpath string) string
- type Request
- 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) NewFilterRequest(request *http.Request, filter TransportFilter)
- func (r *Request) NewMultipartRequest(method, path, filename string, file interface{}, fields ...map[string]string)
- func (r *Request) NewRequest(request *http.Request)
- func (r *Request) NewSessionRequest(request *http.Request)
- func (r *Request) NewWebsocket(t *testing.T, path string) *websocket.Conn
- 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) WithHeader(key, value string) *Request
- func (r *Request) WithHttpHeader(header http.Header) *Request
- type TransportFilter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Response *http.Response
ResponseBody []byte
// 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) AssertContains ¶
AssertContains asserts that the response body contains the string.
func (*Client) AssertContainsJSON ¶
AssertContainsJSON asserts that the response body contains JSON value of the key.
func (*Client) AssertContentType ¶
AssertContentType asserts that the response includes Content-Type header with value.
func (*Client) AssertEmpty ¶
func (c *Client) AssertEmpty()
AssertEmpty asserts that the response body is empty.
func (*Client) AssertExistHeader ¶
AssertExistHeader asserts that the response includes named header.
func (*Client) AssertForbidden ¶
func (c *Client) AssertForbidden()
AssertForbidden asserts that the response status code is 403.
func (*Client) AssertHeader ¶
AssertHeader asserts that the response includes named header with value.
func (*Client) AssertMatch ¶
AssertMatch asserts that the response body matches the regular expression.
func (*Client) AssertNotContains ¶
AssertNotContains asserts that the response body does not contain the string.
func (*Client) AssertNotContainsJSON ¶
AssertNotContainsJSON asserts that the response body dose not contain JSON value of the key.
func (*Client) AssertNotEmpty ¶
func (c *Client) AssertNotEmpty()
AssertNotEmpty asserts that the response body is not empty.
func (*Client) AssertNotExistHeader ¶
AssertNotExistHeader asserts that the response does not include named header.
func (*Client) AssertNotFound ¶
func (c *Client) AssertNotFound()
AssertNotFound asserts that the response status code is 404.
func (*Client) AssertNotMatch ¶
AssertNotMatch asserts that the response body does not match the regular expression.
func (*Client) AssertOK ¶
func (c *Client) AssertOK()
AssertOK asserts that the response status code is 200.
func (*Client) AssertStatus ¶
AssertStatus asserts that the response status code is equal to value.
func (*Client) Close ¶
func (c *Client) Close()
Close tries to
- close *httptest.Server created by NewServer()
- release lock of previous request if existed
func (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) NewFilterRequest ¶
NewFilterRequest issues any request with TransportFilter and read the response. If successful, the caller may examine the Response and ResponseBody properties. NOTE: It returns error without apply HTTP request when transport filter returned an error.
func (*Client) NewMultipartRequest ¶
func (c *Client) NewMultipartRequest(t *testing.T, 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 (*Client) NewRequest ¶
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 (*Client) NewSessionRequest ¶
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 cookies for you.
func (*Client) NewWebsocket ¶
NewWebsocket creates a websocket connection to the given path and returns the connection
func (*Client) Options ¶
Options issues an OPTIONS request to the given path Content-Type: text/html header, and stores the result in Response if success.
func (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 (*Client) 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 unspported types and reset content type to application/json for the request.
func (*Client) SetCookies ¶
SetCookies sets cookies for the host
func (*Client) Url ¶
Url returns the abs http/https URL of the resource, e.g. "http://127.0.0.1:9090/status". The scheme is set to https if http.ssl is set to true in the configuration.
func (*Client) WebsocketUrl ¶
WebsocketUrl returns the abs websocket URL of the resource, e.g. "ws://127.0.0.1:9090/status"
type Request ¶
type Request struct {
*Client
// contains filtered or unexported fields
}
Request defines http client for human
func NewRequest ¶
NewRequest returns a new *Request with *Client
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) NewFilterRequest ¶
func (r *Request) NewFilterRequest(request *http.Request, filter TransportFilter)
NewFilterRequest issues any request with TransportFiler and read the response. If successful, the caller may examine the Response and ResponseBody properties. NOTE: It returns error without apply HTTP request when transport filter returned an error.
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 ¶
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 ¶
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 cookies for requested host.
func (*Request) NewWebsocket ¶
NewWebsocket creates a websocket connection to the given path and returns the connection
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 unspported types and reset content type to application/json for the request.
func (*Request) WithHeader ¶
WithHeader sets http.Request header by replace
type TransportFilter ¶
TransportFilter is a callback for http request injection.