httpvcr

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2020 License: MIT Imports: 10 Imported by: 0

README

HTTP VCR

For writing deterministic tests from external sources.

Features

  • Easy to use
  • No flags (records when no cassete file is present, otherwise replays)
  • Filter sensitive data (such as API keys)
  • Modify requests before they are sent (e.g. to add row limits)
  • Ignores request headers (so a timestamp or crypto signature does not break your cassette files)
  • No dependencies

Examples

...

License

MIT, see LICENSE

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	HTTPDefaultOverride: true,
}

Functions

func ModifyHTTPRequestBody

func ModifyHTTPRequestBody(request *http.Request, modifyFunc ModifyStringFunc)

ModifyHTTPRequestBody changes the body of an HTTP request using a callback function

Types

type Mode

type Mode uint32
const (
	ModeStopped Mode = iota
	ModeRecord
	ModeReplay
)

type ModifyStringFunc

type ModifyStringFunc func(input string) string

ModifyStringFunc is a function that modifies a given string and returns it

type Options

type Options struct {
	HTTPDefaultOverride bool
}

type VCR

type VCR struct {
	Cassette      *cassette
	FilterMap     map[string]string
	BeforeRequest func(Mode, *http.Request)
	URLRewriter   func(string) string
	// contains filtered or unexported fields
}

func New

func New(cassetteName string, opts ...Options) *VCR

func (*VCR) Done

func (v *VCR) Done() <-chan struct{}

func (*VCR) FilterResponseBody

func (v *VCR) FilterResponseBody(original string, replacement string)

FilterData allows replacement of sensitive data with a dummy-string

func (*VCR) Mode

func (v *VCR) Mode() Mode

func (*VCR) RoundTrip

func (v *VCR) RoundTrip(request *http.Request) (*http.Response, error)

func (*VCR) Start

func (v *VCR) Start(ctx context.Context)

Start starts a VCR session with the given cassette name. Records episodes if the cassette file does not exists. Otherwise plays back recorded episodes.

func (*VCR) Stop

func (v *VCR) Stop()

Stop stops the VCR session and writes the cassette file (when recording)

Jump to

Keyboard shortcuts

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