recorder

package
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2016 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package recorder allows to capture request/response pairs via a reverse proxy and generate tests for these pairs.

Index

Constants

View Source
const (
	RewriteNothing        uint32 = 0
	RewriteResponseHeader uint32 = 1 << (iota - 1)
	RewriteResponseBody
	RewriteRequestHeader
	RewriteRequestBody
)

Variables

View Source
var Events []Event

Events is the global list of recorded events.

Functions

func DumpEvents

func DumpEvents(events []Event, directory string, suitename string) error

DumpEvents writes events to directory, it extracts common request headers.

func ExtractCommonRequestHeaders

func ExtractCommonRequestHeaders(events []Event) http.Header

ExtractCommonRequestHeaders from events.

func ExtractCommonResponseHeaders

func ExtractCommonResponseHeaders(events []Event) http.Header

ExtractCommonResponseHeaders from events.

func StartReverseProxy

func StartReverseProxy(port string, remoteURL *url.URL, opts Options) error

StartReverseProxy listens on the local port and forwards request to remote while capturing the request/response pairs selected by opts.

Types

type Event

type Event struct {
	Request      *http.Request              // The request.
	Response     *httptest.ResponseRecorder // The recorded response.
	RequestBody  string                     // The captured body.
	ResponseBody string
	Timestamp    time.Time // Timestamp when caputred.
	Name         string    // Used during dumping.
}

Event is a request/response pair.

type Options

type Options struct {
	// Disarm is the time span after a captured request/response pair
	// in which the capturing is disarmed.
	Disarm time.Duration

	// IgnoredContentType allows to skip capturing a request whose
	// Content-Type header matches.
	IgnoredContentType *regexp.Regexp

	// IgnoredPath allows to skip capturing events based on the
	// requested path,
	IgnoredPath *regexp.Regexp

	// Rewrite determines what is rewritten.
	Rewrite Rewriter
}

Options determining which and how events should be captured.

type Rewriter

type Rewriter struct {
	// contains filtered or unexported fields
}

Rewriter from remote to local host

func NewRewriter

func NewRewriter(local, remote string, what uint32) Rewriter

func (Rewriter) Request

func (r Rewriter) Request(header http.Header, body []byte) (http.Header, []byte)

func (Rewriter) Response

func (r Rewriter) Response(header http.Header, body []byte) (http.Header, []byte)

type Suite

type Suite struct {
	Name        string
	Description string `json:",omitempty"`
	Tests       []string
	Variables   map[string]string
}

Suite is a reduced version of ht.Suite suitable to serialization to JSON5.

type Test

type Test struct {
	Name        string
	Description string   `json:",omitempty"`
	BasedOn     []string `json:",omitempty"`
	Request     ht.Request
	Checks      ht.CheckList `json:",omitempty"`
}

Test is a reduced version of ht.Test suitable for serialization to JSON5.

Jump to

Keyboard shortcuts

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