Documentation ¶
Overview ¶
Package testutils contains testing helpers.
Index ¶
Constants ¶
const DefaultChanBufferSize = 1
DefaultChanBufferSize is the default buffer size of the underlying channel.
const DefaultHTTPRequestTimeout = 1 * time.Second
DefaultHTTPRequestTimeout is the default timeout value for the amount of time this client waits for a response to be pushed on RespChan before it fails the Do() call.
Variables ¶
This section is empty.
Functions ¶
func StatusErrEqual ¶ added in v1.22.0
StatusErrEqual returns true iff both err1 and err2 wrap status.Status errors and their underlying status protos are equal.
Types ¶
type Channel ¶ added in v1.30.0
type Channel struct {
// contains filtered or unexported fields
}
Channel wraps a generic channel and provides a timed receive operation.
func NewChannelWithSize ¶ added in v1.30.0
NewChannelWithSize returns a new Channel with a buffer of bufSize.
func (*Channel) Receive ¶ added in v1.30.0
Receive returns the value received on the underlying channel, or the error returned by ctx if it is closed or cancelled.
func (*Channel) Replace ¶ added in v1.33.0
func (cwt *Channel) Replace(value interface{})
Replace clears the value on the underlying channel, and sends the new value.
It's expected to be used with a size-1 channel, to only keep the most up-to-date item. This method is inherently racy when invoked concurrently from multiple goroutines.
type FakeHTTPClient ¶ added in v1.33.0
type FakeHTTPClient struct { // ReqChan exposes the HTTP.Request made by the code under test. ReqChan *Channel // RespChan is a channel on which this fake client accepts responses to be // sent to the code under test. RespChan *Channel // Err, if set, is returned by Do(). Err error // RecvTimeout is the amount of the time this client waits for a response to // be pushed on RespChan before it fails the Do() call. If this field is // left unspecified, DefaultHTTPRequestTimeout is used. RecvTimeout time.Duration }
FakeHTTPClient helps mock out HTTP calls made by the code under test. It makes HTTP requests made by the code under test available through a channel, and makes it possible to inject various responses.
type PipeListener ¶
type PipeListener struct {
// contains filtered or unexported fields
}
PipeListener is a listener with an unbuffered pipe. Each write will complete only once the other side reads. It should only be created using NewPipeListener.
func NewPipeListener ¶
func NewPipeListener() *PipeListener
NewPipeListener creates a new pipe listener.