martiantest

package
v2.0.0-beta.2+incompat... Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2015 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package martiantest provides helper utilities for testing modifiers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Modifier

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

Modifier keeps track of the number of requests and responses it has modified and can be configured to return errors or run custom functions.

func NewModifier

func NewModifier() *Modifier

NewModifier returns a new test modifier.

func (*Modifier) ModifyRequest

func (m *Modifier) ModifyRequest(req *http.Request) error

ModifyRequest increases the count of requests seen and runs reqfunc if configured.

func (*Modifier) ModifyResponse

func (m *Modifier) ModifyResponse(res *http.Response) error

ModifyResponse increases the count of responses seen and runs resfunc if configured.

func (*Modifier) RequestCount

func (m *Modifier) RequestCount() int32

RequestCount returns the number of requests modified.

func (*Modifier) RequestError

func (m *Modifier) RequestError(err error)

RequestError overrides the error returned by ModifyRequest.

func (*Modifier) RequestFunc

func (m *Modifier) RequestFunc(reqfunc func(req *http.Request))

RequestFunc is a function to run during ModifyRequest.

func (*Modifier) RequestModified

func (m *Modifier) RequestModified() bool

RequestModified returns whether a request has been modified.

func (*Modifier) Reset

func (m *Modifier) Reset()

Reset resets the request and response counts, the custom functions, and the modifier errors.

func (*Modifier) ResponseCount

func (m *Modifier) ResponseCount() int32

ResponseCount returns the number of responses modified.

func (*Modifier) ResponseError

func (m *Modifier) ResponseError(err error)

ResponseError overrides the error returned by ModifyResponse.

func (*Modifier) ResponseFunc

func (m *Modifier) ResponseFunc(resfunc func(res *http.Response))

ResponseFunc is a function to run during ModifyResponse.

func (*Modifier) ResponseModified

func (m *Modifier) ResponseModified() bool

ResponseModified returns whether a response has been modified.

type Transport

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

Transport is an http.RoundTripper for testing.

func NewTransport

func NewTransport() *Transport

NewTransport builds a new transport that will respond with a 200 OK response.

func (*Transport) CopyHeaders

func (tr *Transport) CopyHeaders(names ...string)

CopyHeaders sets the transport to respond with a 200 OK response with headers copied from the request to the response verbatim.

func (*Transport) Func

func (tr *Transport) Func(rtfunc func(*http.Request) (*http.Response, error))

Func sets the transport to use the rtfunc.

func (*Transport) Respond

func (tr *Transport) Respond(statusCode int)

Respond sets the transport to respond with response with statusCode.

func (*Transport) RespondError

func (tr *Transport) RespondError(err error)

RespondError sets the transport to respond with an error on round trip.

func (*Transport) RoundTrip

func (tr *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip runs the stored round trip func and returns the response.

Jump to

Keyboard shortcuts

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