Documentation
¶
Index ¶
- Constants
- Variables
- func EitherShortcutOrHTTPSpecAt(node *yaml.Node) error
- func HTTPHeaderNotIn(element, container interface{}) error
- func HTTPNotInBody(element string) error
- func HTTPStatusNotEqual(exp, got interface{}) error
- func InvalidHTTPMethodAt(method string, node *yaml.Node) error
- func MultipleHTTPMethods(firstMethod string, secondMethod string, node *yaml.Node) error
- func NewServerFixture(h nethttp.Handler, useTLS bool) api.Fixture
- func Plugin() api.Plugin
- type Action
- type Defaults
- type Expect
- type HTTPSpec
- type RunData
- type Spec
- type VarEntry
- type Variables
Constants ¶
const ( StateKeyBaseURL = "http.base_url" StateKeyClient = "http.client" )
Variables ¶
var ( // DefaultTimeout is the default timeout used for each individual test // spec. Note that gdt's top-level Scenario.Run handles all timeout and // retry behaviour. DefaultTimeout = "5s" )
var ( // ErrExpectedLocationHeader indicates that the user specified the special // `$LOCATION` string in the `url` or `GET` fields of the HTTP test spec // but there have been no previous HTTP responses to find a Location HTTP // Header within. ErrExpectedLocationHeader = fmt.Errorf( "%w: expected Location HTTP Header in previous response", api.RuntimeError, ) )
Functions ¶
func EitherShortcutOrHTTPSpecAt ¶ added in v1.10.0
EitherShortcutOrHTTPSpecAt returns a parse error indicating the test author included both a shortcut (e.g. `http.get` or just `GET`) AND the long-form `http` object in the same test spec.
func HTTPHeaderNotIn ¶
func HTTPHeaderNotIn(element, container interface{}) error
HTTPHeaderNotIn returns an ErrNotIn when an expected header doesn't appear in a response's headers.
func HTTPNotInBody ¶
HTTPNotInBody returns an ErrNotIn when an expected thing doesn't appear in a a response's Body.
func HTTPStatusNotEqual ¶
func HTTPStatusNotEqual(exp, got interface{}) error
HTTPStatusNotEqual returns an ErrNotEqual when an expected thing doesn't equal an observed thing.
func InvalidHTTPMethodAt ¶ added in v1.10.0
InvalidHTTPMethodAt returns a parse error indicating the test author used an invalid method field value.
func MultipleHTTPMethods ¶ added in v1.10.0
MultipleHTTPMethods returns a parse error indicating the test author specified multiple HTTP methods either full-form or via shortcuts.
func NewServerFixture ¶
NewServerFixture returns a fixture that will start and stop a supplied http.Handler. The returned fixture exposes an "http.base_url" state key that test cases of type "http" examine to determine the base URL the tests should hit
Types ¶
type Action ¶ added in v1.10.0
type Action struct {
// URL being called by HTTP client. Used with the `Method` field.
URL string `yaml:"url,omitempty"`
// HTTP Method specified by HTTP client. Used with the `URL` shortcut field.
Method string `yaml:"method,omitempty"`
// Data is the payload to send along in request
Data interface{} `yaml:"data,omitempty"`
// Shortcut for URL and Method of "GET"
Get string `yaml:"get,omitempty"`
// Shortcut for URL and Method of "POST"
Post string `yaml:"post,omitempty"`
// Shortcut for URL and Method of "PUT"
Put string `yaml:"put,omitempty"`
// Shortcut for URL and Method of "PATCH"
Patch string `yaml:"patch,omitempty"`
// Shortcut for URL and Method of "DELETE"
Delete string `yaml:"delete,omitempty"`
}
Action describes the the HTTP-specific action that is performed by the test.
type Defaults ¶
type Defaults struct {
// contains filtered or unexported fields
}
Defaults is the known HTTP plugin defaults collection
func (*Defaults) BaseURLFromContext ¶
BaseURLFromContext returns the base URL to use when constructing HTTP requests. If the Defaults is non-nil and has a BaseURL value, use that. Otherwise we look up a base URL from the context's fixtures.
func (*Defaults) Merge ¶ added in v1.11.0
Merge merges the supplies map of key/value combinations with the set of handled defaults for the plugin. The supplied key/value map will NOT be unpacked from its top-most plugin named element. So, for example, the kube plugin should expect to get a map that looks like "kube:namespace:<namespace>" and not "namespace:<namespace>".
type Expect ¶
type Expect struct {
// JSON contains the assertions about JSON data in the response
JSON *gdtjson.Expect `yaml:"json,omitempty"`
// Headers contains a list of HTTP headers that should be in the response
Headers []string `yaml:"headers,omitempty"`
// Strings contains a list of strings that should be present in the
// response content
Strings []string `yaml:"strings,omitempty"`
// Status contains the numeric HTTP status code (e.g. 200 or 404) that
// should be returned in the HTTP response
Status *int `yaml:"status,omitempty"`
}
Expect contains one or more assertions about an HTTP response
type HTTPSpec ¶ added in v1.10.0
type HTTPSpec struct {
Action
}
HTTPSpec is the complex type containing all of the HTTP-specific actions. Most users will use the `GET`, `http.get` and similar shortcut fields.
type RunData ¶
RunData is data stored in the context about the run. It is fetched from the gdtcontext.PriorRun() function and evaluated for things like the special `$LOCATION` URL value.
type Spec ¶
type Spec struct {
api.Spec
// HTTP is the complex type containing all of the HTTP-specific actions and
// assertions. Most users will use the `URL`/`Method`, `GET`, `http.get`
// and similar shortcut fields.
HTTP *HTTPSpec `yaml:"http,omitempty"`
// Shortcut for `http.url`
URL string `yaml:"url,omitempty"`
// Shortcut for `http.method`
Method string `yaml:"method,omitempty"`
// Shortcut for `http.get`
GET string `yaml:"GET,omitempty"`
// Shortcut for `http.post`
POST string `yaml:"POST,omitempty"`
// Shortcut for `http.put`
PUT string `yaml:"PUT,omitempty"`
// Shortcut for `http.patch`
PATCH string `yaml:"PATCH,omitempty"`
// Shortcut for `http.delete`
DELETE string `yaml:"DELETE,omitempty"`
// Shortcut for `http.data`
Data any `yaml:"data,omitempty"`
// Assert is the assertions for the HTTP response
Assert *Expect `yaml:"assert,omitempty"`
// Var allows the test author to save arbitrary data to the test scenario,
// facilitating the passing of variables between test specs potentially
// provided by different gdt Plugins.
Var Variables `yaml:"var,omitempty"`
}
Spec describes a test of a single HTTP request and response
type VarEntry ¶ added in v1.10.0
type VarEntry struct {
// From is a string that indicates where the value of the variable will be
// sourced from. This string is a JSONPath expression that contains
// instructions on how to extract a particular field from the HTTP response.
From string `yaml:"from"`
}