vcr

package module
v0.0.0-...-11ee999 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

VCR

Go Report GolangCI Travis codecov License Maintenance GoDoc

Save your API requests for testing in fixtures.

Features

  • Easy to use
  • Works with net/http - fasthttp support upcoming

Example

Simple:

package examples

import (
  "github.com/apibillme/vcr"
  "net/http"
  "testing"
)

func TestSomeFeature(t *testing.T) {
  // This will automatically create a cassette file at ./fixtures/vcr/my_feature.json
  vcr.Start("my_feature", nil)
  defer vcr.Stop()

  resp, _ := http.Get("http://google.com/")
  if resp.StatusCode != 200 {
    t.Fatalf("Status code is not 200!")
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterData

func FilterData(original string, replacement string)

FilterData allows replacement of sensitive data with a dummy-string

func ModifyHTTPRequestBody

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

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

func Start

func Start(cassetteName string, modFunc RequestModifierFunc)

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 Stop

func Stop()

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

Types

type ModifyStringFunc

type ModifyStringFunc func(input string) string

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

type RequestModifierFunc

type RequestModifierFunc func(request *http.Request)

RequestModifierFunc is a function that can be used to manipulate HTTP requests before they are sent to the server. Useful for adding row-limits in integration tests.

Jump to

Keyboard shortcuts

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