cassette

package
v0.0.0-...-dce903a Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2016 License: BSD-2-Clause Imports: 9 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InteractionNotFound = errors.New("Requested interaction not found")
)

Functions

This section is empty.

Types

type Cassette

type Cassette struct {
	// Name of the cassette
	Name string `yaml:"-"`

	// File name of the cassette as written on disk
	File string `yaml:"-"`

	// Cassette format version
	Version int `yaml:"version"`

	// Interactions between client and server
	Interactions []*Interaction `yaml:"interactions"`

	// Interactions mutex
	InteractionsMu sync.Mutex `yaml:"-"`

	// Unfinished requests mutex
	UnfinishedRequests sync.RWMutex `yaml:"-"`

	// Closed by client or hanging requests
	UnclosedRequests map[string]interface{} `yaml:"unclosed_requests"`
}

Cassette type

func Load

func Load(name string) (*Cassette, error)

Loads a cassette file from disk

func New

func New(name string) *Cassette

Creates a new empty cassette

func (*Cassette) AddInteraction

func (c *Cassette) AddInteraction(i *Interaction)

Adds a new interaction to the cassette

func (*Cassette) GetInteraction

func (c *Cassette) GetInteraction(r *http.Request) (*Interaction, error)

Gets a recorded interaction

func (*Cassette) HasRequest

func (c *Cassette) HasRequest(url string) bool

func (*Cassette) RequestFinished

func (c *Cassette) RequestFinished(url string)

func (*Cassette) RequestStated

func (c *Cassette) RequestStated(url string)

func (*Cassette) Requests

func (c *Cassette) Requests() []string

func (*Cassette) Save

func (c *Cassette) Save() error

Saves the cassette on disk for future re-use

func (*Cassette) SetMatcher

func (c *Cassette) SetMatcher(m Matcher)

Custom matcher setter

type DefaultMatcher

type DefaultMatcher struct {
	Matcher
}

func (*DefaultMatcher) Match

func (m *DefaultMatcher) Match(interactions []*Interaction, r *http.Request) (
	*Interaction, error)

type Interaction

type Interaction struct {
	Request  `yaml:"request"`
	Response `yaml:"response"`
}

Interaction type contains a pair of request/response for a single HTTP interaction between a client and a server

type Matcher

type Matcher interface {
	Match(interactions []*Interaction, r *http.Request) (*Interaction, error)
	MatchUrlStrings(expected, actual string) bool
}

type Request

type Request struct {
	// Body of request
	Body string `yaml:"body"`

	// Form values
	Form url.Values `yaml:"form"`

	// Request headers
	Headers http.Header `yaml:"headers"`

	// Request URL
	URL string `yaml:"url"`

	// Request method
	Method string `yaml:"method"`
}

Client request type

type Response

type Response struct {
	// Body of response
	Body string `yaml:"body"`

	// Response headers
	Headers http.Header `yaml:"headers"`

	// Response status message
	Status string `yaml:"status"`

	// Response status code
	Code int `yaml:"code"`
}

Server response type

Jump to

Keyboard shortcuts

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