baloo: github.com/h2non/baloo Index | Files | Directories

package baloo

import "github.com/h2non/baloo"

Index

Package Files

client.go expect.go request.go version.go

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
)

func AddAssertFunc Uses

func AddAssertFunc(name string, fn assert.Func)

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 Uses

func FlushAssertFuncs()

FlushAssertFuncs flushes registered assertion functions.

type Client Uses

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 New Uses

func New(url string) *Client

New creates a new high level client entity able to perform HTTP requests.

func (*Client) AddCookie Uses

func (c *Client) AddCookie(cookie *http.Cookie) *Client

AddCookie sets a new cookie field bsaed on the given http.Cookie struct without overwriting any existent cookie.

func (*Client) AddCookies Uses

func (c *Client) AddCookies(data []*http.Cookie) *Client

AddCookies sets a new cookie field based on a list of http.Cookie without overwriting any existent cookie.

func (*Client) AddHeader Uses

func (c *Client) AddHeader(name, value string) *Client

AddHeader adds a new header field by name and value without overwriting any existent header.

func (*Client) BaseURL Uses

func (c *Client) BaseURL(uri string) *Client

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 Uses

func (c *Client) CookieJar() *Client

CookieJar creates a cookie jar to store HTTP cookies when they are sent down.

func (*Client) Delete Uses

func (c *Client) Delete(path string) *Request

Delete creates a new DELETE request.

func (*Client) Get Uses

func (c *Client) Get(path string) *Request

Get creates a new GET request.

func (*Client) Head Uses

func (c *Client) Head(path string) *Request

Head creates a new HEAD request.

func (*Client) Method Uses

func (c *Client) Method(name string) *Client

Method defines a the default HTTP method used by outgoing client requests.

func (*Client) Param Uses

func (c *Client) Param(name, value string) *Client

Param replaces a path param based on the given param name and value.

func (*Client) Params Uses

func (c *Client) Params(params map[string]string) *Client

Params replaces path params based on the given params key-value map.

func (*Client) Patch Uses

func (c *Client) Patch(path string) *Request

Patch creates a new PATCH request.

func (*Client) Path Uses

func (c *Client) Path(path string) *Client

Path defines the URL base path for client requests.

func (*Client) Post Uses

func (c *Client) Post(path string) *Request

Post creates a new POST request.

func (*Client) Put Uses

func (c *Client) Put(path string) *Request

Put creates a new PUT request.

func (*Client) Request Uses

func (c *Client) Request() *Request

Request creates a new Request based on the current Client

func (*Client) SetHeader Uses

func (c *Client) SetHeader(key, value string) *Client

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 Uses

func (c *Client) SetHeaders(fields map[string]string) *Client

SetHeaders adds new header fields based on the given map.

func (*Client) URL Uses

func (c *Client) URL(uri string) *Client

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) Use Uses

func (c *Client) Use(p plugin.Plugin) *Client

Use uses a new plugin to the middleware stack.

func (*Client) UseError Uses

func (c *Client) UseError(fn context.HandlerFunc) *Client

UseError uses a new middleware function for error phase.

func (*Client) UseHandler Uses

func (c *Client) UseHandler(phase string, fn context.HandlerFunc) *Client

UseHandler uses a new middleware function for the given phase.

func (*Client) UseParent Uses

func (c *Client) UseParent(parent *Client) *Client

UseParent uses another Client as parent inheriting its middleware stack and configuration.

func (*Client) UseRequest Uses

func (c *Client) UseRequest(fn context.HandlerFunc) *Client

UseRequest uses a new middleware function for request phase.

func (*Client) UseResponse Uses

func (c *Client) UseResponse(fn context.HandlerFunc) *Client

UseResponse uses a new middleware function for response phase.

type Expect Uses

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 NewExpect Uses

func NewExpect(req *Request) *Expect

NewExpect creates a new testing expectation instance.

func (*Expect) Assert Uses

func (e *Expect) Assert(assertions ...string) *Expect

Assert adds a new assertion function by alias name. Assertion function must be previosly registered via baloo.AddAssertFunc("alias", function).

func (*Expect) AssertFunc Uses

func (e *Expect) AssertFunc(assertion ...assert.Func) *Expect

AssertFunc adds a new assertion function.

