grpc

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package grpc contains gRPC-specific implementations for itestkit.

Index

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

func NormalizeProtoMessage(msg proto.Message) (any, error)

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.

func (ErrorInspector) FromError

func (ErrorInspector) FromError(err error) (codes.Code, string, bool)

FromError retrieves the code and message from a runtime 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.

func (Registry[C]) Resolve

func (reg Registry[C]) Resolve(name string) (itestkit.Handler[C], error)

Resolve returns a handler by name.

func (Registry[C]) Supported

func (reg Registry[C]) Supported() []string

Supported returns a sorted list of supported handlers.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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