Documentation ¶
Overview ¶
Package transport provides http.RoundTrippers that may be useful to clients of Blazer.
Index ¶
- func WithFailures(rt http.RoundTripper, opts ...FailureOption) http.RoundTripper
- type FailureOption
- func AfterNBytes(n int, effect func()) FailureOption
- func Body(msg string) FailureOption
- func FailureRate(rate float64) FailureOption
- func MatchPathSubstring(s string) FailureOption
- func Response(status int) FailureOption
- func Stall(dur time.Duration) FailureOption
- func Trigger(ctx context.Context) FailureOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithFailures ¶
func WithFailures(rt http.RoundTripper, opts ...FailureOption) http.RoundTripper
WithFailures returns an http.RoundTripper that wraps an existing RoundTripper, causing failures according to the options given. If rt is nil, the http.DefaultTransport is wrapped.
Types ¶
type FailureOption ¶
type FailureOption func(*options)
A FailureOption specifies the kind of failure that the RoundTripper should display.
func AfterNBytes ¶
func AfterNBytes(n int, effect func()) FailureOption
AfterNBytes will call effect once (roughly) n bytes have gone over the wire. Both sent and received bytes are counted against the total. Only bytes in the body of an HTTP request are currently counted; this may change in the future. effect will only be called once, and it will block (allowing callers to simulate connection hangs).
func Body ¶
func Body(msg string) FailureOption
If a specific Response is requested, the body will have the given message set.
func FailureRate ¶
func FailureRate(rate float64) FailureOption
FailureRate causes the RoundTripper to fail a certain percentage of the time. rate should be a number between 0 and 1, where 0 will never fail and 1 will always fail. The default is never to fail.
func MatchPathSubstring ¶
func MatchPathSubstring(s string) FailureOption
MatchPathSubstring restricts the RoundTripper to URLs whose paths contain the given string. The default behavior is to match all paths.
func Response ¶
func Response(status int) FailureOption
Response simulates a given status code. The returned http.Response will have its Status, StatusCode, and Body (with any predefined message) set.
func Stall ¶
func Stall(dur time.Duration) FailureOption
Stall simulates a network connection failure by stalling for the given duration.
func Trigger ¶
func Trigger(ctx context.Context) FailureOption
Trigger will raise the RoundTripper's failure rate to 100% when the given context is closed.