func (*Expect) BindTest Uses

func (e *Expect) BindTest(t TestingT) *Expect

BindTest binds the Go testing instance to the current suite. In the future multiple testing interfaces can be supported via adapters.

func (*Expect) BodyEquals Uses

func (e *Expect) BodyEquals(pattern string) *Expect

BodyEquals asserts as strict equality comparison the response body with a given string string.

func (*Expect) BodyLength Uses

func (e *Expect) BodyLength(length int) *Expect

BodyLength asserts a response body length.

func (*Expect) BodyMatchString Uses

func (e *Expect) BodyMatchString(pattern string) *Expect

BodyMatchString asserts a response body matching a string expression. Regular expressions can be used as value to perform the specific assertions.

func (*Expect) Done Uses

func (e *Expect) Done() error

Done performs and asserts the HTTP response based on the defined expectations.

func (*Expect) End Uses

func (e *Expect) End() error

End is an alias to `Done()`.

func (*Expect) Header Uses

func (e *Expect) Header(key, value string) *Expect

Header asserts a response header field value matches. Regular expressions can be used as value to perform the specific assertions.

func (*Expect) HeaderEquals Uses

func (e *Expect) HeaderEquals(key, value string) *Expect

HeaderEquals asserts a response header field value is equal to the given value.

func (*Expect) HeaderNotEquals Uses

func (e *Expect) HeaderNotEquals(key, value string) *Expect

HeaderNotEquals asserts that a response header field value is not equal to the given one.

func (*Expect) HeaderNotPresent Uses

func (e *Expect) HeaderNotPresent(key string) *Expect

HeaderNotPresent asserts if a header field is not present in the response.

func (*Expect) HeaderPresent Uses

func (e *Expect) HeaderPresent(key string) *Expect

HeaderPresent asserts if a header field is present in the response.

func (*Expect) JSON Uses

func (e *Expect) JSON(data interface{}) *Expect

JSON asserts the response body with the given JSON struct.

func (*Expect) JSONSchema Uses

func (e *Expect) JSONSchema(schema string) *Expect

JSONSchema asserts the response body with the given JSON schema definition.

func (*Expect) RedirectTo Uses

func (e *Expect) RedirectTo(uri string) *Expect

RedirectTo asserts the server response redirects to the given URL pattern. Regular expressions are supported.

func (*Expect) Send Uses

func (e *Expect) Send() (*gentleman.Response, error)

Send does the same as `Done()`, but it also returns the `*http.Response` along with the `error`.

func (*Expect) Status Uses

func (e *Expect) Status(code int) *Expect

Status asserts the response status code with the given status.

func (*Expect) StatusClientError Uses

func (e *Expect) StatusClientError() *Expect

StatusClientError asserts the response status code as server error response (>= 400 && < 500).

func (*Expect) StatusError Uses

func (e *Expect) StatusError() *Expect

StatusError asserts the response status code as client/server error response (>= 400 && < 600).

func (*Expect) StatusOk Uses

func (e *Expect) StatusOk() *Expect

StatusOk asserts the response status code as valid response (>= 200 && < 400).

func (*Expect) StatusServerError Uses

func (e *Expect) StatusServerError() *Expect

StatusServerError asserts the response status code as server error response (>= 500 && < 600).

func (*Expect) Type Uses

func (e *Expect) Type(kind string) *Expect

Type asserts the response MIME type with the given alias or value.

type Request Uses

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 NewRequest Uses

func NewRequest() *Request

NewRequest creates a new Request entity.

func (*Request) AddCookie Uses

func (r *Request) AddCookie(cookie *http.Cookie) *Request

AddCookie sets a new cookie field bsaed on the given http.Cookie struct without overwriting any existent cookie.

func (*Request) AddCookies Uses

func (r *Request) AddCookies(data []*http.Cookie) *Request

AddCookies sets a new cookie field based on a list of http.Cookie without overwriting any existent cookie.

func (*Request) AddHeader Uses

func (r *Request) AddHeader(name, value string) *Request

AddHeader adds a new header field by name and value without overwriting any existent header.

func (*Request) AddPath Uses

func (r *Request) AddPath(path string) *Request

AddPath defines the request URL path to be used in the outgoing request.

func (*Request) AddQuery Uses

func (r *Request) AddQuery(name, value string) *Request

