package testutils
import "google.golang.org/grpc/internal/testutils"
Package testutils contains testing helpers.
Index ¶
- Constants
- func StatusErrEqual(err1, err2 error) bool
- type Channel
- func NewChannel() *Channel
- func NewChannelWithSize(bufSize int) *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.
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.
Functions ¶
func StatusErrEqual ¶
StatusErrEqual returns true iff both err1 and err2 wrap status.Status errors and their underlying status protos are equal.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel wraps a generic channel and provides a timed receive operation.
func NewChannel ¶
func NewChannel() *Channel
NewChannel returns a new Channel.
func NewChannelWithSize ¶
NewChannelWithSize returns a new Channel with a buffer of bufSize.
func (*Channel) Receive ¶
Receive returns the value received on the underlying channel, or the error returned by ctx if it is closed or cancelled.
func (*Channel) ReceiveOrFail ¶
ReceiveOrFail returns the value on the underlying channel and true, or nil and false if the channel was empty.
func (*Channel) Replace ¶
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 ¶
func (c *Channel) Send(value interface{})
Send sends value on the underlying channel.
func (*Channel) SendContext ¶
SendContext sends value on the underlying channel, or returns an error if the context expires.
func (*Channel) SendOrFail ¶
SendOrFail attempts to send value on the underlying channel. Returns true if successful or false if the channel was full.
type FakeHTTPClient ¶
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.
func (*FakeHTTPClient) Do ¶
Do pushes req on ReqChan and returns the response available on RespChan.
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.
func (*PipeListener) Accept ¶
func (p *PipeListener) Accept() (net.Conn, error)
Accept accepts a connection.
func (*PipeListener) Addr ¶
func (p *PipeListener) Addr() net.Addr
Addr returns a pipe addr.
func (*PipeListener) Close ¶
func (p *PipeListener) Close() error
Close closes the listener.
func (*PipeListener) Dialer ¶
Dialer dials a connection.
Source Files ¶
channel.go http_client.go pipe_listener.go status_equal.go
- Version
- v1.36.0-dev
- Published
- Jan 11, 2021
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 5 minutes ago –
Tools for package owners.