Documentation
¶
Overview ¶
Package sdk provides an embedded gRPC mock server for tests.
Index ¶
- Variables
- type BidirectionalExpectation
- func (e *BidirectionalExpectation) Delay(d time.Duration) *BidirectionalExpectation
- func (e *BidirectionalExpectation) Effect(effects ...*Effect) *BidirectionalExpectation
- func (e *BidirectionalExpectation) Match(matches ...any) *BidirectionalExpectation
- func (e *BidirectionalExpectation) MatchSequence(matchers ...Matcher) *BidirectionalExpectation
- func (e *BidirectionalExpectation) Once() *BidirectionalExpectation
- func (e *BidirectionalExpectation) Priority(n int) *BidirectionalExpectation
- func (e *BidirectionalExpectation) ReturnError(code codes.Code, msg string) *BidirectionalExpectation
- func (e *BidirectionalExpectation) ReturnErrorWithDetails(code codes.Code, msg string, details ...map[string]any) *BidirectionalExpectation
- func (e *BidirectionalExpectation) ReturnHeaders(headers map[string]string) *BidirectionalExpectation
- func (e *BidirectionalExpectation) ReturnStatus(code codes.Code) *BidirectionalExpectation
- func (e *BidirectionalExpectation) ReturnTrailers(trailers map[string]string) *BidirectionalExpectation
- func (e *BidirectionalExpectation) Run(fn BidirectionalHandler) *BidirectionalExpectation
- func (e *BidirectionalExpectation) SendStream(items ...any) *BidirectionalExpectation
- func (e *BidirectionalExpectation) SendStreamTemplate(document string) *BidirectionalExpectation
- func (e *BidirectionalExpectation) Session(id string) *BidirectionalExpectation
- func (b *BidirectionalExpectation) StubID() string
- func (e *BidirectionalExpectation) Times(n int) *BidirectionalExpectation
- func (e *BidirectionalExpectation) Twice() *BidirectionalExpectation
- func (e *BidirectionalExpectation) WithHeader(headers ...Matcher) *BidirectionalExpectation
- func (e *BidirectionalExpectation) WithID(id uuid.UUID) *BidirectionalExpectation
- type BidirectionalHandler
- type CallRecord
- type ClientStreamExpectation
- func (e *ClientStreamExpectation) Delay(d time.Duration) *ClientStreamExpectation
- func (e *ClientStreamExpectation) Effect(effects ...*Effect) *ClientStreamExpectation
- func (e *ClientStreamExpectation) Match(matches ...any) *ClientStreamExpectation
- func (e *ClientStreamExpectation) MatchSequence(matchers ...Matcher) *ClientStreamExpectation
- func (e *ClientStreamExpectation) Once() *ClientStreamExpectation
- func (e *ClientStreamExpectation) Priority(n int) *ClientStreamExpectation
- func (e *ClientStreamExpectation) Return(kv ...any) *ClientStreamExpectation
- func (e *ClientStreamExpectation) ReturnError(code codes.Code, msg string) *ClientStreamExpectation
- func (e *ClientStreamExpectation) ReturnErrorWithDetails(code codes.Code, msg string, details ...map[string]any) *ClientStreamExpectation
- func (e *ClientStreamExpectation) ReturnHeaders(headers map[string]string) *ClientStreamExpectation
- func (e *ClientStreamExpectation) ReturnJSON(v any) *ClientStreamExpectation
- func (e *ClientStreamExpectation) ReturnProto(msg proto.Message) *ClientStreamExpectation
- func (e *ClientStreamExpectation) ReturnStatus(code codes.Code) *ClientStreamExpectation
- func (e *ClientStreamExpectation) ReturnTemplate(document string) *ClientStreamExpectation
- func (e *ClientStreamExpectation) ReturnTrailers(trailers map[string]string) *ClientStreamExpectation
- func (e *ClientStreamExpectation) ReturnValue(v any) *ClientStreamExpectation
- func (e *ClientStreamExpectation) Run(fn ClientStreamHandler) *ClientStreamExpectation
- func (e *ClientStreamExpectation) Session(id string) *ClientStreamExpectation
- func (b *ClientStreamExpectation) StubID() string
- func (e *ClientStreamExpectation) Times(n int) *ClientStreamExpectation
- func (e *ClientStreamExpectation) Twice() *ClientStreamExpectation
- func (e *ClientStreamExpectation) WithHeader(headers ...Matcher) *ClientStreamExpectation
- func (e *ClientStreamExpectation) WithID(id uuid.UUID) *ClientStreamExpectation
- type ClientStreamHandler
- type DelayItem
- type Effect
- type EffectBuilder
- func (b *EffectBuilder) Build() *Effect
- func (b *EffectBuilder) Match(key string, value any) *EffectBuilder
- func (b *EffectBuilder) MatchAny(matchers ...Matcher) *EffectBuilder
- func (b *EffectBuilder) Priority(n int) *EffectBuilder
- func (b *EffectBuilder) Return(kv ...any) *EffectBuilder
- func (b *EffectBuilder) ReturnError(code codes.Code, msg string) *EffectBuilder
- func (b *EffectBuilder) ReturnErrorWithDetails(code codes.Code, msg string, details ...map[string]any) *EffectBuilder
- func (b *EffectBuilder) ReturnHeaders(headers map[string]string) *EffectBuilder
- func (b *EffectBuilder) ReturnTemplate(document string) *EffectBuilder
- func (b *EffectBuilder) ReturnTrailers(trailers map[string]string) *EffectBuilder
- func (b *EffectBuilder) SendStream(items ...any) *EffectBuilder
- func (b *EffectBuilder) SendStreamTemplate(document string) *EffectBuilder
- func (b *EffectBuilder) Session(id string) *EffectBuilder
- func (b *EffectBuilder) Times(n int) *EffectBuilder
- func (b *EffectBuilder) WithHeader(headers ...Matcher) *EffectBuilder
- func (b *EffectBuilder) WithID(id uuid.UUID) *EffectBuilder
- type ExpectationNotMetError
- type InMemoryRecorder
- type Matcher
- type Option
- func WithBatch() Option
- func WithDescriptors(fds *descriptorpb.FileDescriptorSet) Option
- func WithFileDescriptor(fd protoreflect.FileDescriptor) Option
- func WithGRPCTimeout(d time.Duration) Option
- func WithHTTPClient(client *http.Client) Option
- func WithHealthCheckTimeout(d time.Duration) Option
- func WithListenAddr(network, addr string) Option
- func WithProtoFiles(paths ...string) Option
- func WithReflection(addr string) Option
- func WithRemote(grpcAddr string, restURL string) Option
- func WithSession(sessionID string) Option
- func WithSessionTTL(d time.Duration) Option
- type Server
- func (s *Server) Address() string
- func (s *Server) Called(fullMethod string) int
- func (s *Server) Close() error
- func (s *Server) Conn() *grpc.ClientConn
- func (s *Server) ExpectBidirectionalStream(fullMethod string) *BidirectionalExpectation
- func (s *Server) ExpectClientStream(fullMethod string) *ClientStreamExpectation
- func (s *Server) ExpectServerStream(fullMethod string) *ServerStreamExpectation
- func (s *Server) ExpectUnary(fullMethod string) *UnaryExpectation
- func (s *Server) ExpectationsWereMet() error
- func (s *Server) ExpectationsWereMetContext(ctx context.Context) error
- func (s *Server) Flush() error
- func (s *Server) History() []CallRecord
- func (s *Server) Reset()
- func (s *Server) TotalCalls() int
- type ServerStreamBuilder
- type ServerStreamExpectation
- func (e *ServerStreamExpectation) Delay(d time.Duration) *ServerStreamExpectation
- func (e *ServerStreamExpectation) Effect(effects ...*Effect) *ServerStreamExpectation
- func (e *ServerStreamExpectation) Match(matches ...any) *ServerStreamExpectation
- func (e *ServerStreamExpectation) Once() *ServerStreamExpectation
- func (e *ServerStreamExpectation) Priority(n int) *ServerStreamExpectation
- func (e *ServerStreamExpectation) ReturnError(code codes.Code, msg string) *ServerStreamExpectation
- func (e *ServerStreamExpectation) ReturnErrorWithDetails(code codes.Code, msg string, details ...map[string]any) *ServerStreamExpectation
- func (e *ServerStreamExpectation) ReturnHeaders(headers map[string]string) *ServerStreamExpectation
- func (e *ServerStreamExpectation) ReturnStatus(code codes.Code) *ServerStreamExpectation
- func (e *ServerStreamExpectation) ReturnTrailers(trailers map[string]string) *ServerStreamExpectation
- func (e *ServerStreamExpectation) Run(fn ServerStreamHandler) *ServerStreamExpectation
- func (e *ServerStreamExpectation) SendStream(items ...any) *ServerStreamBuilder
- func (e *ServerStreamExpectation) SendStreamTemplate(document string) *ServerStreamExpectation
- func (e *ServerStreamExpectation) Session(id string) *ServerStreamExpectation
- func (b *ServerStreamExpectation) StubID() string
- func (e *ServerStreamExpectation) Times(n int) *ServerStreamExpectation
- func (e *ServerStreamExpectation) Twice() *ServerStreamExpectation
- func (e *ServerStreamExpectation) WithHeader(headers ...Matcher) *ServerStreamExpectation
- func (e *ServerStreamExpectation) WithID(id uuid.UUID) *ServerStreamExpectation
- type ServerStreamHandler
- type StreamErrorItem
- type TestingT
- type UnaryExpectation
- func (e *UnaryExpectation) Delay(d time.Duration) *UnaryExpectation
- func (e *UnaryExpectation) Effect(effects ...*Effect) *UnaryExpectation
- func (e *UnaryExpectation) Match(matches ...any) *UnaryExpectation
- func (e *UnaryExpectation) NextWillReturn(kv ...any) *UnaryExpectation
- func (e *UnaryExpectation) NextWillReturnError(code codes.Code, msg string) *UnaryExpectation
- func (e *UnaryExpectation) Once() *UnaryExpectation
- func (e *UnaryExpectation) Priority(n int) *UnaryExpectation
- func (e *UnaryExpectation) Return(kv ...any) *UnaryExpectation
- func (e *UnaryExpectation) ReturnError(code codes.Code, msg string) *UnaryExpectation
- func (e *UnaryExpectation) ReturnErrorWithDetails(code codes.Code, msg string, details ...map[string]any) *UnaryExpectation
- func (e *UnaryExpectation) ReturnHeaders(headers map[string]string) *UnaryExpectation
- func (e *UnaryExpectation) ReturnJSON(v any) *UnaryExpectation
- func (e *UnaryExpectation) ReturnProto(msg proto.Message) *UnaryExpectation
- func (e *UnaryExpectation) ReturnStatus(code codes.Code) *UnaryExpectation
- func (e *UnaryExpectation) ReturnTemplate(document string) *UnaryExpectation
- func (e *UnaryExpectation) ReturnTrailers(trailers map[string]string) *UnaryExpectation
- func (e *UnaryExpectation) ReturnValue(v any) *UnaryExpectation
- func (e *UnaryExpectation) Run(fn UnaryHandler) *UnaryExpectation
- func (e *UnaryExpectation) Session(id string) *UnaryExpectation
- func (b *UnaryExpectation) StubID() string
- func (e *UnaryExpectation) Times(n int) *UnaryExpectation
- func (e *UnaryExpectation) Twice() *UnaryExpectation
- func (e *UnaryExpectation) WithHeader(headers ...Matcher) *UnaryExpectation
- func (e *UnaryExpectation) WithID(id uuid.UUID) *UnaryExpectation
- type UnaryHandler
Constants ¶
This section is empty.
Variables ¶
var ( ErrDescriptorsRequired = errors.New("gripmock: descriptors required (use WithDescriptors or MockFrom)") ErrNoUsableServicesFoundViaReflection = errors.New("no services found via reflection (or only grpc.reflection/grpc.health)") ErrUnexpectedResponse = errors.New("unexpected response: not ListServicesResponse") ErrVerificationFailed = errors.New("gripmock: expectations not met") ErrInvalidInput = errors.New("gripmock: invalid input") ErrReflection = errors.New("gripmock: reflection error") )
var ErrServerNotHealthy = errors.New("gripmock: server did not become healthy")
Functions ¶
This section is empty.
Types ¶
type BidirectionalExpectation ¶ added in v3.16.0
type BidirectionalExpectation struct {
// contains filtered or unexported fields
}
BidirectionalExpectation builds a bidi-stream mock expectation.
func (*BidirectionalExpectation) Delay ¶ added in v3.20.0
func (e *BidirectionalExpectation) Delay(d time.Duration) *BidirectionalExpectation
Delay holds every message of the stream back by d.
func (*BidirectionalExpectation) Effect ¶ added in v3.16.0
func (e *BidirectionalExpectation) Effect(effects ...*Effect) *BidirectionalExpectation
Effect attaches side effects to a bidirectional-stream expectation.
func (*BidirectionalExpectation) Match ¶ added in v3.20.0
func (e *BidirectionalExpectation) Match(matches ...any) *BidirectionalExpectation
func (*BidirectionalExpectation) MatchSequence ¶ added in v3.20.0
func (e *BidirectionalExpectation) MatchSequence(matchers ...Matcher) *BidirectionalExpectation
MatchSequence matches the incoming messages positionally.
func (*BidirectionalExpectation) Once ¶ added in v3.20.0
func (e *BidirectionalExpectation) Once() *BidirectionalExpectation
func (*BidirectionalExpectation) Priority ¶ added in v3.16.0
func (e *BidirectionalExpectation) Priority(n int) *BidirectionalExpectation
func (*BidirectionalExpectation) ReturnError ¶ added in v3.20.0
func (e *BidirectionalExpectation) ReturnError(code codes.Code, msg string) *BidirectionalExpectation
ReturnError fails the exchange with a gRPC status instead of answering.
func (*BidirectionalExpectation) ReturnErrorWithDetails ¶ added in v3.20.0
func (e *BidirectionalExpectation) ReturnErrorWithDetails( code codes.Code, msg string, details ...map[string]any, ) *BidirectionalExpectation
func (*BidirectionalExpectation) ReturnHeaders ¶ added in v3.20.0
func (e *BidirectionalExpectation) ReturnHeaders(headers map[string]string) *BidirectionalExpectation
func (*BidirectionalExpectation) ReturnStatus ¶ added in v3.20.0
func (e *BidirectionalExpectation) ReturnStatus(code codes.Code) *BidirectionalExpectation
ReturnStatus fails the exchange with a bare gRPC status code and no message.
func (*BidirectionalExpectation) ReturnTrailers ¶ added in v3.20.0
func (e *BidirectionalExpectation) ReturnTrailers(trailers map[string]string) *BidirectionalExpectation
func (*BidirectionalExpectation) Run ¶ added in v3.16.0
func (e *BidirectionalExpectation) Run(fn BidirectionalHandler) *BidirectionalExpectation
Run executes a custom handler for this bidi expectation.
func (*BidirectionalExpectation) SendStream ¶ added in v3.20.0
func (e *BidirectionalExpectation) SendStream(items ...any) *BidirectionalExpectation
func (*BidirectionalExpectation) SendStreamTemplate ¶ added in v3.22.0
func (e *BidirectionalExpectation) SendStreamTemplate(document string) *BidirectionalExpectation
func (*BidirectionalExpectation) Session ¶ added in v3.20.0
func (e *BidirectionalExpectation) Session(id string) *BidirectionalExpectation
Session isolates this stub to a specific session (X-Gripmock-Session header).
func (*BidirectionalExpectation) StubID ¶ added in v3.16.0
func (b *BidirectionalExpectation) StubID() string
Available after calling a terminal method (Return, SendStream, Run).
func (*BidirectionalExpectation) Times ¶ added in v3.16.0
func (e *BidirectionalExpectation) Times(n int) *BidirectionalExpectation
func (*BidirectionalExpectation) Twice ¶ added in v3.20.0
func (e *BidirectionalExpectation) Twice() *BidirectionalExpectation
func (*BidirectionalExpectation) WithHeader ¶ added in v3.16.0
func (e *BidirectionalExpectation) WithHeader(headers ...Matcher) *BidirectionalExpectation
func (*BidirectionalExpectation) WithID ¶ added in v3.20.0
func (e *BidirectionalExpectation) WithID(id uuid.UUID) *BidirectionalExpectation
type BidirectionalHandler ¶ added in v3.16.0
BidirectionalHandler processes a bidirectional stream.
type CallRecord ¶
type CallRecord = history.CallRecord
CallRecord is a recorded gRPC call. Re-export for SDK users.
type ClientStreamExpectation ¶ added in v3.16.0
type ClientStreamExpectation struct {
// contains filtered or unexported fields
}
ClientStreamExpectation builds a client-stream mock expectation.
func (*ClientStreamExpectation) Delay ¶ added in v3.20.0
func (e *ClientStreamExpectation) Delay(d time.Duration) *ClientStreamExpectation
Delay holds the response back before the reply is sent.
func (*ClientStreamExpectation) Effect ¶ added in v3.16.0
func (e *ClientStreamExpectation) Effect(effects ...*Effect) *ClientStreamExpectation
Effect attaches side effects to a client-stream expectation.
func (*ClientStreamExpectation) Match ¶ added in v3.16.0
func (e *ClientStreamExpectation) Match(matches ...any) *ClientStreamExpectation
Match accepts key-value pairs (shorthand for Equals on payload) or Matcher values.
func (*ClientStreamExpectation) MatchSequence ¶ added in v3.20.0
func (e *ClientStreamExpectation) MatchSequence(matchers ...Matcher) *ClientStreamExpectation
func (*ClientStreamExpectation) Once ¶ added in v3.20.0
func (e *ClientStreamExpectation) Once() *ClientStreamExpectation
func (*ClientStreamExpectation) Priority ¶ added in v3.16.0
func (e *ClientStreamExpectation) Priority(n int) *ClientStreamExpectation
func (*ClientStreamExpectation) Return ¶ added in v3.16.0
func (e *ClientStreamExpectation) Return(kv ...any) *ClientStreamExpectation
func (*ClientStreamExpectation) ReturnError ¶ added in v3.16.0
func (e *ClientStreamExpectation) ReturnError(code codes.Code, msg string) *ClientStreamExpectation
func (*ClientStreamExpectation) ReturnErrorWithDetails ¶ added in v3.20.0
func (e *ClientStreamExpectation) ReturnErrorWithDetails( code codes.Code, msg string, details ...map[string]any, ) *ClientStreamExpectation
ReturnErrorWithDetails returns a gRPC error carrying google.rpc.* details.
func (*ClientStreamExpectation) ReturnHeaders ¶ added in v3.20.0
func (e *ClientStreamExpectation) ReturnHeaders(headers map[string]string) *ClientStreamExpectation
func (*ClientStreamExpectation) ReturnJSON ¶ added in v3.20.0
func (e *ClientStreamExpectation) ReturnJSON(v any) *ClientStreamExpectation
ReturnJSON marshals any value to JSON and uses it as response.
func (*ClientStreamExpectation) ReturnProto ¶ added in v3.20.0
func (e *ClientStreamExpectation) ReturnProto(msg proto.Message) *ClientStreamExpectation
ReturnProto marshals a proto.Message to JSON and uses it as response.
func (*ClientStreamExpectation) ReturnStatus ¶ added in v3.20.0
func (e *ClientStreamExpectation) ReturnStatus(code codes.Code) *ClientStreamExpectation
ReturnStatus replies with a bare gRPC status code and no message.
func (*ClientStreamExpectation) ReturnTemplate ¶ added in v3.22.0
func (e *ClientStreamExpectation) ReturnTemplate(document string) *ClientStreamExpectation
func (*ClientStreamExpectation) ReturnTrailers ¶ added in v3.20.0
func (e *ClientStreamExpectation) ReturnTrailers(trailers map[string]string) *ClientStreamExpectation
func (*ClientStreamExpectation) ReturnValue ¶ added in v3.20.0
func (e *ClientStreamExpectation) ReturnValue(v any) *ClientStreamExpectation
func (*ClientStreamExpectation) Run ¶ added in v3.20.0
func (e *ClientStreamExpectation) Run(fn ClientStreamHandler) *ClientStreamExpectation
Run drains the request stream with fn and replies with its return value.
func (*ClientStreamExpectation) Session ¶ added in v3.20.0
func (e *ClientStreamExpectation) Session(id string) *ClientStreamExpectation
Session isolates this stub to a specific session (X-Gripmock-Session header).
func (*ClientStreamExpectation) StubID ¶ added in v3.16.0
func (b *ClientStreamExpectation) StubID() string
Available after calling a terminal method (Return, SendStream, Run).
func (*ClientStreamExpectation) Times ¶ added in v3.16.0
func (e *ClientStreamExpectation) Times(n int) *ClientStreamExpectation
func (*ClientStreamExpectation) Twice ¶ added in v3.20.0
func (e *ClientStreamExpectation) Twice() *ClientStreamExpectation
func (*ClientStreamExpectation) WithHeader ¶ added in v3.16.0
func (e *ClientStreamExpectation) WithHeader(headers ...Matcher) *ClientStreamExpectation
func (*ClientStreamExpectation) WithID ¶ added in v3.20.0
func (e *ClientStreamExpectation) WithID(id uuid.UUID) *ClientStreamExpectation
type ClientStreamHandler ¶ added in v3.16.0
type Effect ¶ added in v3.16.0
type Effect struct {
// contains filtered or unexported fields
}
Effect is a side effect that executes after a stub is matched.
func DeleteStub ¶ added in v3.16.0
DeleteStub creates an effect that deletes a stub by ID on match.
type EffectBuilder ¶ added in v3.16.0
type EffectBuilder struct {
// contains filtered or unexported fields
}
EffectBuilder builds a stub that is registered when the triggering stub is matched.
func Upsert ¶ added in v3.16.0
func Upsert(service, method string) *EffectBuilder
Upsert creates an effect that registers another stub on match.
func (*EffectBuilder) Build ¶ added in v3.16.0
func (b *EffectBuilder) Build() *Effect
func (*EffectBuilder) Match ¶ added in v3.16.0
func (b *EffectBuilder) Match(key string, value any) *EffectBuilder
Match adds an exact-equality matcher. Use MatchAny for contains/matches/glob.
func (*EffectBuilder) MatchAny ¶ added in v3.20.0
func (b *EffectBuilder) MatchAny(matchers ...Matcher) *EffectBuilder
func (*EffectBuilder) Priority ¶ added in v3.20.0
func (b *EffectBuilder) Priority(n int) *EffectBuilder
Priority ranks the effect stub against others for the same method.
func (*EffectBuilder) Return ¶ added in v3.16.0
func (b *EffectBuilder) Return(kv ...any) *EffectBuilder
func (*EffectBuilder) ReturnError ¶ added in v3.16.0
func (b *EffectBuilder) ReturnError(code codes.Code, msg string) *EffectBuilder
func (*EffectBuilder) ReturnErrorWithDetails ¶ added in v3.20.0
func (b *EffectBuilder) ReturnErrorWithDetails(code codes.Code, msg string, details ...map[string]any) *EffectBuilder
ReturnErrorWithDetails fails the effect stub with google.rpc.* details.
func (*EffectBuilder) ReturnHeaders ¶ added in v3.20.0
func (b *EffectBuilder) ReturnHeaders(headers map[string]string) *EffectBuilder
ReturnHeaders sets response metadata on the effect stub.
func (*EffectBuilder) ReturnTemplate ¶ added in v3.22.0
func (b *EffectBuilder) ReturnTemplate(document string) *EffectBuilder
ReturnTemplate makes the effect stub answer with a Go template, rendered per request against the child's own request rather than the parent's.
func (*EffectBuilder) ReturnTrailers ¶ added in v3.20.0
func (b *EffectBuilder) ReturnTrailers(trailers map[string]string) *EffectBuilder
ReturnTrailers sets trailing metadata on the effect stub.
func (*EffectBuilder) SendStream ¶ added in v3.20.0
func (b *EffectBuilder) SendStream(items ...any) *EffectBuilder
SendStream makes the effect stub answer with a server stream.
func (*EffectBuilder) SendStreamTemplate ¶ added in v3.22.0
func (b *EffectBuilder) SendStreamTemplate(document string) *EffectBuilder
SendStreamTemplate makes the effect stub answer with a stream computed by a Go template.
func (*EffectBuilder) Session ¶ added in v3.20.0
func (b *EffectBuilder) Session(id string) *EffectBuilder
Session scopes the effect stub to one session.
func (*EffectBuilder) Times ¶ added in v3.20.0
func (b *EffectBuilder) Times(n int) *EffectBuilder
Times limits how many calls the effect stub may answer.
func (*EffectBuilder) WithHeader ¶ added in v3.20.0
func (b *EffectBuilder) WithHeader(headers ...Matcher) *EffectBuilder
WithHeader matches request metadata on the effect stub.
func (*EffectBuilder) WithID ¶ added in v3.20.0
func (b *EffectBuilder) WithID(id uuid.UUID) *EffectBuilder
WithID pins the effect stub's identifier so a later DeleteStub can target it.
type ExpectationNotMetError ¶ added in v3.16.0
ExpectationNotMetError describes a single unmet expectation for ExpectationsWereMet. Is(ErrVerificationFailed) returns true so callers can use errors.Is.
func (*ExpectationNotMetError) Error ¶ added in v3.16.0
func (e *ExpectationNotMetError) Error() string
func (*ExpectationNotMetError) Is ¶ added in v3.16.0
func (e *ExpectationNotMetError) Is(target error) bool
type InMemoryRecorder ¶
type InMemoryRecorder = history.MemoryStore
InMemoryRecorder is the in-memory call recorder used by the embedded server.
type Matcher ¶ added in v3.16.0
type Matcher struct {
// contains filtered or unexported fields
}
Matcher describes how to match a gRPC request field or header. Same type works for both payload fields and gRPC metadata headers. Created via Equals, Contains, Matches, Glob; composed via AnyOf, And.
Use Match(sdk.Contains(...)) for payload matching and WithHeader(sdk.Contains(...)) for gRPC metadata matching.
func And ¶ added in v3.16.0
And returns a Matcher that passes when all given matchers match (AND logic).
func AnyOf ¶ added in v3.16.0
AnyOf returns a Matcher that passes when at least one alternative matches (OR logic).
func IgnoreArrayOrder ¶
type Option ¶
type Option func(*options)
func WithBatch ¶ added in v3.16.0
func WithBatch() Option
WithBatch enables batch mode for remote stub registration.
func WithDescriptors ¶
func WithDescriptors(fds *descriptorpb.FileDescriptorSet) Option
WithDescriptors appends files from the FileDescriptorSet to the mock server (skips duplicates by name).
func WithFileDescriptor ¶
func WithFileDescriptor(fd protoreflect.FileDescriptor) Option
WithFileDescriptor appends a generated protoreflect.FileDescriptor (e.g. helloworld.File_service_proto).
func WithGRPCTimeout ¶ added in v3.7.1
WithGRPCTimeout sets default per-RPC timeout for remote gRPC calls.
func WithHTTPClient ¶ added in v3.7.1
WithHTTPClient overrides the HTTP client used by WithRemote mode for REST API calls.
func WithHealthCheckTimeout ¶ added in v3.7.1
func WithListenAddr ¶
WithListenAddr sets network and address for real port listening. The default is a loopback port (127.0.0.1:0), which is also the address the server reports.
func WithProtoFiles ¶ added in v3.16.0
func WithReflection ¶ added in v3.16.0
WithReflection resolves descriptors from a running gRPC server via reflection.
func WithRemote ¶ added in v3.7.1
WithRemote configures the mock to connect to an external gripmock process.
func WithSession ¶
WithSession sets the session ID for isolation.
func WithSessionTTL ¶ added in v3.7.1
WithSessionTTL configures automatic cleanup time for session-scoped remote resources.
type Server ¶ added in v3.16.0
type Server struct {
// contains filtered or unexported fields
}
Server is a running gRPC mock server (v2 API).
func (*Server) Address ¶ added in v3.16.0
Address returns the server address (e.g. "127.0.0.1:PORT").
func (*Server) Close ¶ added in v3.16.0
Close flushes pending stubs in batch mode and shuts down the server.
func (*Server) Conn ¶ added in v3.16.0
func (s *Server) Conn() *grpc.ClientConn
func (*Server) ExpectBidirectionalStream ¶ added in v3.16.0
func (s *Server) ExpectBidirectionalStream(fullMethod string) *BidirectionalExpectation
ExpectBidirectionalStream terminal: Run.
func (*Server) ExpectClientStream ¶ added in v3.16.0
func (s *Server) ExpectClientStream(fullMethod string) *ClientStreamExpectation
ExpectClientStream terminal: Return, ReturnError.
func (*Server) ExpectServerStream ¶ added in v3.16.0
func (s *Server) ExpectServerStream(fullMethod string) *ServerStreamExpectation
ExpectServerStream terminal: SendStream.
func (*Server) ExpectUnary ¶ added in v3.16.0
func (s *Server) ExpectUnary(fullMethod string) *UnaryExpectation
ExpectUnary terminal: Return, ReturnProto, ReturnError, Run.
func (*Server) ExpectationsWereMet ¶ added in v3.16.0
ExpectationsWereMet checks all expectations with non-zero Times were fulfilled.
func (*Server) ExpectationsWereMetContext ¶ added in v3.16.0
ExpectationsWereMetContext is the context-aware version of ExpectationsWereMet.
func (*Server) Flush ¶ added in v3.16.0
Flush is a no-op for embedded mode and non-batch remote mode.
func (*Server) History ¶ added in v3.16.0
func (s *Server) History() []CallRecord
func (*Server) TotalCalls ¶ added in v3.16.0
type ServerStreamBuilder ¶ added in v3.16.0
type ServerStreamBuilder struct {
// contains filtered or unexported fields
}
ServerStreamBuilder extends ServerStreamExpectation for chaining additional stream messages.
func (*ServerStreamBuilder) NextWillReturn ¶ added in v3.16.0
func (b *ServerStreamBuilder) NextWillReturn(kv ...any) *ServerStreamBuilder
NextWillReturn registers a new stub with lower priority.
func (*ServerStreamBuilder) Send ¶ added in v3.16.0
func (b *ServerStreamBuilder) Send(kv ...any) *ServerStreamBuilder
Send accepts KV pairs or DelayItem: Send(Delay(100*ms, "msg", "hello")).
type ServerStreamExpectation ¶ added in v3.16.0
type ServerStreamExpectation struct {
// contains filtered or unexported fields
}
ServerStreamExpectation builds a server-stream mock expectation.
func (*ServerStreamExpectation) Delay ¶ added in v3.20.0
func (e *ServerStreamExpectation) Delay(d time.Duration) *ServerStreamExpectation
func (*ServerStreamExpectation) Effect ¶ added in v3.16.0
func (e *ServerStreamExpectation) Effect(effects ...*Effect) *ServerStreamExpectation
Effect attaches side effects to a server-stream expectation.
func (*ServerStreamExpectation) Match ¶ added in v3.16.0
func (e *ServerStreamExpectation) Match(matches ...any) *ServerStreamExpectation
Match accepts key-value pairs (shorthand for Equals on payload) or Matcher values.
func (*ServerStreamExpectation) Once ¶ added in v3.16.0
func (e *ServerStreamExpectation) Once() *ServerStreamExpectation
func (*ServerStreamExpectation) Priority ¶ added in v3.16.0
func (e *ServerStreamExpectation) Priority(n int) *ServerStreamExpectation
func (*ServerStreamExpectation) ReturnError ¶ added in v3.20.0
func (e *ServerStreamExpectation) ReturnError(code codes.Code, msg string) *ServerStreamExpectation
ReturnError terminates the call with a gRPC status instead of a stream.
func (*ServerStreamExpectation) ReturnErrorWithDetails ¶ added in v3.20.0
func (e *ServerStreamExpectation) ReturnErrorWithDetails( code codes.Code, msg string, details ...map[string]any, ) *ServerStreamExpectation
func (*ServerStreamExpectation) ReturnHeaders ¶ added in v3.20.0
func (e *ServerStreamExpectation) ReturnHeaders(headers map[string]string) *ServerStreamExpectation
func (*ServerStreamExpectation) ReturnStatus ¶ added in v3.20.0
func (e *ServerStreamExpectation) ReturnStatus(code codes.Code) *ServerStreamExpectation
ReturnStatus terminates the call with a bare gRPC status code and no message.
func (*ServerStreamExpectation) ReturnTrailers ¶ added in v3.20.0
func (e *ServerStreamExpectation) ReturnTrailers(trailers map[string]string) *ServerStreamExpectation
func (*ServerStreamExpectation) Run ¶ added in v3.20.0
func (e *ServerStreamExpectation) Run(fn ServerStreamHandler) *ServerStreamExpectation
Run writes the response stream from fn instead of a static Output.Stream.
func (*ServerStreamExpectation) SendStream ¶ added in v3.16.0
func (e *ServerStreamExpectation) SendStream(items ...any) *ServerStreamBuilder
func (*ServerStreamExpectation) SendStreamTemplate ¶ added in v3.22.0
func (e *ServerStreamExpectation) SendStreamTemplate(document string) *ServerStreamExpectation
func (*ServerStreamExpectation) Session ¶ added in v3.20.0
func (e *ServerStreamExpectation) Session(id string) *ServerStreamExpectation
Session isolates this stub to a specific session (X-Gripmock-Session header).
func (*ServerStreamExpectation) StubID ¶ added in v3.16.0
func (b *ServerStreamExpectation) StubID() string
Available after calling a terminal method (Return, SendStream, Run).
func (*ServerStreamExpectation) Times ¶ added in v3.16.0
func (e *ServerStreamExpectation) Times(n int) *ServerStreamExpectation
func (*ServerStreamExpectation) Twice ¶ added in v3.16.0
func (e *ServerStreamExpectation) Twice() *ServerStreamExpectation
func (*ServerStreamExpectation) WithHeader ¶ added in v3.16.0
func (e *ServerStreamExpectation) WithHeader(headers ...Matcher) *ServerStreamExpectation
func (*ServerStreamExpectation) WithID ¶ added in v3.20.0
func (e *ServerStreamExpectation) WithID(id uuid.UUID) *ServerStreamExpectation
type ServerStreamHandler ¶ added in v3.16.0
ServerStreamHandler processes a server-stream request.
type StreamErrorItem ¶ added in v3.20.0
StreamErrorItem aborts a stream at this position instead of sending a message.
func StreamError ¶ added in v3.20.0
type UnaryExpectation ¶ added in v3.16.0
type UnaryExpectation struct {
// contains filtered or unexported fields
}
UnaryExpectation builds a unary mock expectation.
func (*UnaryExpectation) Delay ¶ added in v3.20.0
func (e *UnaryExpectation) Delay(d time.Duration) *UnaryExpectation
Delay holds the response back before it is sent.
func (*UnaryExpectation) Effect ¶ added in v3.16.0
func (e *UnaryExpectation) Effect(effects ...*Effect) *UnaryExpectation
Effect attaches side effects to a unary expectation.
func (*UnaryExpectation) Match ¶ added in v3.16.0
func (e *UnaryExpectation) Match(matches ...any) *UnaryExpectation
Match accepts key-value pairs (shorthand for Equals on payload) or Matcher values.
func (*UnaryExpectation) NextWillReturn ¶ added in v3.16.0
func (e *UnaryExpectation) NextWillReturn(kv ...any) *UnaryExpectation
NextWillReturn chains sequential responses: 1st call→Return, 2nd→NextWillReturn, etc.
func (*UnaryExpectation) NextWillReturnError ¶ added in v3.16.0
func (e *UnaryExpectation) NextWillReturnError(code codes.Code, msg string) *UnaryExpectation
func (*UnaryExpectation) Once ¶ added in v3.16.0
func (e *UnaryExpectation) Once() *UnaryExpectation
func (*UnaryExpectation) Priority ¶ added in v3.16.0
func (e *UnaryExpectation) Priority(n int) *UnaryExpectation
func (*UnaryExpectation) Return ¶ added in v3.16.0
func (e *UnaryExpectation) Return(kv ...any) *UnaryExpectation
Return with optional Delay: Return(Delay(100*ms, "msg", "hello")).
func (*UnaryExpectation) ReturnError ¶ added in v3.16.0
func (e *UnaryExpectation) ReturnError(code codes.Code, msg string) *UnaryExpectation
ReturnError returns a gRPC error for the call.
func (*UnaryExpectation) ReturnErrorWithDetails ¶ added in v3.16.0
func (e *UnaryExpectation) ReturnErrorWithDetails(code codes.Code, msg string, details ...map[string]any) *UnaryExpectation
ReturnErrorWithDetails returns a gRPC error with additional error details.
func (*UnaryExpectation) ReturnHeaders ¶ added in v3.20.0
func (e *UnaryExpectation) ReturnHeaders(headers map[string]string) *UnaryExpectation
func (*UnaryExpectation) ReturnJSON ¶ added in v3.16.0
func (e *UnaryExpectation) ReturnJSON(v any) *UnaryExpectation
ReturnJSON marshals any value to JSON and uses it as response.
func (*UnaryExpectation) ReturnProto ¶ added in v3.16.0
func (e *UnaryExpectation) ReturnProto(msg proto.Message) *UnaryExpectation
ReturnProto marshals a proto.Message to JSON and uses it as response.
func (*UnaryExpectation) ReturnStatus ¶ added in v3.20.0
func (e *UnaryExpectation) ReturnStatus(code codes.Code) *UnaryExpectation
ReturnStatus replies with a bare gRPC status code and no message.
func (*UnaryExpectation) ReturnTemplate ¶ added in v3.22.0
func (e *UnaryExpectation) ReturnTemplate(document string) *UnaryExpectation
func (*UnaryExpectation) ReturnTrailers ¶ added in v3.20.0
func (e *UnaryExpectation) ReturnTrailers(trailers map[string]string) *UnaryExpectation
ReturnTrailers sets response metadata sent with the closing status.
func (*UnaryExpectation) ReturnValue ¶ added in v3.20.0
func (e *UnaryExpectation) ReturnValue(v any) *UnaryExpectation
ReturnValue replies with v verbatim, including scalars, arrays and null.
func (*UnaryExpectation) Run ¶ added in v3.16.0
func (e *UnaryExpectation) Run(fn UnaryHandler) *UnaryExpectation
func (*UnaryExpectation) Session ¶ added in v3.16.0
func (e *UnaryExpectation) Session(id string) *UnaryExpectation
Session isolates this stub to a specific session (X-Gripmock-Session header).
func (*UnaryExpectation) StubID ¶ added in v3.16.0
func (b *UnaryExpectation) StubID() string
Available after calling a terminal method (Return, SendStream, Run).
func (*UnaryExpectation) Times ¶ added in v3.16.0
func (e *UnaryExpectation) Times(n int) *UnaryExpectation
func (*UnaryExpectation) Twice ¶ added in v3.16.0
func (e *UnaryExpectation) Twice() *UnaryExpectation
func (*UnaryExpectation) WithHeader ¶ added in v3.16.0
func (e *UnaryExpectation) WithHeader(headers ...Matcher) *UnaryExpectation
func (*UnaryExpectation) WithID ¶ added in v3.20.0
func (e *UnaryExpectation) WithID(id uuid.UUID) *UnaryExpectation