package cassette
import "github.com/dnaeon/go-vcr/cassette"
Index ¶
- Variables
- func DefaultMatcher(r *http.Request, i Request) bool
- type Cassette
- func Load(name string) (*Cassette, error)
- func New(name string) *Cassette
- func (c *Cassette) AddInteraction(i *Interaction)
- func (c *Cassette) GetInteraction(r *http.Request) (*Interaction, error)
- func (c *Cassette) Save() error
- type Filter
- type Interaction
- type Matcher
- type Request
- type Response
Variables ¶
var ( // ErrInteractionNotFound indicates that a requested // interaction was not found in the cassette file ErrInteractionNotFound = errors.New("Requested interaction not found") )
Functions ¶
func DefaultMatcher ¶
DefaultMatcher is used when a custom matcher is not defined and compares only the method and URL.
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"` // Mutex to lock accessing Interactions. omitempty is set // to prevent the mutex appearing in the recorded YAML. Mu sync.RWMutex `yaml:"mu,omitempty"` // Interactions between client and server Interactions []*Interaction `yaml:"interactions"` // ReplayableInteractions defines whether to allow interactions to be replayed or not ReplayableInteractions bool `yaml:"-"` // Matches actual request with interaction requests. Matcher Matcher `yaml:"-"` // Filters interactions before when they are captured. Filters []Filter `yaml:"-"` // SaveFilters are applied to interactions just before they are saved. SaveFilters []Filter `yaml:"-"` }
Cassette type
func Load ¶
Load reads a cassette file from disk
func New ¶
New creates a new empty cassette
func (*Cassette) AddInteraction ¶
func (c *Cassette) AddInteraction(i *Interaction)
AddInteraction appends a new interaction to the cassette
func (*Cassette) GetInteraction ¶
func (c *Cassette) GetInteraction(r *http.Request) (*Interaction, error)
GetInteraction retrieves a recorded request/response interaction
func (*Cassette) Save ¶
Save writes the cassette data on disk for future re-use
type Filter ¶
type Filter func(*Interaction) error
Filter function allows modification of an interaction before saving.
type Interaction ¶
Interaction type contains a pair of request/response for a single HTTP interaction between a client and a server
type Matcher ¶
Matcher function returns true when the actual request matches a single HTTP interaction's request according to the function's own criteria.
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"` }
Request represents a client request as recorded in the cassette file
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"` // Response duration (something like "100ms" or "10s") Duration string `yaml:"duration"` // contains filtered or unexported fields }
Response represents a server response as recorded in the cassette file
Source Files ¶
- Version
- v1.2.0 (latest)
- Published
- Jun 7, 2021
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 1 month ago –
Tools for package owners.