Documentation
¶
Index ¶
- type GrpcDefinition
- type GrpcLoader
- type GrpcMock
- func (m *GrpcMock) Addr() string
- func (m *GrpcMock) EndRunningContext() []error
- func (m *GrpcMock) GetRecordedRequests() []*RecordedRequest
- func (m *GrpcMock) ResetDefinitions()
- func (m *GrpcMock) SetDefinition(def *GrpcDefinition)
- func (m *GrpcMock) StartServer(addr string) error
- func (m *GrpcMock) Stop()
- type GrpcMocks
- type RecordedRequest
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 GrpcLoader ¶ added in v1.3.3
type GrpcLoader struct {
// contains filtered or unexported fields
}
GrpcLoader reads per-test grpcMocks YAML definitions and calls SetDefinition on the appropriate registered GrpcMock, converting JSON response bodies to proto wire bytes.
func NewGrpcLoader ¶ added in v1.3.3
func NewGrpcLoader(registry *GrpcMocks) *GrpcLoader
NewGrpcLoader creates a loader that uses registry to resolve mock instances and the registry's DescriptorSource for JSON→proto conversion.
func (*GrpcLoader) Load ¶ added in v1.3.3
func (l *GrpcLoader) Load(defs map[string]interface{}) error
Load accepts the map parsed from the grpcMocks YAML field. Each key is a mock name; each value is a map with: service, method, responseBody (JSON string), responseStatus (int).
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 with gRPC reflection enabled. Reflection is backed by protoregistry.GlobalFiles, so any proto-generated Go package imported in the test binary is automatically discoverable.
func (*GrpcMock) EndRunningContext ¶
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 ¶
StartServer starts the gRPC server on the given address.
type GrpcMocks ¶ added in v1.3.3
type GrpcMocks struct {
// contains filtered or unexported fields
}
GrpcMocks is a registry of named GrpcMock instances, shared with a descriptor source used for JSON→proto conversion at load time.
func NewGrpcMocks ¶ added in v1.3.3
func NewGrpcMocks(ds grpcurl.DescriptorSource) *GrpcMocks
NewGrpcMocks creates a registry backed by ds. Pass nil to auto-discover descriptors from protoregistry.GlobalFiles — this works out of the box when the test binary imports proto-generated Go packages.
type RecordedRequest ¶
RecordedRequest is an incoming request captured by the mock server.