AddQuery adds a new URL query param field without overwriting any existent query field.

func (*Request) Assert Uses

func (r *Request) Assert(t TestingT) *Expect

Assert is an alias to .Expect().

func (*Request) BaseURL Uses

func (r *Request) BaseURL(uri string) *Request

BaseURL parses the given URL and uses the URL schema and host in the outgoing request.

func (*Request) Body Uses

func (r *Request) Body(reader io.Reader) *Request

Body defines the request body based on a io.Reader stream.

func (*Request) BodyString Uses

func (r *Request) BodyString(data string) *Request

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) Clone Uses

func (r *Request) Clone() *Request

Clone creates a new side-effects free Request based on the current one.

func (*Request) CookieJar Uses

func (r *Request) CookieJar() *Request

CookieJar creates a cookie jar to store HTTP cookies when they are sent down.

func (*Request) Expect Uses

func (r *Request) Expect(t TestingT) *Expect

Expect creates and returns the request test expectation suite.

func (*Request) File Uses

func (r *Request) File(name string, reader io.Reader) *Request

File serializes and defines the request body as multipart/form-data containing one file field.

func (*Request) Files Uses

func (r *Request) Files(files []multipart.FormFile) *Request

Files serializes and defines the request body as multipart/form-data containing the given file fields.

func (*Request) Form Uses

func (r *Request) Form(data multipart.FormData) *Request

Form serializes and defines the request body as multipart/form-data based on the given form data.

func (*Request) JSON Uses

func (r *Request) JSON(data interface{}) *Request

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) Method Uses

func (r *Request) Method(method string) *Request

Method defines the HTTP verb to be used.

func (*Request) Param Uses

func (r *Request) Param(name, value string) *Request

Param replaces a path param based on the given param name and value.

func (*Request) Params Uses

func (r *Request) Params(params map[string]string) *Request

Params replaces path params based on the given params key-value map.

func (*Request) Path Uses

func (r *Request) Path(path string) *Request

Path defines the request URL path to be used in the outgoing request.

func (*Request) Send Uses

func (r *Request) Send() (*gentleman.Response, error)

Send executes the current request and returns the response or error.

func (*Request) SetClient Uses

func (r *Request) SetClient(cli *Client) *Request

SetClient Attach a client to the current Request This is mostly done internally.

func (*Request) SetHeader Uses

func (r *Request) SetHeader(name, value string) *Request

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 Uses

func (r *Request) SetHeaders(fields map[string]string) *Request

SetHeaders adds new header fields based on the given map.

func (*Request) SetQuery Uses

func (r *Request) SetQuery(name, value string) *Request

SetQuery sets a new URL query param field. If another query param exists with the same key, it will be overwritten.

func (*Request) SetQueryParams Uses

func (r *Request) SetQueryParams(params map[string]string) *Request

SetQueryParams sets URL query params based on the given map.

func (*Request) Type Uses

func (r *Request) Type(name string) *Request

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) URL Uses

func (r *Request) URL(uri string) *Request

URL parses and defines the URL to be used in the outgoing request.

func (*Request) Use Uses

func (r *Request) Use(p plugin.Plugin) *Request

Use uses a new plugin in the middleware stack.

func (*Request) UseError Uses

func (r *Request) UseError(fn context.HandlerFunc) *Request

UseError uses an error middleware handler.

func (*Request) UseHandler Uses

func (r *Request) UseHandler(phase string, fn context.HandlerFunc) *Request

UseHandler uses an new middleware handler for the given phase.

func (*Request) UseRequest Uses

func (r *Request) UseRequest(fn context.HandlerFunc) *Request

UseRequest uses a request middleware handler.

func (*Request) UseResponse Uses

func (r *Request) UseResponse(fn context.HandlerFunc) *Request

UseResponse uses a response middleware handler.

func (*Request) XML Uses

func (r *Request) XML(data interface{}) *Request

XML serializes and defines the request body based on the given input. The proper Content-Type header will be transparently added for you.

type TestingT Uses

type TestingT interface {
    Error(args ...interface{})
}

TestingT implements part of the same interface as testing.T

Directories

PathSynopsis
assert

Package baloo imports 8 packages (graph). Updated 2018-09-18. Refresh now. Tools for package owners.