fakegrpc

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(config *TemplateConfig)

Generate generates a fake server code to stdout.

func HandleRequest

func HandleRequest[R any](
	ss *GRPCServerStub,
	ctx context.Context,
	rpcName string,
	req any,
) (R, error)

HandleRequest is a generic function to handle requests.

Types

type GRPCServer

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

GRPCServer provides a gRPC server.

func NewGRPCServer

func NewGRPCServer() *GRPCServer

NewGRPCServer() assigns a new port and creates a gRPC server.

func (*GRPCServer) Addr

func (gs *GRPCServer) Addr() string

Addr returns the address with a port number.

func (*GRPCServer) Port

func (gs *GRPCServer) Port() string

Port returns the port number of the address.

func (*GRPCServer) Serve

func (gs *GRPCServer) Serve()

Serve starts the gRPC server.

func (*GRPCServer) Server

func (gs *GRPCServer) Server() *grpc.Server

Server returns a grpcServer.

type GRPCServerStub

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

GRPCServerStub provides basic primitives for a fake gRPC server.

func (*GRPCServerStub) ClearAllResponses

func (ss *GRPCServerStub) ClearAllResponses(
	tid string,
)

ClearAllResponses clear all responsed and errors for tid.

func (*GRPCServerStub) HandleRequest

func (ss *GRPCServerStub) HandleRequest(
	ctx context.Context,
	rpcName string,
	req any,
) (any, error)

HandleRequest is a method to handle requestes.

func (*GRPCServerStub) SetResponse

func (ss *GRPCServerStub) SetResponse(
	tid, rpcName string,
	response any,
	err error,
)

SetResponse sets specified response and error for a RPC(rcpName). tid represents Testing ID.

func (*GRPCServerStub) SetResponseCreator

func (ss *GRPCServerStub) SetResponseCreator(
	tid, rpcName string,
	creator ResponseCreator,
)

SetResponseCreator sets a creator for a RPC.

type RPCMethod

type RPCMethod struct {
	Name        string
	ReqTypeName string
	ResTypeName string
}

type RequestCapture

type RequestCapture[RQ, RS protoreflect.ProtoMessage] struct {
	// contains filtered or unexported fields
}

func NewRequestCapture

func NewRequestCapture[RQ, RS protoreflect.ProtoMessage](
	res RS,
	err error,
) *RequestCapture[RQ, RS]

func (*RequestCapture[RQ, RS]) Creator

func (rc *RequestCapture[RQ, RS]) Creator(
	ctx context.Context,
	req RQ,
) (RS, error)

func (*RequestCapture[RQ, RS]) Get

func (rc *RequestCapture[RQ, RS]) Get() RQ

type ResponseBuilder

type ResponseBuilder[RQ, RS protoreflect.ProtoMessage] struct {
	// contains filtered or unexported fields
}

ResponseBuilder builds a ResponseCreator which returns a sequence of response/errors.

func (*ResponseBuilder[RQ, RS]) Append

func (rb *ResponseBuilder[RQ, RS]) Append(
	res RS,
	err error,
)

func (*ResponseBuilder[RQ, RS]) Creator

func (rb *ResponseBuilder[RQ, RS]) Creator(
	ctx context.Context,
	req RQ,
) (RS, error)

type ResponseCreator

type ResponseCreator func(ctx context.Context, req any) (response any, err error)

ResponseCreator is a function to create response and error.

type TemplateConfig

type TemplateConfig struct {
	ServerPackageName      string
	ProtoPackageImportPath string // Import Path
	ProtoPackageImportName string // Import Name
	ServiceName            string
	ServiceClientType      reflect.Type
	Methods                []*RPCMethod
}

TemplateConfig defines paramters to templates.

Jump to

Keyboard shortcuts

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