Documentation ¶
Overview ¶
Package testutils contains testing helpers.
Index ¶
- Constants
- func MarshalAny(m proto.Message) *anypb.Any
- func StatusErrEqual(err1, err2 error) bool
- type Channel
- func (c *Channel) Receive(ctx context.Context) (interface{}, error)
- func (c *Channel) ReceiveOrFail() (interface{}, bool)
- func (c *Channel) Replace(value interface{})
- func (c *Channel) Send(value interface{})
- func (c *Channel) SendContext(ctx context.Context, value interface{}) error
- func (c *Channel) SendOrFail(value interface{}) bool
- type FakeHTTPClient
- type PipeListener
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 MarshalAny ¶ added in v1.38.0
MarshalAny is a convenience function to marshal protobuf messages into any protos. It will panic if the marshaling fails.
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) ReceiveOrFail ¶ added in v1.34.0
ReceiveOrFail returns the value on the underlying channel and true, or nil and false if the channel was empty.
func (*Channel) Replace ¶ added in v1.33.0
func (c *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.
func (*Channel) Send ¶ added in v1.30.0
func (c *Channel) Send(value interface{})
Send sends value on the underlying channel.
func (*Channel) SendContext ¶ added in v1.34.0
SendContext sends value on the underlying channel, or returns an error if the context expires.
func (*Channel) SendOrFail ¶ added in v1.34.0
SendOrFail attempts to send value on the underlying channel. Returns true if successful or false if the channel was full.
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.