planner

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 8 Imported by: 2

Documentation

Overview

Package planner provides functionalities for deciding what expectation matches the given request.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchBody

func MatchBody(expected Expectation, actual *http.Request) (err error)

MatchBody matches the payload of a given request.

func MatchHeader

func MatchHeader(expected Expectation, actual *http.Request) (err error)

MatchHeader matches the header of a given request.

func MatchMethod

func MatchMethod(expected Expectation, actual *http.Request) (err error)

MatchMethod matches the method of a given request.

func MatchRequest

func MatchRequest(expected Expectation, actual *http.Request) error

MatchRequest checks whether a request is matched.

func MatchURI

func MatchURI(expected Expectation, actual *http.Request) (err error)

MatchURI matches the URI of a given request.

Types

type Error

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

Error represents an error that occurs while matching a request.

func NewError

func NewError(expected Expectation, request *http.Request, messageFormat string, messageArgs ...any) *Error

NewError creates a new Error.

func (Error) Error

func (e Error) Error() string

Error satisfies the error interface.

type Expectation added in v0.10.0

type Expectation interface {
	Method() string
	URIMatcher() matcher.Matcher
	HeaderMatcher() matcher.HeaderMatcher
	BodyMatcher() *matcher.BodyMatcher
	RemainTimes() uint
	Fulfilled()
	FulfilledTimes() uint
}

Expectation is an interface that represents an expectation.

type Planner

type Planner interface {
	// IsEmpty checks whether the planner has no expectation.
	IsEmpty() bool
	// Expect adds a new expectation.
	Expect(e Expectation)
	// Plan decides how a request matches an expectation.
	Plan(req *http.Request) (Expectation, error)
	// Remain returns remain expectations.
	Remain() []Expectation
	// Reset removes all the expectations.
	Reset()
}

Planner or Request Execution Planner is in charge of selecting the right expectation for a given request.

func Sequence

func Sequence() Planner

Sequence creates a new Planner that matches the request sequentially.

Jump to

Keyboard shortcuts

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