api

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidStatus is thrown when response status code does not match
	// expected status.
	ErrInvalidStatus = errors.New("status code does not match expected")

	// ErrExpectedEmptyBody is thrown when response expected body to be empty
	// but it was not.
	ErrExpectedEmptyBody = errors.New("response body should be empty")
	// ErrExpectedBody is thrown when response expected body to not be empty
	// but it was.
	ErrExpectedBody = errors.New("response should have a body")

	// ErrUnexpectedCookie is thrown when response or client should not have
	// specified cookies but at least one exists.
	ErrUnexpectedCookie = errors.New("should not have cookie")
	// ErrExpectedCookie is thrown when response should have specified cookies
	// but at least one does not exists.
	ErrExpectedCookie = errors.New("should have cookie")
	// ErrInvalidCookieSecurity is thrown when cookies security does not match
	// expected.
	ErrInvalidCookieSecurity = errors.New("cookie security does not match expected")
	// ErrInvalidCookieHTTPSetting is thrown when cookies HTTP setting does
	// not match expected.
	ErrInvalidCookieHTTPSetting = errors.New("cookie HTTP setting does not match expected")
	// ErrInvalidCookieDomain is thrown when cookie domain does not match expected.
	ErrInvalidCookieDomain = errors.New("cookie domain does not match expected")

	// ErrInvalidArgNumber is thrown when assertions methods receive an
	// unexpected number of arguments on periodic argument.
	ErrInvalidArgNumber = errors.New("invalid quantity for periodic arguments")
)
View Source
var (
	// ErrNoBody is thrown when asserting on response expected a body to exists
	// but none exists.
	ErrNoBody = api.ErrNoBody

	// ErrUnknownKey is thrown when provided key does not exists in JSON.
	ErrUnknownKey = api.ErrUnknownKey

	// ErrNoMatch is thrown when assertions fails to match expected value.
	ErrNoMatch = api.ErrNoMatch

	// ErrNotFullyMatch is thrown when actual asserted object contains
	// more values than expected.
	ErrNotFullyMatch = api.ErrNotFullyMatch

	// ErrNoPath is thrown when provided assertion path does not exists
	// in actual object.
	ErrNoPath = api.ErrNoPath

	// ErrNoRequest is thrown when assertion expected a request to exists
	// but none exists.
	ErrNoRequest = api.ErrNoRequest
)

Exposes api errors

View Source
var ErrInvalidMethod = errors.New("invalid method provided")

ErrInvalidMethod is thrown when an unsupported method is provided.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides methods to test HTTP Rest API endpoints.

func New

func New(store *internalPicker.Store, autoReset bool) (*Client, error)

New initializes an HTTP API tester.

func (*Client) AddCookie

func (cli *Client) AddCookie(key, value string, config *godog.Table) error

AddCookie adds a new cookie to requests.

func (*Client) AddHeaders

func (cli *Client) AddHeaders(headers *godog.Table)

AddHeaders adds headers to known list. It ALWAYS return nil.

func (*Client) AddQueryParam

func (cli *Client) AddQueryParam(key, val string)

AddQueryParam adds a single query parameter.

func (*Client) AddQueryParams

func (cli *Client) AddQueryParams(args *godog.Table)

AddQueryParams adds query parameters.

func (*Client) ClearBody

func (cli *Client) ClearBody()

ClearBody resets request body.

func (*Client) ClientHasCookies

func (cli *Client) ClientHasCookies(not bool, names ...string) error

ClientHasCookies asserts client has or does not have specified cookie list depending on not parameter.

func (Client) Debug

func (Client) Debug()

Debug start debug logs. It will be removed when calling Reset.

func (*Client) DisableAutoResetRequest

func (cli *Client) DisableAutoResetRequest()

func (*Client) DisableCookie

func (cli *Client) DisableCookie()

DisableCookie disables cookie storage for request.

func (Client) DisableDebug

func (Client) DisableDebug()

DisableDebug stops debugging.

func (*Client) DisableRedirect

func (cli *Client) DisableRedirect()

DisableRedirect disables redirection.

func (*Client) DisableTrace

func (cli *Client) DisableTrace()

DisableTrace disables client request tracing.

func (*Client) EmptyResponseBody

func (cli *Client) EmptyResponseBody(not bool, _ ...string) error

EmptyResponseBody asserts response body should or should not be empty depending on not parameter.

Second argument is not used. It is present for interface.AsNot simplification in step definitions..

func (*Client) EnableAutoResetRequest

func (cli *Client) EnableAutoResetRequest()

func (*Client) EnableCookie

func (cli *Client) EnableCookie()

EnableCookie enables cookie storage for request.

func (*Client) ExecuteRequest

func (cli *Client) ExecuteRequest() error

ExecuteRequest builds and executes request through http client.

func (*Client) FollowRedirect

func (cli *Client) FollowRedirect()

FollowRedirect enables redirection.

func (*Client) InitRequest

func (cli *Client) InitRequest(withCookie bool)

InitRequest starts a new request with default parameter.

func (Client) PickArgumentFromURLArg

