package martiantest
import "github.com/google/martian/martiantest"
Package martiantest provides helper utilities for testing modifiers.
Index ¶
- type Modifier
- func NewModifier() *Modifier
- func (m *Modifier) ModifyRequest(req *http.Request) error
- func (m *Modifier) ModifyResponse(res *http.Response) error
- func (m *Modifier) RequestCount() int32
- func (m *Modifier) RequestError(err error)
- func (m *Modifier) RequestFunc(reqfunc func(req *http.Request))
- func (m *Modifier) RequestModified() bool
- func (m *Modifier) Reset()
- func (m *Modifier) ResponseCount() int32
- func (m *Modifier) ResponseError(err error)
- func (m *Modifier) ResponseFunc(resfunc func(res *http.Response))
- func (m *Modifier) ResponseModified() bool
- type Transport
- func NewTransport() *Transport
- func (tr *Transport) CopyHeaders(names ...string)
- func (tr *Transport) Func(rtfunc func(*http.Request) (*http.Response, error))
- func (tr *Transport) Respond(statusCode int)
- func (tr *Transport) RespondError(err error)
- func (tr *Transport) RoundTrip(req *http.Request) (*http.Response, error)
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 ¶
ModifyRequest increases the count of requests seen and runs reqfunc if configured.
func (*Modifier) ModifyResponse ¶
ModifyResponse increases the count of responses seen and runs resfunc if configured.
func (*Modifier) RequestCount ¶
RequestCount returns the number of requests modified.
func (*Modifier) RequestError ¶
RequestError overrides the error returned by ModifyRequest.
func (*Modifier) RequestFunc ¶
RequestFunc is a function to run during ModifyRequest.
func (*Modifier) RequestModified ¶
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 ¶
ResponseCount returns the number of responses modified.
func (*Modifier) ResponseError ¶
ResponseError overrides the error returned by ModifyResponse.
func (*Modifier) ResponseFunc ¶
ResponseFunc is a function to run during ModifyResponse.
func (*Modifier) ResponseModified ¶
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 ¶
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 sets the transport to use the rtfunc.
func (*Transport) Respond ¶
Respond sets the transport to respond with response with statusCode.
func (*Transport) RespondError ¶
RespondError sets the transport to respond with an error on round trip.
func (*Transport) RoundTrip ¶
RoundTrip runs the stored round trip func and returns the response.
Source Files ¶
- Version
- v2.0.0-beta.2+incompatible
- Published
- Aug 24, 2015
- Platform
- js/wasm
- Imports
- 3 packages
- Last checked
- 24 minutes ago –
Tools for package owners.