mock

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RegisterRPC      = "Register"
	LookupRPC        = "Lookup"
	SearchRPC        = "Search"
	VerificationRPC  = "Verification"
	VerifyContactRPC = "VerifyContact"
	StatusRPC        = "Status"
)
View Source
const (
	ListRPC    = "List"
	SummaryRPC = "Summary"
	DetailsRPC = "Details"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GDS

type GDS struct {
	gds.UnimplementedTRISADirectoryServer

	Calls           map[string]int
	OnRegister      func(context.Context, *gds.RegisterRequest) (*gds.RegisterReply, error)
	OnLookup        func(context.Context, *gds.LookupRequest) (*gds.LookupReply, error)
	OnSearch        func(context.Context, *gds.SearchRequest) (*gds.SearchReply, error)
	OnVerification  func(context.Context, *gds.VerificationRequest) (*gds.VerificationReply, error)
	OnVerifyContact func(context.Context, *gds.VerifyContactRequest) (*gds.VerifyContactReply, error)
	OnStatus        func(context.Context, *gds.HealthCheck) (*gds.ServiceState, error)
	// contains filtered or unexported fields
}

GDS implements a mock gRPC server that listens on a buffconc and registers the TRISA directory service. The RPC methods are able to be set from individual tests so that the user can specify the return of the RPC in order to test specific functionality. The mock allows us to test dual GDS (TestNet and MainNet) handling from the BFF without having to set up a whole microservices architecture with data storage and managing fixtures.

To set the response of the mock for a particular test, update the GDS OnRPC method. e.g. to mock the Register RPC, set the OnRegister method. The number of calls to the RPC will be recorded to verifiy that the service is being called correctly. Use the Reset method to remove all RPC handlers and set calls back to 0.

NOTE: this mock is not safe for concurrent use. NOTE: if the OnRPC function is not set, the test will panic

func NewGDS

func NewGDS(conf config.DirectoryConfig) (g *GDS, err error)

func (*GDS) Client

func (g *GDS) Client() (client gds.TRISADirectoryClient, err error)

func (*GDS) DialOpts added in v1.5.0

func (g *GDS) DialOpts() (opts []grpc.DialOption)

func (*GDS) Lookup

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

func (*GDS) Register

func (g *GDS) Register(ctx context.Context, in *gds.RegisterRequest) (*gds.RegisterReply, error)

func (*GDS) Reset

func (g *GDS) Reset()

func (*GDS) Search

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

func (*GDS) Shutdown

func (g *GDS) Shutdown()

func (*GDS) Status

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

func (*GDS) UseError

func (g *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 (g *GDS) UseFixture(rpc, path string) (err error)

UseFixture allows you to specify a JSON fixture that is loaded from disk as the protocol buffer response for the specified RPC, simplifying the handler mocking.

func (*GDS) Verification

func (g *GDS) Verification(ctx context.Context, in *gds.VerificationRequest) (*gds.VerificationReply, error)

func (*GDS) VerifyContact

func (g *GDS) VerifyContact(ctx context.Context, in *gds.VerifyContactRequest) (*gds.VerifyContactReply, error)

type Members added in v1.5.0

type Members struct {
	members.UnimplementedTRISAMembersServer

	Calls     map[string]int
	OnList    func(context.Context, *members.ListRequest) (*members.ListReply, error)
	OnSummary func(context.Context, *members.SummaryRequest) (*members.SummaryReply, error)
	OnDetails func(context.Context, *members.DetailsRequest) (*members.MemberDetails, error)
	// contains filtered or unexported fields
}

Memberss implements a mock gRPC server that listens on a buffcon and registers the TRISA members service. The RPC methods are able to be set from individual tests so that the user can specify the return of the RPC in order to test specific functionality. The mock allows us to test dual members (TestNet and MainNet) handling from the BFF without having to set up a whole microservices architecture with data storage and managing fixtures.

To set the response of the mock for a particular test, update the Members OnRPC method. e.g. to mock the Summary RPC, set the OnSummary method. The number of calls to the RPC will be recorded to verifiy that the service is being called correctly. Use the Reset method to remove all RPC handlers and set calls back to 0.

NOTE: this mock is not safe for concurrent use. NOTE: if the OnRPC function is not set, the test will panic

func NewMembers added in v1.5.0

func NewMembers(conf config.MembersConfig) (m *Members, err error)

func (*Members) Client added in v1.5.0

func (g *Members) Client() (client members.TRISAMembersClient, err error)

func (*Members) Details added in v1.5.0

func (*Members) DialOpts added in v1.5.0

func (g *Members) DialOpts() (opts []grpc.DialOption)

func (*Members) List added in v1.5.0

func (*Members) Reset added in v1.5.0

func (m *Members) Reset()

func (*Members) Shutdown added in v1.5.0

func (g *Members) Shutdown()

func (*Members) Summary added in v1.5.0

func (*Members) UseError added in v1.5.0

func (m *Members) 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 (*Members) UseFixture added in v1.5.0

func (m *Members) UseFixture(rpc, path string) (err error)

UseFixture allows you to specify a JSON fixture that is loaded from disk as the protocol buffer response for the specified RPC, simplifying the handler mocking.

type Trtl added in v1.5.3

type Trtl struct {
	// contains filtered or unexported fields
}

func NewTrtl added in v1.5.3

func NewTrtl() (t *Trtl, err error)

func (*Trtl) Client added in v1.5.3

func (t *Trtl) Client() (_ store.Store, err error)

func (*Trtl) Shutdown added in v1.5.3

func (t *Trtl) Shutdown()

Jump to

Keyboard shortcuts

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