package martiantest
import "github.com/google/martian/v3/martiantest"
Package martiantest provides helper utilities for testing modifiers.
Index ¶
- type Matcher
- func NewMatcher() *Matcher
- func (tm *Matcher) MatchRequest(*http.Request) bool
- func (tm *Matcher) MatchResponse(*http.Response) bool
- func (tm *Matcher) RequestEvaluatesTo(value bool)
- func (tm *Matcher) ResponseEvaluatesTo(value bool)
- 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 Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher is a stubbed matcher used in tests.
func NewMatcher ¶
func NewMatcher() *Matcher
NewMatcher returns a pointer to martiantest.Matcher with the return values for MatchRequest and MatchResponse intiailized to true.
func (*Matcher) MatchRequest ¶
MatchRequest returns the stubbed value in tm.reqval.
func (*Matcher) MatchResponse ¶
MatchResponse returns the stubbed value in tm.resval.
func (*Matcher) RequestEvaluatesTo ¶
RequestEvaluatesTo sets the value returned by MatchRequest.
func (*Matcher) ResponseEvaluatesTo ¶
ResponseEvaluatesTo sets the value returned by MatchResponse.
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
- v3.3.3 (latest)
- Published
- Aug 16, 2022
- Platform
- darwin/amd64
- Imports
- 3 packages
- Last checked
- 2 hours ago –
Tools for package owners.