Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NopResponseWriter ¶
func NopResponseWriter() http.ResponseWriter
NopResponseWriter returns a http.ResponseWriter with a no-op Header, Write and WriteHeader methods. This is a simple stub for testing.
func SetDefaultTarget ¶
func SetDefaultTarget(target string)
SetDefaultTarget sets default target for RequestBuilder
Types ¶
type RequestBuilder ¶
type RequestBuilder interface { // SetHeader sets the request's target. SetTarget(target string) RequestBuilder // SetMethod sets the request's HTTP method. SetMethod(method string) RequestBuilder // SetQuery sets the query for the request. SetQuery(q url.Values) RequestBuilder // SetQueryValue sets the query parameter for the request. SetQueryValue(key string, value ...string) RequestBuilder // SetHeader sets the header for the request. SetHeader(key string, value ...string) RequestBuilder // SetContentType sets the request's Content-Type header. // // Example of a value: application/json; charset=UTF-8. // // See RFC 7231, Section 3.1.1.5. SetContentType(value string) RequestBuilder // SetContentTypeWithParam sets the request's Content-Type header with parameter. //SetContentTypeWithParam(mimeType, param string) RequestBuilder // SetAccept sets the request's Accept header. SetAccept(value string) RequestBuilder // SetAcceptLanguage sets the request's Accept-Language header. SetAcceptLanguage(value string) RequestBuilder // SetCookies sets the request's cookie. SetCookies(cookie ...*http.Cookie) RequestBuilder // SetContext sets the request's context. SetContext(context context.Context) RequestBuilder // SetContextValue sets the request's context value. SetContextValue(key, value interface{}) RequestBuilder // SetBody sets the request's body. SetBody(reader io.Reader) RequestBuilder // SetPostForm sets the request's body as PostForm. // If PostForm is nil, it is initialized. The method is set as POST. // Content type as application/x-www-form-urlencoded. SetPostForm(postForm url.Values) RequestBuilder // SetPostFormValue sets field for the request's PostForm. // If PostForm is nil, it is initialized. The method is set as POST. // Content type is set as application/x-www-form-urlencoded. SetPostFormValue(key string, value ...string) RequestBuilder // SetJSON sets JSON-encoded data to the request body. // // If HTTP method is not set or GET or DELETE, the value is set as POST. // // If Content-Type header is not set, then the value is set as application/json;charset=UTF8. SetJSON(data []byte) RequestBuilder // SetJSONFromValue converts the value to JSON encoding // and sets data to the request body. An error encoding the value will cause a panic. // // If HTTP method is not set or GET or DELETE, the value is set as POST. // // If Content-Type header is not set, then the value is set as application/json;charset=UTF8. SetJSONFromValue(v interface{}) RequestBuilder // SetAuth sets the request's Authorization header. // Prefix specifies the authentication scheme. SetAuth(prefix, value string) RequestBuilder // SetBasicAuth sets Authorization header to use HTTP // Basic Authentication with the provided username and password. // See RFC 2617, Section 2. SetBasicAuth(username, password string) RequestBuilder // SetBearerAuth sets the request's Authorization header to use HTTP Bearer Authentication. // See RFC 6750, bearer tokens to access OAuth 2.0-protected resources. SetBearerAuth(token string) RequestBuilder // SetUserAgent sets User-Agent header. SetUserAgent(value string) RequestBuilder // Request constructs and returns a new incoming server http.Request for testing. // // If PostForm is initialized, the request body will be set as strings.Reader of its values. // Other method SetBody calls will be ignored. Request() *http.Request }
A RequestBuilder interface defines methods for constructing a test http.Request.
func Builder ¶
func Builder() RequestBuilder
Builder returns a new RequestBuilder for constructing a test http.Request. By default HTTP method is set as GET.
Click to show internal directories.
Click to hide internal directories.