Documentation ¶
Overview ¶
Package testutil contains helpers and utilities for writing unittests against the sansshell proxy.
Index ¶
- Constants
- func Exchange(t *testing.T, stream pb.Proxy_ProxyClient, req *pb.ProxyRequest) *pb.ProxyReply
- func MustStartStream(t *testing.T, stream pb.Proxy_ProxyClient, target, method string, ...) uint64
- func NewAllowAllRPCAuthorizer(ctx context.Context, t *testing.T) *rpcauth.Authorizer
- func NewRPCAuthorizer(ctx context.Context, t *testing.T, policy string) *rpcauth.Authorizer
- func PackStreamData(t *testing.T, req proto.Message, streamIds ...uint64) *pb.ProxyRequest
- func StartStream(t *testing.T, stream pb.Proxy_ProxyClient, target, method string, ...) *pb.StartStreamReply
- func StartTestDataServer(t *testing.T, serverName string) *bufconn.Listener
- func StartTestDataServers(t *testing.T, serverNames ...string) map[string]*bufconn.Listener
- func UnpackStreamData(t *testing.T, reply *pb.ProxyReply) ([]uint64, proto.Message)
- func WithBufDialer(m map[string]*bufconn.Listener) grpc.DialOption
- type EchoTestDataServer
- func (e *EchoTestDataServer) TestBidiStream(stream tdpb.TestService_TestBidiStreamServer) error
- func (e *EchoTestDataServer) TestClientStream(stream tdpb.TestService_TestClientStreamServer) error
- func (e *EchoTestDataServer) TestServerStream(req *tdpb.TestRequest, stream tdpb.TestService_TestServerStreamServer) error
- func (e *EchoTestDataServer) TestUnary(ctx context.Context, req *tdpb.TestRequest) (*tdpb.TestResponse, error)
Constants ¶
const BufSize = 1024 * 1024
BufSize is the buffer size used for a bufnet listener.
Variables ¶
This section is empty.
Functions ¶
func Exchange ¶
func Exchange(t *testing.T, stream pb.Proxy_ProxyClient, req *pb.ProxyRequest) *pb.ProxyReply
Exchange is a test helper for the common pattern of trading messages with a proxy server over an open stream. Errors encountered during send/receive will cause `t` to fail. `req` may be nil, in which case this only performs a Recv
func MustStartStream ¶
func MustStartStream(t *testing.T, stream pb.Proxy_ProxyClient, target, method string, dialTimeout ...time.Duration) uint64
MustStartStream invokes StartStream, but fails `t` if the response does not contain a valid stream id. Returns the created stream id.
func NewAllowAllRPCAuthorizer ¶
NewAllowAllRPCAuthorizer generates a new authorizer which allows all RPCs to pass through.
func NewRPCAuthorizer ¶
NewRPCAuthorizer generates a new authorizer with the given policy. Will handle errors for testing.
func PackStreamData ¶
PackStreamData creates a StreamData request for the supplied streamIds, with `req` as the payload. Any error in creation will fail `t`
func StartStream ¶
func StartStream(t *testing.T, stream pb.Proxy_ProxyClient, target, method string, dialTimeout ...time.Duration) *pb.StartStreamReply
StartStream establishes a new target stream through the proxy connection in `stream`. Will fail `t` on any errors communicating with the proxy, or if the returned response from the proxy is not a valid StartStreamReply.
func StartTestDataServer ¶
StartTestDataServer will start the given server running (as a separate Go routine) and return the Listener to connect to it over. The server will be automatically stopped when the enclosing test exits.
func StartTestDataServers ¶
StartTestDataServers will start N servers using StartTestDataServer returning a map of server -> Listener
func UnpackStreamData ¶
UnpackStreamData will unmarshal a StreamData entry into a slice of stream ids and the message associated with it.
func WithBufDialer ¶
func WithBufDialer(m map[string]*bufconn.Listener) grpc.DialOption
WithBufDialer returns a DialOption which will lookup a bufnet connection in the map passed to it. Allows arbitrary N backend servers to run simultaneously.
Types ¶
type EchoTestDataServer ¶
type EchoTestDataServer struct {
// contains filtered or unexported fields
}
EchoTestDataServer is a TestDataServiceServer for testing
func (*EchoTestDataServer) TestBidiStream ¶
func (e *EchoTestDataServer) TestBidiStream(stream tdpb.TestService_TestBidiStreamServer) error
TestBidiStream implements the service for EchoTestDataServer
func (*EchoTestDataServer) TestClientStream ¶
func (e *EchoTestDataServer) TestClientStream(stream tdpb.TestService_TestClientStreamServer) error
TestClientStream implements the service for EchoTestDataServer
func (*EchoTestDataServer) TestServerStream ¶
func (e *EchoTestDataServer) TestServerStream(req *tdpb.TestRequest, stream tdpb.TestService_TestServerStreamServer) error
TestServerStream implements the service for EchoTestDataServer
func (*EchoTestDataServer) TestUnary ¶
func (e *EchoTestDataServer) TestUnary(ctx context.Context, req *tdpb.TestRequest) (*tdpb.TestResponse, error)
TestUnary implements the service for EchoTestDataServer