Documentation
¶
Overview ¶
Package grpc contains gRPC-specific implementations for itestkit.
Index ¶
- func DecodeProtoJSON(raw json.RawMessage, msg proto.Message) error
- func DecodeProtoJSONWithGoogleDateStrings(raw json.RawMessage, msg proto.Message) error
- func NormalizeProtoMessage(msg proto.Message) (any, error)
- func ServiceMethodNames(desc *grpc.ServiceDesc) []string
- func SupportedCodeNames() []string
- type ErrorInspector
- type HandlerSpec
- type Registry
- type StatusCodec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeProtoJSON ¶
func DecodeProtoJSON(raw json.RawMessage, msg proto.Message) error
DecodeProtoJSON decodes JSON into proto-message and disables unknown fields.
This is the basic decode path for gRPC helpers. For non-standard form fixture JSON it can be wrapped in a custom decode hook at the `HandlerSpec` level.
func DecodeProtoJSONWithGoogleDateStrings ¶
func DecodeProtoJSONWithGoogleDateStrings(raw json.RawMessage, msg proto.Message) error
DecodeProtoJSONWithGoogleDateStrings decodes fixture JSON into proto-message, where the `google.type.Date` fields can be specified with the string `YYYY-MM-DD`.
This is an opt-in helper for human-readable fixtures. It doesn't change behavior base `DecodeProtoJSON(...)` by default.
func NormalizeProtoMessage ¶
NormalizeProtoMessage converts the proto-message to DeepEqual-stable JSON.
This allows full proto responses to be used in asserts without `reflect.DeepEqual` hooks on the internal details of protobuf structures.
func ServiceMethodNames ¶
func ServiceMethodNames(desc *grpc.ServiceDesc) []string
ServiceMethodNames returns a sorted list of service methods.
func SupportedCodeNames ¶
func SupportedCodeNames() []string
SupportedCodeNames returns a list of supported assert.code field values.
Types ¶
type ErrorInspector ¶
type ErrorInspector struct{}
ErrorInspector extracts the code and message from a gRPC error.
type HandlerSpec ¶
type HandlerSpec[C any] struct { NewRequest func() proto.Message NewResponse func() proto.Message // DecodeRequestJSON allows you to override the standard proto decode for request. // // This is necessary for fixture formats that require preliminary preparation of JSON // before `protojson.Unmarshal`, but want to keep the common handler scaffold. DecodeRequestJSON func(json.RawMessage, proto.Message) error // DecodeExpectedResponseJSON allows you to override the decode of the expected proto-response. DecodeExpectedResponseJSON func(json.RawMessage, proto.Message) error Invoke func(context.Context, C, proto.Message) (proto.Message, error) NormalizeResponse func(proto.Message) (any, error) }
HandlerSpec describes the handler spec contract for gRPC integration.
func NewHandlerSpec ¶
func NewHandlerSpec[Req proto.Message, Resp proto.Message, C any]( handlerName string, newRequest func() Req, newResponse func() Resp, invoke func(context.Context, C, Req) (Resp, error), normalize func(Resp) (any, error), ) HandlerSpec[C]
NewHandlerSpec creates a type-safe handler spec.
type Registry ¶
type Registry[C any] struct { // contains filtered or unexported fields }
Registry stores a set of gRPC specs and implements itestkit.HandlerRegistry.
func NewRegistry ¶
func NewRegistry[C any](specs map[string]HandlerSpec[C]) Registry[C]
NewRegistry creates a registry handler spec for gRPC integration.
type StatusCodec ¶
type StatusCodec struct{}
StatusCodec implements a gRPC status code parser for itestkit.
func (StatusCodec) Parse ¶
func (StatusCodec) Parse(raw string) (codes.Code, error)
Parse converts the string status code to codes.Code.
func (StatusCodec) Success ¶
func (StatusCodec) Success() codes.Code
Success returns the success code.