params

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyHost = "HOSTNAME"
)

Various parameters that don't come from specs or input.

Variables

This section is empty.

Functions

func Cast

func Cast(v interface{}) string

Cast casts the given value to string.

func ParseArrayIndexRef

func ParseArrayIndexRef(selector string) (int, int)

ParseArrayIndexRef parses the JSON array index signature [N] in the beginning of selector. It returns the index and number of parsed characters when successful, and (-1, 0) when it was not able to parse.

func ParseObjectFieldRef

func ParseObjectFieldRef(selector string) (string, int)

ParseObjectFieldRef parses the JSON object field signature .fieldName in the beginning of selector. It returns the field name and number of parsed characters when successful, and ("", 0) when it was not able to parse.

func Value

func Value(v string) func() string

Value is the default pass-through function to provide parameters.

Types

type BodyParameters

type BodyParameters struct {
	contract.EntityTrait
	*MultiSet
}

BodyParameters is the source for request header parameters.

func Body

func Body(log contract.Logger) *BodyParameters

Body creates a new BodyParameters instance.

func (BodyParameters) Enrich

func (params BodyParameters) Enrich(req *http.Request, log contract.Logger)

Enrich applies the parameters as header values to the request.

type HeadersParameters

type HeadersParameters struct {
	contract.EntityTrait
	*MultiSet
}

HeadersParameters is the source for request header parameters.

func Headers

func Headers(log contract.Logger) *HeadersParameters

Headers creates a new HeadersParameters instance.

func (HeadersParameters) Enrich

func (params HeadersParameters) Enrich(req *http.Request, log contract.Logger)

Enrich applies the parameters as header values to the request.

type Map

type Map map[string][]contract.Parameter

Map is a map of parameters.

type MemorySource

type MemorySource struct {
	Name string
	Data map[string]string
}

MemorySource is a parameter source which uses a native map as a source storage.

func NewMemorySource

func NewMemorySource(name string) *MemorySource

NewMemorySource creates a new MemoryParameterSource instance.

func (*MemorySource) Add

func (ds *MemorySource) Add(n string, v string)

Add stores a kv pair in the source.

func (*MemorySource) Get

func (ds *MemorySource) Get(pn string) string

Get returns a parameter by it's name.

func (*MemorySource) Iterate

func (ds *MemorySource) Iterate() contract.ParameterIterator

Iterate returns an iterable channel to receive parameter tuples.

type MultiSet

type MultiSet struct {
	Name string
	// contains filtered or unexported fields
}

MultiSet is a set of named values used as input parameters for an operation. Each key can have multiple values.

func NewMultiSet

func NewMultiSet(name string) *MultiSet

NewMultiSet creates a new MultiSet instance.

func (*MultiSet) ClearData

func (params *MultiSet) ClearData()

ClearData clears the data (but keeps the required parameters).

func (*MultiSet) Iterate

func (params *MultiSet) Iterate() contract.ParameterIterator

Iterate creates an iterable channel.

func (*MultiSet) Load

func (params *MultiSet) Load(src contract.ParameterSource)

Load reads parameters from a source.

func (*MultiSet) Reload

func (params *MultiSet) Reload()

Reload re-reads parameters from the saved source.

func (*MultiSet) RememberSource

func (params *MultiSet) RememberSource(src contract.ParameterSource)

RememberSource remembers the source to later Reload() from.

func (*MultiSet) Require

func (params *MultiSet) Require(paramName string)

Require adds a parameter name to the requried parameters list.

func (*MultiSet) StopRememberingSources

func (params *MultiSet) StopRememberingSources()

StopRememberingSources disables the source remembering functionality (see Load).

func (*MultiSet) Validate

func (params *MultiSet) Validate() error

Validate checks that all required parameters have their values available.

type NullSource

type NullSource struct {
	errors.NullObjectPrototype
}

NullSource is a placeholder source used when we can't have a real one.