func (cli Client) PickArgumentFromURLArg(argument, urlCandidate, pickAs string) error

PickArgumentFromURLArg picks header from response.

func (Client) PickFromResponseJSONBody

func (cli Client) PickFromResponseJSONBody(path, pickAs string) error

PickFromResponseJSONBody picks paths value from a response JSON body.

func (Client) PickResponseCookie

func (cli Client) PickResponseCookie(name, pickAs string)

PickResponseCookie picks cookie from response.

func (Client) PickResponseHTMLTag

func (cli Client) PickResponseHTMLTag(tag, attribute, pickAs string, filters *godog.Table) error

PickResponseHTMLTag picks tag value from a response HTML body.

func (Client) PickResponseHeader

func (cli Client) PickResponseHeader(name, pickAs string)

PickResponseHeader picks header from response.

func (*Client) Reset

func (cli *Client) Reset()

Reset resets client instance. Client will be reset to default. Response/request will be forgotten.

func (*Client) ResetCookie

func (cli *Client) ResetCookie()

ResetCookie resets requests cookies.

func (*Client) ResetRequest

func (cli *Client) ResetRequest()

ResetRequest resets client request. If cli.autoResetRequest is enabled, request will automatically be cleared after response parsing.

func (*Client) ResponseCookieDomainShouldOrShouldNotMatch

func (cli *Client) ResponseCookieDomainShouldOrShouldNotMatch(not bool, params ...string) error

ResponseCookieDomainShouldOrShouldNotMatch asserts response cookie domain does/doesn't match expected domains.

func (*Client) ResponseCookiesShouldOrShouldNotBeHTTPOnly

func (cli *Client) ResponseCookiesShouldOrShouldNotBeHTTPOnly(not bool, params ...string) error

ResponseCookiesShouldOrShouldNotBeHTTPOnly asserts response cookies are/aren't HTTP Only.

func (*Client) ResponseCookiesShouldOrShouldNotBeSecure

func (cli *Client) ResponseCookiesShouldOrShouldNotBeSecure(not bool, names ...string) error

ResponseCookiesShouldOrShouldNotBeSecure asserts response cookies are/aren't secure.

func (*Client) ResponseHTMLShouldBeEquivalent

func (cli *Client) ResponseHTMLShouldBeEquivalent(body *godog.DocString) error

ResponseHTMLShouldBeEquivalent asserts response body is a HTML resembling provided.

func (*Client) ResponseHTMLShouldContains

func (cli *Client) ResponseHTMLShouldContains(elements *godog.Table) error

ResponseHTMLShouldContains asserts response HTML body contains provided strings.

func (*Client) ResponseHasCookies

func (cli *Client) ResponseHasCookies(not bool, names ...string) error

ResponseHasCookies asserts response has or does not have specified cookie list depending on not parameter.

func (*Client) ResponseHasStatus

func (cli *Client) ResponseHasStatus(expectedStatus int) error

ResponseHasStatus asserts Response has expected status.

func (*Client) ResponseHeaderShouldOrShouldNotMatch

func (cli *Client) ResponseHeaderShouldOrShouldNotMatch(not bool, params ...string) error

ResponseHeaderShouldOrShouldNotMatch asserts response header match or does not match provided value using provided matcher.

func (*Client) ResponseJSONShouldBeEquivalent

func (cli *Client) ResponseJSONShouldBeEquivalent(expected *godog.DocString) error

ResponseJSONShouldBeEquivalent asserts response body is a JSON resembling provided JSON.

func (*Client) ResponseJSONShouldContain

func (cli *Client) ResponseJSONShouldContain(fully bool, matchPaths *godog.Table) error

ResponseJSONShouldContain asserts response body is a JSON having provided keys. If fully is true, it also ensures no key exists besides provided one. Keys are provided as Path using `.` separators To match insides JSON Array, use Index.

test.0.has matches a path inside: {"test": [{"matches": val}}

func (*Client) SetEndpoint

func (cli *Client) SetEndpoint(endpoint string)

SetEndpoint adds Endpoint to request.

func (*Client) SetFormBody

func (cli *Client) SetFormBody(body *godog.Table)

SetFormBody replaces current request body with new Form body.

func (*Client) SetHeader

func (cli *Client) SetHeader(key, values string)

SetHeader adds a single key,value couple to request headers. It ALWAYS return nil.

func (*Client) SetJSONBody

func (cli *Client) SetJSONBody(body *godog.DocString)

SetJSONBody replaces current request body with new JSON body.

func (*Client) SetMethod

func (cli *Client) SetMethod(method string) error

SetMethod adds HTTP method to request.

func (*Client) SetQueryParams

func (cli *Client) SetQueryParams(args *godog.Table) error

SetQueryParams replaces query parameters with new ones.

func (*Client) SetRequestHeaders

func (cli *Client) SetRequestHeaders(headers *godog.Table)

SetRequestHeaders replaces current headers with list of provided ones. It ALWAYS return nil.

func (*Client) Trace

func (cli *Client) Trace()

Trace activates client request tracing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL