test

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: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONResponse

func JSONResponse(result *contract.OperationResult, schema *api.Schema, log contract.Logger) bool

JSONResponse tests JSON response bodies.

func NewRequest

func NewRequest(op contract.Operation, log contract.Logger) contract.Request

NewRequest creates a new Request instance.

func NoRequest

func NoRequest(err error, log contract.Logger) contract.Request

NoRequest creates a new NullRequest instance.

func Operation

Operation performs a test of an operation by requesting a path and validating the received response headers & content against the definitions founds in an OAS spec file.

func Schema

func Schema(data interface{}, schema *api.Schema, logger contract.Logger) bool

Schema validates data against the provided schema.

func Success

func Success() *contract.OperationResult

Success creates a new OperationResult instance with the Success field set to true to assure maximum SUCCESS.

func TryJSONBooleanResponse

func TryJSONBooleanResponse(respData *[]byte, log contract.Logger) (res bool, err error)

TryJSONBooleanResponse tries to unmarshal respData as a boolean.

func TryJSONNumberResponse

func TryJSONNumberResponse(respData *[]byte, log contract.Logger) (res int64, err error)

TryJSONNumberResponse tries to unmarshal respData as a number.

func TryJSONStringResponse

func TryJSONStringResponse(respData *[]byte, log contract.Logger) (res string, err error)

TryJSONStringResponse tries to unmarshal respData as a string.

Types

type JSONArray

type JSONArray = []interface{}

JSONArray is an array to unmarshal JSONs into.

func TryJSONArrayResponse

func TryJSONArrayResponse(respData *[]byte, log contract.Logger) (res JSONArray, err error)

TryJSONArrayResponse tries to unmarshal respData as an array.

type JSONMap

type JSONMap = map[string]interface{}

JSONMap is a map to unmarshal JSONs into.

func TryJSONObjectResponse

func TryJSONObjectResponse(respData *[]byte, log contract.Logger) (res JSONMap, err error)

TryJSONObjectResponse tries to unmarshal respData as an object.

type NullRequest

type NullRequest struct {
	errors.NullObjectPrototype
}

NullRequest is a placeholder request used when we can't have a real one.

func (*NullRequest) Enrich

func (req *NullRequest) Enrich(en contract.RequestEnrichment)

Enrich reports an error.

func (*NullRequest) Execute

func (req *NullRequest) Execute() *contract.OperationResult

Execute reports an error.

type NullValidator

type NullValidator struct {
	errors.NullObjectPrototype
}

NullValidator is used whenever we can't have a real one from DataResolver.Response(). Reports the contained error on every method call.

func NoValidator

func NoValidator(err error, log contract.Logger) *NullValidator

NoValidator creates a new NullValidator instance.

func (*NullValidator) Expect

func (v *NullValidator) Expect(ex contract.Expectation)

Expect adds an Expectation function to the list.

func (*NullValidator) Validate

Validate runs through the list of expectations and tests the HTTP request instance from the OperationResult against them.

type Request

type Request struct {
	contract.EntityTrait
	HTTPRequest *http.Request
	HTTPClient  *http.Client
	Result      *contract.OperationResult
}

Request represents an operation HTTP request. It contains native API objects, supplies data, tracks results and does logging.

func (*Request) Enrich

func (req *Request) Enrich(en contract.RequestEnrichment)

Enrich extends the internal request with additional data.

func (*Request) Execute

func (req *Request) Execute() *contract.OperationResult

Execute executes the request.

type Validator

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

Validator tests an operation response for compliance with the expectations.

func NewValidator

func NewValidator(log contract.Logger) *Validator

NewValidator creates a new Validator instance.

func (*Validator) Expect

func (v *Validator) Expect(ex contract.Expectation)

Expect adds an Expectation function to the list.

func (*Validator) Validate

Validate runs through the list of expectations and tests the HTTP request instance from the OperationResult against them.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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