contract

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: 4 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataResolver

type DataResolver interface {

	// Host attempts to come up with a valid host name based on the input
	// host hint, which is a spec-specific host identifier.
	// F.e. it's a name for OAS3, but may be index or a literal host for other
	// spec standards.
	Host(hostHint string) ParameterSource
	Security(secName string) Security
	Response(status int64, CT string) Validator
}

DataResolver is an interface to resolution of internal spec data based on user input such as host name or ID, security name, etc.

type EntityTrait

type EntityTrait struct {
	Log Logger
}

EntityTrait contains basic functions shared by multiple different app components, such as logging.

func Entity

func Entity(log Logger) EntityTrait

Entity creates a new EntityTrait instance.

type Expectation

type Expectation func(*OperationResult) bool

Expectation is a function to check various properties of an HTTP request. A list of various expectation compose a Validator.

type LogStyle

type LogStyle interface {
	Default(...interface{}) string
	URL(...interface{}) string
	Method(...interface{}) string
	Op(...interface{}) string
	OK(...interface{}) string
	Failure(...interface{}) string
	Success(...interface{}) string
	Error(...interface{}) string
	ID(...interface{}) string
	ValueExpected(...interface{}) string
	ValueActual(...interface{}) string
	Value(...interface{}) string
}

LogStyle is an interface to log styling.

type Logger

type Logger interface {
	NOMESSAGE(msg string, args ...interface{})
	Parameters(name string, params ParameterSource)

	Print(l int64, msg string, args ...interface{})

	Usage()
	Error(err error)
	LoadingSpec(path string)
	LoadingScript(path string)

	PrintOperations(ops OperationIterator)
	TestingProject(p ProjectInfo)
	TestingOperation(res Operation)

	UsingSecurity(sec Security)
	SecurityHasNoData(sec Security)

	Requesting(method string, url string)

	UsingParameterExample(paramName string, in string, container string, value string)

	Expecting(what string, v string)
	ExpectingProperty(what string, v string)

	HeaderHasNoValue(hdr string)
	ResponseHasWrongStatus(expectedStatus int, actualStatus int)
	ResponseHasWrongContentType(expectedCT string, actualCT string)
	ResponseHasWrongPropertyValue(propName string, expected string, actual string)

	OperationOK()
	OperationFail()

	SchemaOK(schemaName string)
	SchemaFail(schemaName string, errors []gojsonschema.ResultError)

	ScriptExecutionStart(node string)

	XError(err error, style LogStyle, tab TabFn)
}

Logger - interface for test execution loggers.

type Operation

type Operation interface {
	ID() string
	Name() string
	Description() string
	Method() string
	Path() string

	Data() *OperationData
	Result() *OperationResult
	Resolve() DataResolver

	GetRequest() (*http.Request, error)
}

Operation is an interface for accessing operation properties.

type OperationAccess

type OperationAccess interface {
	Operations() OperationIterator
	GetOperation(id string) Operation
}

OperationAccess is an interafce for operation access.

type OperationData

OperationData is an interface to access data from various sources (spec path, spec op, cli input, test output) needed in order to build an http.Request instance.

func (*OperationData) Load

func (data *OperationData) Load(data2 *OperationData)

Load loads parameters from data2.

func (*OperationData) Reload

func (data *OperationData) Reload()

Reload reloads all the sources.

type OperationIterator

type OperationIterator chan Operation

OperationIterator is an iterable channel to receive operations from.

type OperationResult

type OperationResult struct {
	Success       bool
	HTTPRequest   *http.Request
	HTTPResponse  *http.Response
	ResponseBytes []byte
}

OperationResult describes the outcome of an operation test. It is bo te used as a possible source of data for subsequent tests.

func (*OperationResult) And

And creates a new OperationResult instance with the Success field assigned the result of r1.Success && r2.Success.

type OperationResults

type OperationResults map[string]*OperationResult

OperationResults is a map of operation results.

type Parameter

type Parameter struct {
	V      ParameterAccess
	Source string
}

Parameter is a pair of parameter value and name of it's source.

type ParameterAccess

type ParameterAccess func() string

ParameterAccess is a function to provide a value for an operation. Values can be either literal or references. Reference values are used in scripts and look like "#opID.response[JSON_SELECTOR]". They are used to get certain values from one operation response as an input to another operation.

type ParameterIterator

type ParameterIterator chan ParameterTuple

ParameterIterator is an iterable channel to receive tuples of parameter name & value.

type ParameterSource

type ParameterSource interface {
	Iterate() ParameterIterator
}

ParameterSource is an interface for a parameter source. Parameters may come from various places, such as API specs, CLI arguments & another test output.

type ParameterTuple

type ParameterTuple struct {
	Parameter
	N string
}

ParameterTuple is a pair of parameter name and it's value.

type ProjectInfo

type ProjectInfo interface {
	Title() string
	Description() string
	Version() string
}

ProjectInfo is a generic project information.

type Request

type Request interface {
	Enrich(en RequestEnrichment)
	Execute() *OperationResult
}

Request represents an operation HTTP request.

type RequestEnrichment

type RequestEnrichment interface {
	Enrich(request *http.Request, log Logger)
}

RequestEnrichment is a utility type that extends a request instance with additional data.

type RequestEnrichmentParameters

type RequestEnrichmentParameters interface {
	Set
	RequestEnrichment
}

RequestEnrichmentParameters is used to enrich http.Request instances with parameters. Used for headers & query values.

type Script

type Script interface {
	GetExecutionGraph() gcontract.Graph
}

Script is an interface to scenario scripts.

type Security

type Security interface {
	RequestEnrichment
	GetName() string
}

Security is an interface for security mechanisms.

type Set

type Set interface {
	Load(src ParameterSource)
	Reload()
	Require(paramName string)
	Validate() error
	Iterate() ParameterIterator
}

Set is an interface to a set of named values used as input parameters for an operation. Operation parameters come from various sources at various stages of testing, some of them are required, some are optional.

type Spec

type Spec interface {
	ProjectInfo
	OperationAccess
}

Spec is an interface to access specification data.

type StringParameters

type StringParameters interface {
	Set
	String() string
}

StringParameters represent all the available parameters as a string value. At the moment it is used for building a URL.

type TabFn

type TabFn func(log Logger)

TabFn produces indentation when printing nested errors.

func Tab

func Tab(level uint) TabFn

Tab creates an indentation function.

func (TabFn) Shift

func (fn TabFn) Shift() TabFn

Shift produces a new indentation function by adding a level to it.

type Validator

type Validator interface {
	Validate(*OperationResult) *OperationResult
	Expect(Expectation)
}

Validator implements validation/testing logic. It is specific to spec formats and comes from there (via Operation).

Jump to

Keyboard shortcuts

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