func NoSource

func NoSource(err error, log contract.Logger) *NullSource

NoSource creates a new NullSource instance.

func (*NullSource) Get

func (ds *NullSource) Get(pn string) string

Get reports an error.

func (*NullSource) Iterate

func (ds *NullSource) Iterate() contract.ParameterIterator

Iterate reports an error.

type QueryParameters

type QueryParameters struct {
	contract.EntityTrait
	*MultiSet
}

QueryParameters is the source for URL query parameters.

func Query

func Query(log contract.Logger) *QueryParameters

Query creates a new QueryParameters instance.

func (QueryParameters) Enrich

func (params QueryParameters) Enrich(req *http.Request, log contract.Logger)

Enrich applies the parameters as query values to the request.

type Reference

type Reference struct {
	OpID     string
	Result   *contract.OperationResult
	Selector string

	Log contract.Logger
}

Reference is a special kind of parameter which comes from an operation response. When a parameter for some operation in a script has a value like "operationID.response.[0].user.id" this means that the actual value comes from JSON response of the operation "operationID" and it's exact location is "[0].user.id" field.

func (Reference) Cast

func (pr Reference) Cast(v interface{}) string

Cast casts the given value to string.

func (Reference) Value

func (pr Reference) Value() contract.ParameterAccess

Value returns a parameter access function which computes and returns a real value.

type ReferenceAccess

type ReferenceAccess func(interface{}, contract.Logger) interface{}

ReferenceAccess is a function to compute and return a referenced value.

func AccessArray

func AccessArray(access ReferenceAccess, i int) ReferenceAccess

AccessArray treats v as an array and returns i-th element of it.

func AccessContent

func AccessContent() ReferenceAccess

AccessContent passes through.

func AccessObject

func AccessObject(access ReferenceAccess, f string) ReferenceAccess

AccessObject treats v as a map and returns f-th element of it.

func NoAccess

func NoAccess(err error) ReferenceAccess

NoAccess is a placeholder ref access function used when we can't have a real one. Usually when it is impossible to parse a reference selector.

func ParseSelector

func ParseSelector(selector string, log contract.Logger) (ReferenceAccess, string)

ParseSelector parses selectors and constructs a parameter access function from it.

type ReferenceMap

type ReferenceMap map[string][]Reference

ReferenceMap is a multimap of ParameterReferences.

type ReferenceSource

type ReferenceSource struct {
	contract.EntityTrait
	Refs ReferenceMap
}

ReferenceSource is a parameter source backed by a response of other operations. When you want to use some of response data as a input for an operation test, you add references here then Load() them into a target parameter set.

func NewReferenceSource

func NewReferenceSource(log contract.Logger) *ReferenceSource

NewReferenceSource creates a new ReferenceSource instance.

func (*ReferenceSource) AddReference

func (src *ReferenceSource) AddReference(pn string, opID string, result *contract.OperationResult, selector string)

AddReference adds a reference to a parameter value, located in response of op.

func (*ReferenceSource) Iterate

Iterate creates an iterable channel.

type Set

type Set struct {
	*MultiSet
}

Set is a set of parameters used in operation testing. It is basically a MultiSet, the only difference being is that Load() overwrites each key with a [1]string instead of appending them.

func NewSet

func NewSet(name string) *Set

NewSet creates a new MultiSet instance.

func (*Set) Load

func (params *Set) Load(src contract.ParameterSource)

Load reads parameters from a source.

type URLParameters

type URLParameters struct {
	contract.EntityTrait
	*Set

	Path string
}

URLParameters is the source for URL path parameters. URLParameters have an implicit requirement for the @HOSTNAME parameter which is an API host name.

func URL

func URL(path string, log contract.Logger) *URLParameters

URL creates a new URLParameters instance.

func (URLParameters) String

func (params URLParameters) String() string

Make creates a URL string value from path template and parameters it has.

Jump to

Keyboard shortcuts

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