mock

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TransferRPC       = "trisa.api.v1beta1.TRISANetwork/Transfer"
	TransferStreamRPC = "trisa.api.v1beta1.TRISANetwork/TransferStream"
	KeyExchangeRPC    = "trisa.api.v1beta1.TRISANetwork/KeyExchange"
	ConfirmAddressRPC = "trisa.api.v1beta1.TRISANetwork/ConfirmAddress"
	StatusRPC         = "trisa.api.v1beta1.TRISAHealth/Status"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type RemotePeer

type RemotePeer struct {
	api.UnimplementedTRISAHealthServer
	api.UnimplementedTRISANetworkServer

	Calls            map[string]int
	OnTransfer       func(context.Context, *api.SecureEnvelope) (*api.SecureEnvelope, error)
	OnTransferStream func(api.TRISANetwork_TransferStreamServer) error
	OnKeyExchange    func(context.Context, *api.SigningKey) (*api.SigningKey, error)
	OnConfirmAddress func(context.Context, *api.Address) (*api.AddressConfirmation, error)
	OnStatus         func(context.Context, *api.HealthCheck) (*api.ServiceState, error)
	// contains filtered or unexported fields
}

RemotePeer implements a mock gRPC server for testing Peer client connections. The desired response of the remote peer can be set by external callers using the OnRPC functions or the WithFixture or WithError functions. The Calls map can be used to count the number of times the remote peer RPC was called.

func New

func New(bufnet *bufconn.Listener) *RemotePeer

New creates a new mock RemotePeer. If bufnet is nil, one is created for the user.

func NewAuth

func NewAuth(bufnet *bufconn.Listener, conf config.TRISAConfig) (remote *RemotePeer, err error)

NewAuth creates a new mock RemotePeer that enforces mTLS credentials over bufconn.

func (*RemotePeer) Channel

func (s *RemotePeer) Channel() *bufconn.Listener

func (*RemotePeer) ConfirmAddress

func (s *RemotePeer) ConfirmAddress(ctx context.Context, in *api.Address) (*api.AddressConfirmation, error)

func (*RemotePeer) KeyExchange

func (s *RemotePeer) KeyExchange(ctx context.Context, in *api.SigningKey) (*api.SigningKey, error)

func (*RemotePeer) Reset

func (s *RemotePeer) Reset()

func (*RemotePeer) Shutdown

func (s *RemotePeer) Shutdown()

func (*RemotePeer) Status

func (s *RemotePeer) Status(ctx context.Context, in *api.HealthCheck) (*api.ServiceState, error)

func (*RemotePeer) Transfer

func (s *RemotePeer) Transfer(ctx context.Context, in *api.SecureEnvelope) (*api.SecureEnvelope, error)

func (*RemotePeer) TransferStream

func (s *RemotePeer) TransferStream(stream api.TRISANetwork_TransferStreamServer) error

func (*RemotePeer) UseError

func (s *RemotePeer) UseError(rpc string, code codes.Code, msg string) error

UseError allows you to specify a gRPC status error to return from the specified RPC.

func (*RemotePeer) UseFixture

func (s *RemotePeer) UseFixture(rpc, path string) (err error)

UseFixture loadsa a JSON fixture from disk (usually in a testdata folder) to use as the protocol buffer response to the specified RPC, simplifying handler mocking.

Jump to

Keyboard shortcuts

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