Documentation ¶
Index ¶
- Constants
- Variables
- func AddAssertFunc(name string, fn assert.Func)
- func FlushAssertFuncs()
- type Client
- func (c *Client) AddCookie(cookie *http.Cookie) *Client
- func (c *Client) AddCookies(data []*http.Cookie) *Client
- func (c *Client) AddHeader(name, value string) *Client
- func (c *Client) BaseURL(uri string) *Client
- func (c *Client) CookieJar() *Client
- func (c *Client) Delete(path string) *Request
- func (c *Client) Get(path string) *Request
- func (c *Client) Head(path string) *Request
- func (c *Client) Method(name string) *Client
- func (c *Client) Param(name, value string) *Client
- func (c *Client) Params(params map[string]string) *Client
- func (c *Client) Patch(path string) *Request
- func (c *Client) Path(path string) *Client
- func (c *Client) Post(path string) *Request
- func (c *Client) Put(path string) *Request
- func (c *Client) Request() *Request
- func (c *Client) SetHeader(key, value string) *Client
- func (c *Client) SetHeaders(fields map[string]string) *Client
- func (c *Client) URL(uri string) *Client
- func (c *Client) Use(p plugin.Plugin) *Client
- func (c *Client) UseError(fn context.HandlerFunc) *Client
- func (c *Client) UseHandler(phase string, fn context.HandlerFunc) *Client
- func (c *Client) UseParent(parent *Client) *Client
- func (c *Client) UseRequest(fn context.HandlerFunc) *Client
- func (c *Client) UseResponse(fn context.HandlerFunc) *Client
- type Expect
- func (e *Expect) Assert(assertions ...string) *Expect
- func (e *Expect) AssertFunc(assertion ...assert.Func) *Expect
- func (e *Expect) BindTest(t TestingT) *Expect
- func (e *Expect) BodyEquals(pattern string) *Expect
- func (e *Expect) BodyLength(length int) *Expect
- func (e *Expect) BodyMatchString(pattern string) *Expect
- func (e *Expect) Done() error
- func (e *Expect) End() error
- func (e *Expect) Header(key, value string) *Expect
- func (e *Expect) HeaderEquals(key, value string) *Expect
- func (e *Expect) HeaderNotEquals(key, value string) *Expect
- func (e *Expect) HeaderNotPresent(key string) *Expect
- func (e *Expect) HeaderPresent(key string) *Expect
- func (e *Expect) JSON(data interface{}) *Expect
- func (e *Expect) JSONSchema(schema string) *Expect
- func (e *Expect) RedirectTo(uri string) *Expect
- func (e *Expect) Send() (*gentleman.Response, error)
- func (e *Expect) Status(code int) *Expect
- func (e *Expect) StatusClientError() *Expect
- func (e *Expect) StatusError() *Expect
- func (e *Expect) StatusOk() *Expect
- func (e *Expect) StatusServerError() *Expect
- func (e *Expect) Type(kind string) *Expect
- type Request
- func (r *Request) AddCookie(cookie *http.Cookie) *Request
- func (r *Request) AddCookies(data []*http.Cookie) *Request
- func (r *Request) AddHeader(name, value string) *Request
- func (r *Request) AddPath(path string) *Request
- func (r *Request) AddQuery(name, value string) *Request
- func (r *Request) Assert(t TestingT) *Expect
- func (r *Request) BaseURL(uri string) *Request
- func (r *Request) Body(reader io.Reader) *Request
- func (r *Request) BodyString(data string) *Request
- func (r *Request) Clone() *Request
- func (r *Request) CookieJar() *Request
- func (r *Request) Expect(t TestingT) *Expect
- func (r *Request) File(name string, reader io.Reader) *Request
- func (r *Request) Files(files []multipart.FormFile) *Request
- func (r *Request) Form(data multipart.FormData) *Request
- func (r *Request) JSON(data interface{}) *Request
- func (r *Request) Method(method string) *Request
- func (r *Request) Param(name, value string) *Request
- func (r *Request) Params(params map[string]string) *Request
- func (r *Request) Path(path string) *Request
- func (r *Request) Send() (*gentleman.Response, error)
- func (r *Request) SetClient(cli *Client) *Request
- func (r *Request) SetHeader(name, value string) *Request
- func (r *Request) SetHeaders(fields map[string]string) *Request
- func (r *Request) SetQuery(name, value string) *Request
- func (r *Request) SetQueryParams(params map[string]string) *Request
- func (r *Request) Type(name string) *Request
- func (r *Request) URL(uri string) *Request
- func (r *Request) Use(p plugin.Plugin) *Request
- func (r *Request) UseError(fn context.HandlerFunc) *Request
- func (r *Request) UseHandler(phase string, fn context.HandlerFunc) *Request
- func (r *Request) UseRequest(fn context.HandlerFunc) *Request
- func (r *Request) UseResponse(fn context.HandlerFunc) *Request
- func (r *Request) XML(data interface{}) *Request
- type TestingT
Constants ¶
const Version = "3.0.2"
Version defines the current semantic version.
Variables ¶
var Assertions = make(map[string]assert.Func)
Assertions stores global assertion functions by alias name. Use Expect.Assert('<assertion name>') to use new assertion at request expectation level.
var NewHandler = gentleman.NewHandler
NewHandler is a convenient alias to gentleman.NewHandler factory.
var ( // UserAgent represents the static user agent name and version. UserAgent = "baloo/" + Version )
Functions ¶
func AddAssertFunc ¶
AddAssertFunc adds a new assertion function at global level by alias name. Then you can trigger the assertion function in any expectation test.
func FlushAssertFuncs ¶
func FlushAssertFuncs()
FlushAssertFuncs flushes registered assertion functions.
Types ¶
type Client ¶
type Client struct { // Parent stores an optional parent baloo Client instance. Parent *Client // Client entity has it's own Context that will be inherited by requests or child clients. Client *gentleman.Client }
Client represents a high-level HTTP client entity capable with a built-in middleware and context.
func (*Client) AddCookie ¶
AddCookie sets a new cookie field bsaed on the given http.Cookie struct without overwriting any existent cookie.
func (*Client) AddCookies ¶
AddCookies sets a new cookie field based on a list of http.Cookie without overwriting any existent cookie.
func (*Client) AddHeader ¶
AddHeader adds a new header field by name and value without overwriting any existent header.
func (*Client) BaseURL ¶
BaseURL defines the URL schema and host for client requests. Useful to define at client level the base URL used by client child requests.
func (*Client) CookieJar ¶
CookieJar creates a cookie jar to store HTTP cookies when they are sent down.
func (*Client) SetHeader ¶
SetHeader sets a new header field by name and value. If another header exists with the same key, it will be overwritten.
func (*Client) SetHeaders ¶
SetHeaders adds new header fields based on the given map.
func (*Client) URL ¶
URL defines the URL for client requests. Useful to define at client level the base URL and base path used by child requests.
func (*Client) UseError ¶
func (c *Client) UseError(fn context.HandlerFunc) *Client
UseError uses a new middleware function for error phase.
func (*Client) UseHandler ¶
func (c *Client) UseHandler(phase string, fn context.HandlerFunc) *Client
UseHandler uses a new middleware function for the given phase.
func (*Client) UseParent ¶
UseParent uses another Client as parent inheriting its middleware stack and configuration.
func (*Client) UseRequest ¶
func (c *Client) UseRequest(fn context.HandlerFunc) *Client
UseRequest uses a new middleware function for request phase.
func (*Client) UseResponse ¶
func (c *Client) UseResponse(fn context.HandlerFunc) *Client
UseResponse uses a new middleware function for response phase.
type Expect ¶
type Expect struct {
// contains filtered or unexported fields
}
Expect represents the HTTP expectation suite who is able to define multiple assertion functions to match the response.
func (*Expect) Assert ¶
Assert adds a new assertion function by alias name. Assertion function must be previosly registered via baloo.AddAssertFunc("alias", function).
func (*Expect) AssertFunc ¶
AssertFunc adds a new assertion function.
func (*Expect) BindTest ¶
BindTest binds the Go testing instance to the current suite. In the future multiple testing interfaces can be supported via adapters.
func (*Expect) BodyEquals ¶
BodyEquals asserts as strict equality comparison the response body with a given string string.
func (*Expect) BodyLength ¶
BodyLength asserts a response body length.
func (*Expect) BodyMatchString ¶
BodyMatchString asserts a response body matching a string expression. Regular expressions can be used as value to perform the specific assertions.
func (*Expect) Done ¶
Done performs and asserts the HTTP response based on the defined expectations.
func (*Expect) Header ¶
Header asserts a response header field value matches. Regular expressions can be used as value to perform the specific assertions.
func (*Expect) HeaderEquals ¶
HeaderEquals asserts a response header field value is equal to the given value.
func (*Expect) HeaderNotEquals ¶
HeaderNotEquals asserts that a response header field value is not equal to the given one.
func (*Expect) HeaderNotPresent ¶
HeaderNotPresent asserts if a header field is not present in the response.
func (*Expect) HeaderPresent ¶
HeaderPresent asserts if a header field is present in the response.
func (*Expect) JSONSchema ¶
JSONSchema asserts the response body with the given JSON schema definition.
func (*Expect) RedirectTo ¶
RedirectTo asserts the server response redirects to the given URL pattern. Regular expressions are supported.
func (*Expect) Send ¶
Send does the same as `Done()`, but it also returns the `*http.Response` along with the `error`.
func (*Expect) StatusClientError ¶
StatusClientError asserts the response status code as server error response (>= 400 && < 500).
func (*Expect) StatusError ¶
StatusError asserts the response status code as client/server error response (>= 400 && < 600).
func (*Expect) StatusOk ¶
StatusOk asserts the response status code as valid response (>= 200 && < 400).
func (*Expect) StatusServerError ¶
StatusServerError asserts the response status code as server error response (>= 500 && < 600).
type Request ¶
type Request struct { // Optional reference to the parent Client instance. Client *Client // Request stores the reference to gentleman.Request instance. Request *gentleman.Request // contains filtered or unexported fields }
Request HTTP entity for gentleman. Provides middleware capabilities, built-in context and convenient methods to easily setup request params.
func (*Request) AddCookie ¶
AddCookie sets a new cookie field bsaed on the given http.Cookie struct without overwriting any existent cookie.
func (*Request) AddCookies ¶
AddCookies sets a new cookie field based on a list of http.Cookie without overwriting any existent cookie.
func (*Request) AddHeader ¶
AddHeader adds a new header field by name and value without overwriting any existent header.
func (*Request) AddQuery ¶
AddQuery adds a new URL query param field without overwriting any existent query field.
func (*Request) BaseURL ¶
BaseURL parses the given URL and uses the URL schema and host in the outgoing request.
func (*Request) BodyString ¶
BodyString defines the request body based on the given string. If using this method, you should define the proper Content-Type header representing the real content MIME type.
func (*Request) CookieJar ¶
CookieJar creates a cookie jar to store HTTP cookies when they are sent down.
func (*Request) File ¶
File serializes and defines the request body as multipart/form-data containing one file field.
func (*Request) Files ¶
Files serializes and defines the request body as multipart/form-data containing the given file fields.
func (*Request) Form ¶
Form serializes and defines the request body as multipart/form-data based on the given form data.
func (*Request) JSON ¶
JSON serializes and defines as request body based on the given input. The proper Content-Type header will be transparently added for you.
func (*Request) SetClient ¶
SetClient Attach a client to the current Request This is mostly done internally.
func (*Request) SetHeader ¶
SetHeader sets a new header field by name and value. If another header exists with the same key, it will be overwritten.
func (*Request) SetHeaders ¶
SetHeaders adds new header fields based on the given map.
func (*Request) SetQuery ¶
SetQuery sets a new URL query param field. If another query param exists with the same key, it will be overwritten.
func (*Request) SetQueryParams ¶
SetQueryParams sets URL query params based on the given map.
func (*Request) Type ¶
Type defines the Content-Type header field based on the given type name alias or value. You can use the following content type aliases: json, xml, form, html, text and urlencoded.
func (*Request) UseError ¶
func (r *Request) UseError(fn context.HandlerFunc) *Request
UseError uses an error middleware handler.
func (*Request) UseHandler ¶
func (r *Request) UseHandler(phase string, fn context.HandlerFunc) *Request
UseHandler uses an new middleware handler for the given phase.
func (*Request) UseRequest ¶
func (r *Request) UseRequest(fn context.HandlerFunc) *Request
UseRequest uses a request middleware handler.
func (*Request) UseResponse ¶
func (r *Request) UseResponse(fn context.HandlerFunc) *Request
UseResponse uses a response middleware handler.