watney

package module
v0.0.0-...-24bd73b Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2016 License: MIT Imports: 11 Imported by: 0

README

Watney Build Status codecov

A port of the Ruby vcr library to Go, backed by github.com/google/martian/har

Run tests that depend on the network, reliably, without ever touching the network itself.

Consider this package WIP - Pull Requests / Issues are greatly appreciated while the exact API is worked out :)

Usage

watney provides a http.RoundTripper that is automatically configured to use fixtures unless -watney is set in the test flag.

First record fixtures using go test -watney -v ./..., then replay them by omitting -watney in your future test runs.

To record a single test, use go test -watney -v -run CaseName and a new .har will be written.

Bonus! You can inspect any .har individually, with any number of tools, such as HAR Viewer, or Har Viewer

func TestGoogle(t *testing.T) {
	// you can use your own transport here, it is fully preserved during
	// recording
	tr := watney.Configure(http.DefaultTransport, t)

	c := &http.Client{
		Transport: tr,
	}

	// writes to a file like watney_test.go.har
	defer watney.Save(c)

	resp, err := c.Get("https://www.google.com")
	if err != nil {
		t.Fatal(err)
	}

	// test some things about resp

	defer resp.Body.Close()
}

LICENSE

Originally derived from a helper I found in github.com/cardigann/cardigann, which is MIT licensed. The same license applies here

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(tr http.RoundTripper, t TestingT) http.RoundTripper

Configure reconfigures a given http.Client to use a fixture provided transport

func Save

func Save(c *http.Client)

Save writes the interactions to a file, if `-watney` is set for the test run

Types

type TestingT

type TestingT interface {
	Fatal(args ...interface{})
}

Jump to

Keyboard shortcuts

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