mock

package
v0.99999.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LookupRPC = "trisa.gds.api.v1beta1.TRISADirectory/Lookup"
	SearchRPC = "trisa.gds.api.v1beta1.TRISADirectory/Search"
	StatusRPC = "trisa.gds.api.v1beta1.TRISADirectory/Status"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GDS

type GDS struct {
	sync.Mutex
	gds.UnimplementedTRISADirectoryServer

	Calls    map[string]int
	OnLookup func(context.Context, *gds.LookupRequest) (*gds.LookupReply, error)
	OnSearch func(context.Context, *gds.SearchRequest) (*gds.SearchReply, error)
	OnStatus func(context.Context, *gds.HealthCheck) (*gds.ServiceState, error)
	// contains filtered or unexported fields
}

GDS implements a mock gRPC server for testing TRISA Global Directory Service client connections. The desired response of the directory service 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 PRC was called.

func New

func New(bufnet *bufconn.Listener) *GDS

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

func (*GDS) Channel

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

func (*GDS) IncrementCalls

func (s *GDS) IncrementCalls(rpc string)

func (*GDS) Lookup

func (s *GDS) Lookup(ctx context.Context, in *gds.LookupRequest) (*gds.LookupReply, error)

func (*GDS) Reset

func (s *GDS) Reset()

func (*GDS) Search

func (s *GDS) Search(ctx context.Context, in *gds.SearchRequest) (*gds.SearchReply, error)

func (*GDS) Shutdown

func (s *GDS) Shutdown()

func (*GDS) Status

func (s *GDS) Status(ctx context.Context, in *gds.HealthCheck) (*gds.ServiceState, error)

func (*GDS) UseError

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

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