Documentation ¶
Overview ¶
Package mocks provides mocks and helpers used in testing.
Index ¶
- Constants
- func NewRequest() *http.Request
- func NewRequestForURL(u string) *http.Request
- func NewRequestWithCloseBody() *http.Request
- func NewRequestWithCloseBodyContent(c string) *http.Request
- func NewRequestWithContent(c string) *http.Request
- func NewRequestWithParams(method, u string, body io.Reader) *http.Request
- func NewResponse() *http.Response
- func NewResponseWithBodyAndStatus(body *Body, c int, s string) *http.Response
- func NewResponseWithContent(c string) *http.Response
- func NewResponseWithStatus(s string, c int) *http.Response
- func SetAcceptedHeaders(resp *http.Response)
- func SetLocationHeader(resp *http.Response, location string)
- func SetResponseHeader(resp *http.Response, h string, v string)
- func SetResponseHeaderValues(resp *http.Response, h string, values []string)
- func SetRetryHeader(resp *http.Response, delay time.Duration)
- type Body
- type Sender
- func (c *Sender) AppendAndRepeatError(err error, repeat int)
- func (c *Sender) AppendAndRepeatResponse(resp *http.Response, repeat int)
- func (c *Sender) AppendAndRepeatResponseWithDelay(resp *http.Response, delay time.Duration, repeat int)
- func (c *Sender) AppendError(err error)
- func (c *Sender) AppendResponse(resp *http.Response)
- func (c *Sender) AppendResponseWithDelay(resp *http.Response, delay time.Duration)
- func (c *Sender) Attempts() int
- func (c *Sender) Do(r *http.Request) (resp *http.Response, err error)
- func (c *Sender) NumResponses() int
- func (c *Sender) SetAndRepeatError(err error, repeat int)
- func (c *Sender) SetEmitErrorAfter(ea int)
- func (c *Sender) SetError(err error)
- type T
Constants ¶
const ( // TestAuthorizationHeader is a faux HTTP Authorization header value TestAuthorizationHeader = "BEARER SECRETTOKEN" // TestBadURL is a malformed URL TestBadURL = " " // TestDelay is the Retry-After delay used in tests. TestDelay = 0 * time.Second // TestHeader is the header used in tests. TestHeader = "x-test-header" // TestURL is the URL used in tests. TestURL = "https://microsoft.com/a/b/c/" // TestAzureAsyncURL is a URL used in Azure asynchronous tests TestAzureAsyncURL = "https://microsoft.com/a/b/c/async" // TestLocationURL is a URL used in Azure asynchronous tests TestLocationURL = "https://microsoft.com/a/b/c/location" )
Variables ¶
This section is empty.
Functions ¶
func NewRequestForURL ¶
NewRequestForURL instantiates a new request using the passed URL.
func NewRequestWithCloseBody ¶
NewRequestWithCloseBody instantiates a new request.
func NewRequestWithCloseBodyContent ¶
NewRequestWithCloseBodyContent instantiates a new request using the passed string for the body content.
func NewRequestWithContent ¶
NewRequestWithContent instantiates a new request using the passed string for the body content.
func NewRequestWithParams ¶
NewRequestWithParams instantiates a new request using the provided parameters.
func NewResponseWithBodyAndStatus ¶
NewResponseWithBodyAndStatus instantiates a new response using the specified mock body, status and status code
func NewResponseWithContent ¶
NewResponseWithContent instantiates a new response with the passed string as the body content.
func NewResponseWithStatus ¶
NewResponseWithStatus instantiates a new response using the passed string and integer as the status and status code.
func SetAcceptedHeaders ¶
SetAcceptedHeaders adds the headers usually associated with a 202 Accepted response.
func SetLocationHeader ¶
SetLocationHeader adds the Location header.
func SetResponseHeader ¶
SetResponseHeader adds a header to the passed response.
func SetResponseHeaderValues ¶
SetResponseHeaderValues adds a header containing all the passed string values.
Types ¶
type Body ¶
type Body struct {
// contains filtered or unexported fields
}
Body implements acceptable body over a string.
func (*Body) CloseAttempts ¶
CloseAttempts returns the number of times Close was called.
type Sender ¶
type Sender struct {
// contains filtered or unexported fields
}
Sender implements a simple null sender.
func (*Sender) AppendAndRepeatError ¶
AppendAndRepeatError adds the passed error to the response stack along with a repeat count. A negative repeat count will return the response for all remaining calls to Do.
func (*Sender) AppendAndRepeatResponse ¶
AppendAndRepeatResponse adds the passed http.Response to the response stack along with a repeat count. A negative repeat count will return the response for all remaining calls to Do.
func (*Sender) AppendAndRepeatResponseWithDelay ¶
func (c *Sender) AppendAndRepeatResponseWithDelay(resp *http.Response, delay time.Duration, repeat int)
AppendAndRepeatResponseWithDelay adds the passed http.Response to the response stack with the specified delay along with a repeat count. A negative repeat count will return the response for all remaining calls to Do.
func (*Sender) AppendError ¶
AppendError adds the passed error to the response stack.
func (*Sender) AppendResponse ¶
AppendResponse adds the passed http.Response to the response stack.
func (*Sender) AppendResponseWithDelay ¶
AppendResponseWithDelay adds the passed http.Response to the response stack with the specified delay.
func (*Sender) Do ¶
Do accepts the passed request and, based on settings, emits a response and possible error.
func (*Sender) NumResponses ¶
NumResponses returns the number of responses that have been added to the sender.
func (*Sender) SetAndRepeatError ¶
SetAndRepeatError sets the error Do should return and how many calls to Do will return the error. A negative repeat value will return the error for all remaining calls to Do.
func (*Sender) SetEmitErrorAfter ¶
SetEmitErrorAfter sets the number of attempts to be made before errors are emitted.