mock

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	GetRPC      = "trtl.v1.Trtl/Get"
	PutRPC      = "trtl.v1.Trtl/Put"
	DeleteRPC   = "trtl.v1.Trtl/Delete"
	IterRPC     = "trtl.v1.Trtl/Iter"
	BatchRPC    = "trtl.v1.Trtl/Batch"
	CursorRPC   = "trtl.v1.Trtl/Cursor"
	SyncRPC     = "trtl.v1.Trtl/Sync"
	StatusRPC   = "trtl.v1.Trtl/Status"
	GetPeersRPC = "trtl.peers.v1.PeerManagement/GetPeers"
	AddPeersRPC = "trtl.peers.v1.PeerManagement/AddPeers"
	RmPeersRPC  = "trtl.peers.v1.PeerManagement/RmPeers"
	GossipRPC   = "honu.replica.v1.Replication/Gossip"
)

Variables

This section is empty.

Functions

func Config

func Config() config.Config

Config returns a configuration that ensures the server will operate in a fully mocked way with all testing parameters set correctly. The config is returned directly for required modifications, such as pointing the database path to a fixtures path.

Types

type RemoteTrtl

type RemoteTrtl struct {
	pb.UnimplementedTrtlServer
	peers.UnimplementedPeerManagementServer
	replica.UnimplementedReplicationServer

	Calls      map[string]int
	OnGet      func(context.Context, *pb.GetRequest) (*pb.GetReply, error)
	OnPut      func(context.Context, *pb.PutRequest) (*pb.PutReply, error)
	OnDelete   func(context.Context, *pb.DeleteRequest) (*pb.DeleteReply, error)
	OnIter     func(context.Context, *pb.IterRequest) (*pb.IterReply, error)
	OnBatch    func(pb.Trtl_BatchServer) error
	OnCursor   func(*pb.CursorRequest, pb.Trtl_CursorServer) error
	OnSync     func(pb.Trtl_SyncServer) error
	OnStatus   func(context.Context, *pb.HealthCheck) (*pb.ServerStatus, error)
	OnGetPeers func(context.Context, *peers.PeersFilter) (*peers.PeersList, error)
	OnAddPeers func(context.Context, *peers.Peer) (*peers.PeersStatus, error)
	OnRmPeers  func(context.Context, *peers.Peer) (*peers.PeersStatus, error)
	OnGossip   func(replica.Replication_GossipServer) error
	// contains filtered or unexported fields
}

RemoteTrtl implements a mock gRPC server for testing client connections to other trtl peers. 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.GRPCListener, opts ...grpc.ServerOption) *RemoteTrtl

New creates a new mock RemoteTrtl. If bufnet is nil, one is created for the user. The gRPC server defaults to insecure which can be overridden by passing in ServerOptions with configured TLS.

func (*RemoteTrtl) AddPeers

func (s *RemoteTrtl) AddPeers(ctx context.Context, in *peers.Peer) (*peers.PeersStatus, error)

func (*RemoteTrtl) Batch

func (s *RemoteTrtl) Batch(stream pb.Trtl_BatchServer) error

func (*RemoteTrtl) Channel

func (s *RemoteTrtl) Channel() *bufconn.GRPCListener

func (*RemoteTrtl) CloseClient

func (s *RemoteTrtl) CloseClient()

func (*RemoteTrtl) Cursor

func (s *RemoteTrtl) Cursor(in *pb.CursorRequest, stream pb.Trtl_CursorServer) error

func (*RemoteTrtl) DBClient

func (s *RemoteTrtl) DBClient(opts ...grpc.DialOption) (_ pb.TrtlClient, err error)

func (*RemoteTrtl) Delete

func (s *RemoteTrtl) Delete(ctx context.Context, in *pb.DeleteRequest) (*pb.DeleteReply, error)

func (*RemoteTrtl) Get

func (s *RemoteTrtl) Get(ctx context.Context, in *pb.GetRequest) (*pb.GetReply, error)

func (*RemoteTrtl) GetPeers

func (s *RemoteTrtl) GetPeers(ctx context.Context, in *peers.PeersFilter) (*peers.PeersList, error)

func (*RemoteTrtl) Gossip

func (*RemoteTrtl) Iter

func (s *RemoteTrtl) Iter(ctx context.Context, in *pb.IterRequest) (*pb.IterReply, error)

func (*RemoteTrtl) PeersClient

func (s *RemoteTrtl) PeersClient(opts ...grpc.DialOption) (_ peers.PeerManagementClient, err error)

func (*RemoteTrtl) Put

func (s *RemoteTrtl) Put(ctx context.Context, in *pb.PutRequest) (*pb.PutReply, error)

func (*RemoteTrtl) ReplicaClient

func (s *RemoteTrtl) ReplicaClient(opts ...grpc.DialOption) (_ replica.ReplicationClient, err error)

func (*RemoteTrtl) Reset

func (s *RemoteTrtl) Reset()

func (*RemoteTrtl) RmPeers

func (s *RemoteTrtl) RmPeers(ctx context.Context, in *peers.Peer) (*peers.PeersStatus, error)

func (*RemoteTrtl) Shutdown

func (s *RemoteTrtl) Shutdown()

func (*RemoteTrtl) Status

func (s *RemoteTrtl) Status(ctx context.Context, in *pb.HealthCheck) (*pb.ServerStatus, error)

func (*RemoteTrtl) Sync

func (s *RemoteTrtl) Sync(stream pb.Trtl_SyncServer) error

func (*RemoteTrtl) UseError

func (s *RemoteTrtl) 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 (*RemoteTrtl) UseFixture

func (s *RemoteTrtl) 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