expectation

package
v0.0.0-...-00d9010 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QUERY_PARAM string = "Query"
	PATH_PARAM  string = "Path"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback struct {
	Request any    `json:"request"`
	Timeout int    `json:"timeout"`
	Url     string `json:"url"`
	Method  string `json:"method"`
}
type Cookie struct {
	Name  string
	Value string

	Path       string    // optional
	Domain     string    // optional
	Expires    time.Time // optional
	RawExpires string    // for reading cookies only

	// MaxAge=0 means no 'Max-Age' attribute specified.
	// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
	// MaxAge>0 means Max-Age attribute present and given in seconds
	MaxAge   int
	Secure   bool
	HttpOnly bool
	SameSite SameSite
	Raw      string
	Unparsed []string // Raw text of unparsed attribute-value pairs
}

struct taking from net/http package

type Expectation

type Expectation struct {
	Priority int       `json:"priority"`
	Request  Request   `json:"request"`
	Response Response  `json:"response"`
	Callback *Callback `json:"callback"`
}

func (*Expectation) AddRequestParameterMatchers

func (e *Expectation) AddRequestParameterMatchers(pathParams map[string]string, queryParams url.Values) error

func (*Expectation) ValidateRequestParameters

func (e *Expectation) ValidateRequestParameters(requestParamProp schema.RequestParameterProperty) error

ValidateRequestParameters validates the request parameters against the schema

type ExpectationError

type ExpectationError struct {
	Expectation
	ExpectationFieldErrors []ExpectationFieldError
}

func (ExpectationError) Error

func (e ExpectationError) Error() string

type ExpectationFieldError

type ExpectationFieldError struct {
	FieldName string
	Err       error
}

type ExpectationType

type ExpectationType int
const (
	OpenAPI ExpectationType = iota
	Cue
)

type Expectations

type Expectations struct {
	Expectations []Expectation `json:"expectations"`
}

type Matcher

type Matcher[T any] struct {
	Match string `json:"match"`
	Value *T     `json:"value"`
}

func (Matcher[T]) Matches

func (m Matcher[T]) Matches(value *T) bool

type Request

type Request struct {
	Path       string             `json:"path"`
	Method     string             `json:"method"`
	Body       any                `json:"body"`
	Parameters *RequestParameters `json:"params"`
	Headers    map[string]any     `json:"headers"`
	Cookies    *[]Cookie          `json:"cookies"`
}

func (*Request) Match

func (r *Request) Match(req *http.Request, reqParam schema.RequestParameters) bool

func (*Request) Route

func (r *Request) Route() schema.Route

func (*Request) RouteWithParsedPath

func (r *Request) RouteWithParsedPath() (*schema.Route, error)

type RequestParameters

type RequestParameters struct {
	Path  map[string]any `json:"path"`
	Query map[string]any `json:"query"`
}

func (*RequestParameters) Match

type Response

type Response struct {
	Body          any                     `json:"body"`
	GeneratedBody dstruct.GeneratedStruct `json:"-"`
	Status        int                     `json:"status"`
	Headers       *map[string][]string    `json:"headers"`
	Cookies       *[]Cookie               `json:"cookies"`
}

type SameSite

type SameSite int
const (
	SameSiteDefaultMode SameSite = iota + 1
	SameSiteLaxMode
	SameSiteStrictMode
	SameSiteNoneMode
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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