testutil

package
v1.18.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package testutil contains helpers and utilities for writing unittests against the sansshell proxy.

Index

Constants

View Source
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

func NewAllowAllRPCAuthorizer(ctx context.Context, t *testing.T) *rpcauth.Authorizer

NewAllowAllRPCAuthorizer generates a new authorizer which allows all RPCs to pass through.

func NewRPCAuthorizer

func NewRPCAuthorizer(ctx context.Context, t *testing.T, policy string) *rpcauth.Authorizer

NewRPCAuthorizer generates a new authorizer with the given policy. Will handle errors for testing.

func PackStreamData

func PackStreamData(t *testing.T, req proto.Message, streamIds ...uint64) *pb.ProxyRequest

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

func StartTestDataServer(t *testing.T, serverName string) *bufconn.Listener

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

func StartTestDataServers(t *testing.T, serverNames ...string) map[string]*bufconn.Listener

StartTestDataServers will start N servers using StartTestDataServer returning a map of server -> Listener

func UnpackStreamData

func UnpackStreamData(t *testing.T, reply *pb.ProxyReply) ([]uint64, proto.Message)

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

TestBidiStream implements the service for EchoTestDataServer

func (*EchoTestDataServer) TestClientStream

TestClientStream implements the service for EchoTestDataServer

func (*EchoTestDataServer) TestServerStream

TestServerStream implements the service for EchoTestDataServer

func (*EchoTestDataServer) TestUnary

TestUnary implements the service for EchoTestDataServer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL