Documentation
¶
Overview ¶
Package gdutils provides APIContext struct with methods that may be used for behavioral testing of HTTP API.
APIContext may be initialized by two ways:
First, returns *APIContext with default services:
func NewDefaultAPIContext(isDebug bool, jsonSchemaDir string) *APIContext
Second, more customisable returns *APIContext with provided services:
func NewAPIContext(cli *http.Client, c cache.Cache, jv SchemaValidators, p PathFinders, f Formatters, d debugger.Debugger) *APIContext
No matter which way you choose, you can inject your custom services afterwards with one of available setters:
func (apiCtx *APIContext) SetDebugger(d debugger.Debugger) func (apiCtx *APIContext) SetCache(c cache.Cache) func (apiCtx *APIContext) SetRequestDoer(r httpctx.RequestDoer) func (apiCtx *APIContext) SetTemplateEngine(t template.Engine) func (apiCtx *APIContext) SetSchemaStringValidator(j validator.SchemaValidator) func (apiCtx *APIContext) SetSchemaReferenceValidator(j validator.SchemaValidator) func (apiCtx *APIContext) SetJSONPathFinder(r pathfinder.PathFinder) func (apiCtx *APIContext) SetJSONFormatter(jf formatter.Formatter) func (apiCtx *APIContext) SetXMLPathFinder(r pathfinder.PathFinder) func (apiCtx *APIContext) SetYAMLPathFinder(r pathfinder.PathFinder) func (apiCtx *APIContext) SetYAMLFormatter(yd formatter.Formatter) func (apiCtx *APIContext) SetXMLFormatter(xf formatter.Formatter)
Those services will be used in utility methods. For example, if you want to use your own debugger, create your own struct, implement debugger.Debugger interface on it, and then inject it with "func (apiCtx *APIContext) SetDebugger(d debugger.Debugger)" method.
Testing HTTP API usually consist the following aspects:
* Data generation:
func (apiCtx *APIContext) IGenerateARandomIntInTheRangeToAndSaveItAs(from, to int, cacheKey string) error func (apiCtx *APIContext) IGenerateARandomFloatInTheRangeToAndSaveItAs(from, to int, cacheKey string) error func (apiCtx *APIContext) IGenerateARandomRunesInTheRangeToAndSaveItAs(charset string) func(from, to int, cacheKey string) error func (apiCtx *APIContext) IGenerateARandomSentenceInTheRangeFromToWordsAndSaveItAs(charset string, wordMinLength, wordMaxLength int) func(from, to int, cacheKey string) error func (apiCtx *APIContext) IGetTimeAndTravelByAndSaveItAs(t time.Time, timeDirection timeutils.TimeDirection, timeDuration time.Duration, cacheKey string) error func (apiCtx *APIContext) IGenerateCurrentTimeAndTravelByAndSaveItAs(timeDirection timeutils.TimeDirection, timeDuration time.Duration, cacheKey string) error
* Sending HTTP(s) requests:
func (apiCtx *APIContext) ISendRequestToWithBodyAndHeaders(method, urlTemplate string, bodyTemplate string) error
or
func (apiCtx *APIContext) IPrepareNewRequestToAndSaveItAs(method, urlTemplate, cacheKey string) error func (apiCtx *APIContext) ISetFollowingHeadersForPreparedRequest(cacheKey string, headersTemplate string) error func (apiCtx *APIContext) ISetFollowingFormForPreparedRequest(cacheKey, formTemplate string) error func (apiCtx *APIContext) ISetFollowingCookiesForPreparedRequest(cacheKey, cookiesTemplate string) error func (apiCtx *APIContext) ISetFollowingBodyForPreparedRequest(cacheKey string, bodyTemplate string) error func (apiCtx *APIContext) ISendRequest(cacheKey string) error
* Assertions:
func (apiCtx *APIContext) TheResponseStatusCodeShouldBe(code int) error func (apiCtx *APIContext) TheResponseBodyShouldHaveFormat(dataFormat format.DataFormat) error func (apiCtx *APIContext) TheResponseShouldHaveCookie(name string) error func (apiCtx *APIContext) TheResponseShouldHaveCookieOfValue(name, valueTemplate string) error func (apiCtx *APIContext) TheResponseShouldHaveNode(dataFormat format.DataFormat, exprTemplate string) error func (apiCtx *APIContext) TheNodeShouldNotBe(df format.DataFormat, exprTemplate string, goType string) error func (apiCtx *APIContext) TheNodeShouldBe(df format.DataFormat, exprTemplate string, goType string) error func (apiCtx *APIContext) TheNodeShouldMatchRegExp(dataFormat format.DataFormat, exprTemplate, regExpTemplate string) error func (apiCtx *APIContext) TheResponseShouldHaveNodes(dataFormat format.DataFormat, expressionsTemplates string) error func (apiCtx *APIContext) TheNodeShouldBeSliceOfLength(dataFormat format.DataFormat, exprTemplate string, length int) error func (apiCtx *APIContext) TheNodeShouldBeOfValue(dataFormat format.DataFormat, exprTemplate, dataType, dataValue string) error func (apiCtx *APIContext) TheResponseShouldHaveHeader(name string) error func (apiCtx *APIContext) TheResponseShouldHaveHeaderOfValue(name, value string) error func (apiCtx *APIContext) IValidateLastResponseBodyWithSchemaReference(referenceTemplate string) error func (apiCtx *APIContext) IValidateLastResponseBodyWithSchemaString(schemaTemplate string) error func (apiCtx *APIContext) IValidateNodeWithSchemaString(dataFormat format.DataFormat, exprTemplate, schemaTemplate string) error func (apiCtx *APIContext) IValidateNodeWithSchemaReference(dataFormat format.DataFormat, exprTemplate, referenceTemplate string) error func (apiCtx *APIContext) TimeBetweenLastHTTPRequestResponseShouldBeLessThanOrEqualTo(timeInterval time.Duration) error
* Preserving JSON nodes:
func (apiCtx *APIContext) ISaveFromTheLastResponseNodeAs(dataFormat format.DataFormat, exprTemplate, cacheKey string) error func (apiCtx *APIContext) ISaveAs(valueTemplate, cacheKey string) error
* Flow control:
func (apiCtx *APIContext) IWait(timeInterval time.Duration) error
* Debugging:
func (apiCtx *APIContext) IPrintLastResponseBody() error func (apiCtx *APIContext) IStartDebugMode() error func (apiCtx *APIContext) IStopDebugMode() error
Index ¶
- type APIContext
- func (apiCtx *APIContext) GetLastResponse() (*http.Response, error)
- func (apiCtx *APIContext) GetLastResponseBody() ([]byte, error)
- func (apiCtx *APIContext) GetPreparedRequest(cacheKey string) (*http.Request, error)
- func (apiCtx *APIContext) IGenerateARandomFloatInTheRangeToAndSaveItAs(from, to int, cacheKey string) error
- func (apiCtx *APIContext) IGenerateARandomIntInTheRangeToAndSaveItAs(from, to int, cacheKey string) error
- func (apiCtx *APIContext) IGenerateARandomRunesInTheRangeToAndSaveItAs(charset string) func(from, to int, cacheKey string) error
- func (apiCtx *APIContext) IGenerateARandomSentenceInTheRangeFromToWordsAndSaveItAs(charset string, wordMinLength, wordMaxLength int) func(from, to int, cacheKey string) error
- func (apiCtx *APIContext) IGenerateCurrentTimeAndTravelByAndSaveItAs(timeDirection timeutils.TimeDirection, timeDuration time.Duration, ...) error
- func (apiCtx *APIContext) IGetTimeAndTravelByAndSaveItAs(t time.Time, timeDirection timeutils.TimeDirection, timeDuration time.Duration, ...) error
- func (apiCtx *APIContext) IPrepareNewRequestToAndSaveItAs(method, urlTemplate, cacheKey string) error
- func (apiCtx *APIContext) IPrintLastResponseBody() error
- func (apiCtx *APIContext) ISaveAs(valueTemplate, cacheKey string) error
- func (apiCtx *APIContext) ISaveFromTheLastResponseNodeAs(dataFormat format.DataFormat, exprTemplate, cacheKey string) error
- func (apiCtx *APIContext) ISendRequest(cacheKey string) error
- func (apiCtx *APIContext) ISendRequestToWithBodyAndHeaders(method, urlTemplate string, bodyTemplate string) error
- func (apiCtx *APIContext) ISetFollowingBodyForPreparedRequest(cacheKey, bodyTemplate string) error
- func (apiCtx *APIContext) ISetFollowingCookiesForPreparedRequest(cacheKey, cookiesTemplate string) error
- func (apiCtx *APIContext) ISetFollowingFormForPreparedRequest(cacheKey, formTemplate string) error
- func (apiCtx *APIContext) ISetFollowingHeadersForPreparedRequest(cacheKey, headersTemplate string) error
- func (apiCtx *APIContext) IStartDebugMode() error
- func (apiCtx *APIContext) IStopDebugMode() error
- func (apiCtx *APIContext) IValidateLastResponseBodyWithSchemaReference(referenceTemplate string) error
- func (apiCtx *APIContext) IValidateLastResponseBodyWithSchemaString(schema string) error
- func (apiCtx *APIContext) IValidateNodeWithSchemaReference(dataFormat format.DataFormat, exprTemplate, referenceTemplate string) error
- func (apiCtx *APIContext) IValidateNodeWithSchemaString(dataFormat format.DataFormat, exprTemplate, schemaTemplate string) error
- func (apiCtx *APIContext) IWait(timeInterval time.Duration) error
- func (apiCtx *APIContext) ResetState(isDebug bool)
- func (apiCtx *APIContext) SetCache(c cache.Cache)
- func (apiCtx *APIContext) SetDebugger(d debugger.Debugger)
- func (apiCtx *APIContext) SetJSONFormatter(jf formatter.Formatter)
- func (apiCtx *APIContext) SetJSONPathFinder(r pathfinder.PathFinder)
- func (apiCtx *APIContext) SetRequestDoer(r httpctx.RequestDoer)
- func (apiCtx *APIContext) SetSchemaReferenceValidator(j validator.SchemaValidator)
- func (apiCtx *APIContext) SetSchemaStringValidator(j validator.SchemaValidator)
- func (apiCtx *APIContext) SetTemplateEngine(t template.Engine)
- func (apiCtx *APIContext) SetXMLFormatter(xf formatter.Formatter)
- func (apiCtx *APIContext) SetXMLPathFinder(r pathfinder.PathFinder)
- func (apiCtx *APIContext) SetYAMLFormatter(yd formatter.Formatter)
- func (apiCtx *APIContext) SetYAMLPathFinder(r pathfinder.PathFinder)
- func (apiCtx *APIContext) TheNodeShouldBe(dataFormat format.DataFormat, exprTemplate string, goType string) error
- func (apiCtx *APIContext) TheNodeShouldBeOfValue(dataFormat format.DataFormat, exprTemplate, dataType, dataValue string) error
- func (apiCtx *APIContext) TheNodeShouldBeSliceOfLength(dataFormat format.DataFormat, exprTemplate string, length int) error
- func (apiCtx *APIContext) TheNodeShouldMatchRegExp(dataFormat format.DataFormat, exprTemplate, regExpTemplate string) error
- func (apiCtx *APIContext) TheNodeShouldNotBe(dataFormat format.DataFormat, exprTemplate string, goType string) error
- func (apiCtx *APIContext) TheResponseBodyShouldHaveFormat(dataFormat format.DataFormat) error
- func (apiCtx *APIContext) TheResponseShouldHaveCookie(name string) error
- func (apiCtx *APIContext) TheResponseShouldHaveCookieOfValue(name, valueTemplate string) error
- func (apiCtx *APIContext) TheResponseShouldHaveHeader(name string) error
- func (apiCtx *APIContext) TheResponseShouldHaveHeaderOfValue(name, valueTemplate string) error
- func (apiCtx *APIContext) TheResponseShouldHaveNode(dataFormat format.DataFormat, exprTemplate string) error
- func (apiCtx *APIContext) TheResponseShouldHaveNodes(dataFormat format.DataFormat, expressionsTemplate string) error
- func (apiCtx *APIContext) TheResponseStatusCodeShouldBe(code int) error
- func (apiCtx *APIContext) TimeBetweenLastHTTPRequestResponseShouldBeLessThanOrEqualTo(timeInterval time.Duration) error
- type BodyHeaders
- type Formatters
- type PathFinders
- type SchemaValidators
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIContext ¶ added in v0.14.1
type APIContext struct {
// Debugger represents debugger.
Debugger debugger.Debugger
// Cache is storage for data.
Cache cache.Cache
// RequestDoer is service that has ability to send HTTP(s) requests.
RequestDoer httpctx.RequestDoer
// TemplateEngine is entity that has ability to work with template values.
TemplateEngine template.Engine
// SchemaValidators holds validators available to validate data against schemas.
SchemaValidators SchemaValidators
// PathFinders are entities that has ability to obtain data from different data formats.
PathFinders PathFinders
// Formatters are entities that has ability to format data in particular format.
Formatters Formatters
// contains filtered or unexported fields
}
APIContext holds utility services for working with HTTP(s) API.
func NewAPIContext ¶ added in v0.14.1
func NewAPIContext(cli *http.Client, c cache.Cache, jv SchemaValidators, p PathFinders, f Formatters, d debugger.Debugger) *APIContext
NewAPIContext returns *APIContext
func NewDefaultAPIContext ¶ added in v0.14.1
func NewDefaultAPIContext(isDebug bool, jsonSchemaDir string) *APIContext
NewDefaultAPIContext returns *APIContext with default services. jsonSchemaDir may be empty string or valid full path to directory with JSON schemas.
func (*APIContext) GetLastResponse ¶ added in v0.14.1
func (apiCtx *APIContext) GetLastResponse() (*http.Response, error)
GetLastResponse returns last HTTP(s) response.
func (*APIContext) GetLastResponseBody ¶ added in v0.14.1
func (apiCtx *APIContext) GetLastResponseBody() ([]byte, error)
GetLastResponseBody returns last HTTP(s) response body. internally method creates new NoPCloser on last response so this method is safe to reuse many times
func (*APIContext) GetPreparedRequest ¶ added in v0.14.1
func (apiCtx *APIContext) GetPreparedRequest(cacheKey string) (*http.Request, error)
GetPreparedRequest returns prepared request from cache or error if failed
func (*APIContext) IGenerateARandomFloatInTheRangeToAndSaveItAs ¶ added in v0.14.1
func (apiCtx *APIContext) IGenerateARandomFloatInTheRangeToAndSaveItAs(from, to int, cacheKey string) error
IGenerateARandomFloatInTheRangeToAndSaveItAs generates random float from provided range and preserve it under given cacheKey key.
func (*APIContext) IGenerateARandomIntInTheRangeToAndSaveItAs ¶ added in v0.14.1
func (apiCtx *APIContext) IGenerateARandomIntInTheRangeToAndSaveItAs(from, to int, cacheKey string) error
IGenerateARandomIntInTheRangeToAndSaveItAs generates random integer from provided range and preserve it under given cacheKey key.
func (*APIContext) IGenerateARandomRunesInTheRangeToAndSaveItAs ¶ added in v0.14.1
func (apiCtx *APIContext) IGenerateARandomRunesInTheRangeToAndSaveItAs(charset string) func(from, to int, cacheKey string) error
IGenerateARandomRunesInTheRangeToAndSaveItAs creates random runes generator func using provided charset return func creates runes from provided range and preserve it under given cacheKey
func (*APIContext) IGenerateARandomSentenceInTheRangeFromToWordsAndSaveItAs ¶ added in v0.14.1
func (apiCtx *APIContext) IGenerateARandomSentenceInTheRangeFromToWordsAndSaveItAs(charset string, wordMinLength, wordMaxLength int) func(from, to int, cacheKey string) error
IGenerateARandomSentenceInTheRangeFromToWordsAndSaveItAs creates generator func for creating random sentences each sentence has length from - to as provided in params and is saved in provided cacheKey
func (*APIContext) IGenerateCurrentTimeAndTravelByAndSaveItAs ¶ added in v0.14.1
func (apiCtx *APIContext) IGenerateCurrentTimeAndTravelByAndSaveItAs(timeDirection timeutils.TimeDirection, timeDuration time.Duration, cacheKey string) error
IGenerateCurrentTimeAndTravelByAndSaveItAs creates current time object, move timeDuration in time and save it in cache under given cacheKey.
func (*APIContext) IGetTimeAndTravelByAndSaveItAs ¶ added in v0.14.1
func (apiCtx *APIContext) IGetTimeAndTravelByAndSaveItAs(t time.Time, timeDirection timeutils.TimeDirection, timeDuration time.Duration, cacheKey string) error
IGetTimeAndTravelByAndSaveItAs accepts time object, move timeDuration in time and save it in cache under given cacheKey.
func (*APIContext) IPrepareNewRequestToAndSaveItAs ¶ added in v0.14.1
func (apiCtx *APIContext) IPrepareNewRequestToAndSaveItAs(method, urlTemplate, cacheKey string) error
IPrepareNewRequestToAndSaveItAs prepares new request and saves it in cache under cacheKey
func (*APIContext) IPrintLastResponseBody ¶ added in v0.14.1
func (apiCtx *APIContext) IPrintLastResponseBody() error
IPrintLastResponseBody prints last response from request.
func (*APIContext) ISaveAs ¶ added in v0.14.1
func (apiCtx *APIContext) ISaveAs(valueTemplate, cacheKey string) error
ISaveAs saves into cache arbitrary passed data.
func (*APIContext) ISaveFromTheLastResponseNodeAs ¶ added in v0.14.1
func (apiCtx *APIContext) ISaveFromTheLastResponseNodeAs(dataFormat format.DataFormat, exprTemplate, cacheKey string) error
ISaveFromTheLastResponseNodeAs saves from last response body node under given cacheKey key. expr should be valid according to injected PathResolver of given data type
func (*APIContext) ISendRequest ¶ added in v0.14.1
func (apiCtx *APIContext) ISendRequest(cacheKey string) error
ISendRequest sends previously prepared HTTP(s) request.
func (*APIContext) ISendRequestToWithBodyAndHeaders ¶ added in v0.14.1
func (apiCtx *APIContext) ISendRequestToWithBodyAndHeaders(method, urlTemplate string, bodyTemplate string) error
ISendRequestToWithFormatBodyAndHeaders sends HTTP(s) requests with provided body and headers. Argument "method" indices HTTP request method for example: "POST", "GET" etc. Argument "urlTemplate" should be full valid URL. May include template values. Argument "bodyTemplate" should contain data (may include template values) in JSON or YAML format with keys "body" and "headers".
func (*APIContext) ISetFollowingBodyForPreparedRequest ¶ added in v0.14.1
func (apiCtx *APIContext) ISetFollowingBodyForPreparedRequest(cacheKey, bodyTemplate string) error
ISetFollowingBodyForPreparedRequest sets body for previously prepared request bodyTemplate may be in any format and accepts template values
func (*APIContext) ISetFollowingCookiesForPreparedRequest ¶ added in v0.14.1
func (apiCtx *APIContext) ISetFollowingCookiesForPreparedRequest(cacheKey, cookiesTemplate string) error
ISetFollowingCookiesForPreparedRequest sets cookies for previously prepared request. cookiesTemplate should be YAML or JSON deserializable on []http.Cookie.
func (*APIContext) ISetFollowingFormForPreparedRequest ¶ added in v0.14.1
func (apiCtx *APIContext) ISetFollowingFormForPreparedRequest(cacheKey, formTemplate string) error
ISetFollowingFormForPreparedRequest sets form for previously prepared request. Internally method sets proper Content-Type: multipart/form-data header. formTemplate should be YAML or JSON deserializable on map[string]string.
func (*APIContext) ISetFollowingHeadersForPreparedRequest ¶ added in v0.14.1
func (apiCtx *APIContext) ISetFollowingHeadersForPreparedRequest(cacheKey, headersTemplate string) error
ISetFollowingHeadersForPreparedRequest sets provided headers for previously prepared request. incoming data should be in JSON or YAML format
func (*APIContext) IStartDebugMode ¶ added in v0.14.1
func (apiCtx *APIContext) IStartDebugMode() error
IStartDebugMode starts debugging mode
func (*APIContext) IStopDebugMode ¶ added in v0.14.1
func (apiCtx *APIContext) IStopDebugMode() error
IStopDebugMode stops debugging mode
func (*APIContext) IValidateLastResponseBodyWithSchemaReference ¶ added in v0.14.1
func (apiCtx *APIContext) IValidateLastResponseBodyWithSchemaReference(referenceTemplate string) error
IValidateLastResponseBodyWithSchemaReference validates last response body against schema as provided in referenceTemplate. referenceTemplate may be: URL or full/relative path
func (*APIContext) IValidateLastResponseBodyWithSchemaString ¶ added in v0.14.1
func (apiCtx *APIContext) IValidateLastResponseBodyWithSchemaString(schema string) error
IValidateLastResponseBodyWithSchemaString validates last response body against schema.
func (*APIContext) IValidateNodeWithSchemaReference ¶ added in v0.14.1
func (apiCtx *APIContext) IValidateNodeWithSchemaReference(dataFormat format.DataFormat, exprTemplate, referenceTemplate string) error
IValidateNodeWithSchemaReference validates last response body node against schema as provided in referenceTemplate
func (*APIContext) IValidateNodeWithSchemaString ¶ added in v0.14.1
func (apiCtx *APIContext) IValidateNodeWithSchemaString(dataFormat format.DataFormat, exprTemplate, schemaTemplate string) error
IValidateNodeWithSchemaString validates last response body JSON node against schema
func (*APIContext) IWait ¶ added in v0.14.1
func (apiCtx *APIContext) IWait(timeInterval time.Duration) error
IWait waits for given timeInterval amount of time
func (*APIContext) ResetState ¶ added in v0.14.1
func (apiCtx *APIContext) ResetState(isDebug bool)
ResetState resets state of APIContext to initial.
func (*APIContext) SetCache ¶ added in v0.14.1
func (apiCtx *APIContext) SetCache(c cache.Cache)
SetCache sets new Cache for APIContext.
func (*APIContext) SetDebugger ¶ added in v0.14.1
func (apiCtx *APIContext) SetDebugger(d debugger.Debugger)
SetDebugger sets new debugger for APIContext.
func (*APIContext) SetJSONFormatter ¶ added in v0.14.1
func (apiCtx *APIContext) SetJSONFormatter(jf formatter.Formatter)
SetJSONFormatter sets new JSON formatter for APIContext.
func (*APIContext) SetJSONPathFinder ¶ added in v0.14.1
func (apiCtx *APIContext) SetJSONPathFinder(r pathfinder.PathFinder)
SetJSONPathFinder sets new JSON pathfinder for APIContext.
func (*APIContext) SetRequestDoer ¶ added in v0.14.1
func (apiCtx *APIContext) SetRequestDoer(r httpctx.RequestDoer)
SetRequestDoer sets new RequestDoer for APIContext.
func (*APIContext) SetSchemaReferenceValidator ¶ added in v0.14.1
func (apiCtx *APIContext) SetSchemaReferenceValidator(j validator.SchemaValidator)
SetSchemaReferenceValidator sets new schema ReferenceValidator for APIContext.
func (*APIContext) SetSchemaStringValidator ¶ added in v0.14.1
func (apiCtx *APIContext) SetSchemaStringValidator(j validator.SchemaValidator)
SetSchemaStringValidator sets new schema StringValidator for APIContext.
func (*APIContext) SetTemplateEngine ¶ added in v0.14.1
func (apiCtx *APIContext) SetTemplateEngine(t template.Engine)
SetTemplateEngine sets new template Engine for APIContext.
func (*APIContext) SetXMLFormatter ¶ added in v0.14.1
func (apiCtx *APIContext) SetXMLFormatter(xf formatter.Formatter)
SetXMLFormatter sets new XML formatter for APIContext.
func (*APIContext) SetXMLPathFinder ¶ added in v0.14.1
func (apiCtx *APIContext) SetXMLPathFinder(r pathfinder.PathFinder)
SetXMLPathFinder sets new XML pathfinder for APIContext.
func (*APIContext) SetYAMLFormatter ¶ added in v0.14.1
func (apiCtx *APIContext) SetYAMLFormatter(yd formatter.Formatter)
SetYAMLFormatter sets new YAML formatter for APIContext.
func (*APIContext) SetYAMLPathFinder ¶ added in v0.14.1
func (apiCtx *APIContext) SetYAMLPathFinder(r pathfinder.PathFinder)
SetYAMLPathFinder sets new YAML pathfinder for APIContext.
func (*APIContext) TheNodeShouldBe ¶ added in v0.14.1
func (apiCtx *APIContext) TheNodeShouldBe(dataFormat format.DataFormat, exprTemplate string, goType string) error
TheNodeShouldBe checks whether node from last response body is of provided type goType may be one of: nil, string, int, float, bool, map, slice expr should be valid according to injected PathResolver
func (*APIContext) TheNodeShouldBeOfValue ¶ added in v0.14.1
func (apiCtx *APIContext) TheNodeShouldBeOfValue(dataFormat format.DataFormat, exprTemplate, dataType, dataValue string) error
TheNodeShouldBeOfValue compares json node value from expression to expected by user dataValue of given by user dataType Available data types are listed in switch section in each case directive. expr should be valid according to injected PathFinder for provided dataFormat.
func (*APIContext) TheNodeShouldBeSliceOfLength ¶ added in v0.14.1
func (apiCtx *APIContext) TheNodeShouldBeSliceOfLength(dataFormat format.DataFormat, exprTemplate string, length int) error
TheNodeShouldBeSliceOfLength checks whether given key is slice and has given length expr should be valid according to injected PathFinder for provided dataFormat
func (*APIContext) TheNodeShouldMatchRegExp ¶ added in v0.14.1
func (apiCtx *APIContext) TheNodeShouldMatchRegExp(dataFormat format.DataFormat, exprTemplate, regExpTemplate string) error
TheNodeShouldMatchRegExp checks whether last response body node matches provided regExp.
func (*APIContext) TheNodeShouldNotBe ¶ added in v0.14.1
func (apiCtx *APIContext) TheNodeShouldNotBe(dataFormat format.DataFormat, exprTemplate string, goType string) error
TheNodeShouldNotBe checks whether node from last response body is not of provided type. goType may be one of: nil, string, int, float, bool, map, slice, expr should be valid according to injected PathFinder for given data format.
func (*APIContext) TheResponseBodyShouldHaveFormat ¶ added in v0.14.1
func (apiCtx *APIContext) TheResponseBodyShouldHaveFormat(dataFormat format.DataFormat) error
TheResponseBodyShouldHaveFormat checks whether last response body has given data format. Available data formats are listed in format package.
func (*APIContext) TheResponseShouldHaveCookie ¶ added in v0.14.1
func (apiCtx *APIContext) TheResponseShouldHaveCookie(name string) error
TheResponseShouldHaveCookie checks whether last HTTP(s) response has cookie of given name.
func (*APIContext) TheResponseShouldHaveCookieOfValue ¶ added in v0.14.1
func (apiCtx *APIContext) TheResponseShouldHaveCookieOfValue(name, valueTemplate string) error
TheResponseShouldHaveCookieOfValue checks whether last HTTP(s) response has cookie of given name and value.
func (*APIContext) TheResponseShouldHaveHeader ¶ added in v0.14.1
func (apiCtx *APIContext) TheResponseShouldHaveHeader(name string) error
TheResponseShouldHaveHeader checks whether last HTTP response has given header.
func (*APIContext) TheResponseShouldHaveHeaderOfValue ¶ added in v0.14.1
func (apiCtx *APIContext) TheResponseShouldHaveHeaderOfValue(name, valueTemplate string) error
TheResponseShouldHaveHeaderOfValue checks whether last HTTP response has given header with provided valueTemplate.
func (*APIContext) TheResponseShouldHaveNode ¶ added in v0.14.1
func (apiCtx *APIContext) TheResponseShouldHaveNode(dataFormat format.DataFormat, exprTemplate string) error
TheResponseShouldHaveNode checks whether last response body contains given node. expr should be valid according to injected PathFinder for given data format
func (*APIContext) TheResponseShouldHaveNodes ¶ added in v0.14.1
func (apiCtx *APIContext) TheResponseShouldHaveNodes(dataFormat format.DataFormat, expressionsTemplate string) error
TheResponseShouldHaveNodes checks whether last request body has keys defined in string separated by comma nodeExprs should be valid according to injected PathFinder expressions separated by comma (,)
func (*APIContext) TheResponseStatusCodeShouldBe ¶ added in v0.14.1
func (apiCtx *APIContext) TheResponseStatusCodeShouldBe(code int) error
TheResponseStatusCodeShouldBe compare last response status code with given in argument.
func (*APIContext) TimeBetweenLastHTTPRequestResponseShouldBeLessThanOrEqualTo ¶ added in v0.14.1
func (apiCtx *APIContext) TimeBetweenLastHTTPRequestResponseShouldBeLessThanOrEqualTo(timeInterval time.Duration) error
TimeBetweenLastHTTPRequestResponseShouldBeLessThanOrEqualTo asserts that last HTTP request-response time is <= than expected timeInterval. timeInterval should be string acceptable by time.ParseDuration func
type BodyHeaders ¶ added in v0.7.4
type BodyHeaders struct {
// Body should contain HTTP(s) request body
Body interface{}
// Headers should contain HTTP(s) request headers
Headers map[string]string
}
BodyHeaders is entity that holds information about request body and request headers.
type Formatters ¶ added in v0.12.0
type Formatters struct {
// JSON is entity that has ability to serialize and deserialize JSON bytes.
JSON formatter.Formatter
// YAML is entity that has ability to serialize and deserialize YAML bytes.
YAML formatter.Formatter
// XML is entity that has ability to serialize and deserialize XML bytes.
XML formatter.Formatter
}
Formatters is container for entities that know how to serialize and deserialize data.
type PathFinders ¶ added in v0.12.0
type PathFinders struct {
// JSON is entity that has ability to obtain data from bytes in JSON format.
JSON pathfinder.PathFinder
// YAML is entity that has ability to obtain data from bytes in YAML format.
YAML pathfinder.PathFinder
// XML is entity that has ability to obtain data from bytes in XML format.
XML pathfinder.PathFinder
}
PathFinders is container for different data types pathfinders.
type SchemaValidators ¶ added in v0.12.0
type SchemaValidators struct {
// StringValidator represents entity that has ability to validate document against string of containing schema.
StringValidator validator.SchemaValidator
// ReferenceValidator represents entity that has ability to validate document against string with reference
// to schema, which may be URL or relative/full OS path for example.
ReferenceValidator validator.SchemaValidator
}
SchemaValidators is container for JSON schema validators.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pkg holds packages used for steps.
|
Package pkg holds packages used for steps. |
|
cache
Package cache holds definition of Cache used for storing and retrieving data.
|
Package cache holds definition of Cache used for storing and retrieving data. |
|
debugger
Package debugger holds definition of Debugger.
|
Package debugger holds definition of Debugger. |
|
formatter
Package formatter holds utilities for working with different data formats.
|
Package formatter holds utilities for working with different data formats. |
|
httpcache
Package httpcache connects package httpctx and cache
|
Package httpcache connects package httpctx and cache |
|
httpctx
Package httpctx holds utilities for working with HTTP protocol.
|
Package httpctx holds utilities for working with HTTP protocol. |
|
mathutils
Package mathutils holds utilities related with mathematics.
|
Package mathutils holds utilities related with mathematics. |
|
pathfinder
Package pathfinder holds utilities for working with JSON path.
|
Package pathfinder holds utilities for working with JSON path. |
|
reflectutils
Package reflectutils holds utility methods related with reflect package.
|
Package reflectutils holds utility methods related with reflect package. |
|
stringutils
Package stringutils holds utility methods for working with strings.
|
Package stringutils holds utility methods for working with strings. |
|
template
Package template holds utilities for working with templates.
|
Package template holds utilities for working with templates. |
|
validator
Package validator holds utilities for validating data.
|
Package validator holds utilities for validating data. |