grpcmock

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GrpcDefinition

type GrpcDefinition struct {
	Service         string
	Method          string
	ExpectedRequest []byte            // raw proto bytes of expected request (nil = skip verification)
	Response        []byte            // raw proto bytes of response
	ResponseStatus  codes.Code        // gRPC status code
	Metadata        map[string]string // trailing metadata
}

GrpcDefinition describes mock response for a single gRPC method.

type GrpcMock

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

GrpcMock is a mock gRPC server analogous to mocks.ServiceMock for HTTP.

func New

func New() *GrpcMock

New creates a new gRPC mock server.

func (*GrpcMock) Addr

func (m *GrpcMock) Addr() string

Addr returns the listener address or empty string if not started.

func (*GrpcMock) EndRunningContext

func (m *GrpcMock) EndRunningContext() []error

EndRunningContext returns verification errors accumulated during the run.

func (*GrpcMock) GetRecordedRequests

func (m *GrpcMock) GetRecordedRequests() []*RecordedRequest

GetRecordedRequests returns a copy of all recorded incoming requests.

func (*GrpcMock) ResetDefinitions

func (m *GrpcMock) ResetDefinitions()

ResetDefinitions clears all definitions, recorded requests and errors.

func (*GrpcMock) SetDefinition

func (m *GrpcMock) SetDefinition(def *GrpcDefinition)

SetDefinition registers a mock response definition for a gRPC method.

func (*GrpcMock) StartServer

func (m *GrpcMock) StartServer(addr string) error

StartServer starts the gRPC server on the given address.

func (*GrpcMock) Stop

func (m *GrpcMock) Stop()

Stop gracefully stops the gRPC server.

type RecordedRequest

type RecordedRequest struct {
	Method  string
	Payload []byte // raw proto bytes
}

RecordedRequest is an incoming request captured by the mock server.

Jump to

Keyboard shortcuts

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