ping

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

README

Ping Service

This directory has an implementation of a grpc test service.

The service implements the following function:

func Ping(request *PingRequest) (*PingResponse, error)

The PingRequest structure is defined as follows:

type PingRequest struct {
        Error   int32  
	Message string
        Headers map[string]string
}

If the Error in the request is OK(0) the function returns a PingResponse with the same Message than the request. Otherwise, the function generates and error with the status defined in Error and the message defined in Message. The server will return the Headers defined in the request as part of the response's header metadata.

Build

If you modify the protobuf definition you must re-generate the grpc code.

Install the required toolchain:

go install google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc

From the root of this project, execute the following command

protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative pkg/testutils/grpc/ping/ping.proto 

Documentation

Overview

Package ping provides a grpc service for testing The service allows controlling the response returned by the server including the generation of specific errors.

Index

Constants

This section is empty.

Variables

View Source
var File_pkg_testutils_grpc_ping_ping_proto protoreflect.FileDescriptor
View Source
var PingService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "disruptor.testproto.PingService",
	HandlerType: (*PingServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Ping",
			Handler:    _PingService_Ping_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "pkg/testutils/grpc/ping/ping.proto",
}

PingService_ServiceDesc is the grpc.ServiceDesc for PingService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func CompareHeaders

func CompareHeaders(actual metadata.MD, expected map[string]string) bool

CompareHeaders compares the actual metadata with an expected map of headers. The actual header's values are expected as a comma-separated list of values (instead of a string array)

func CompareResponses

func CompareResponses(actual, expected *PingResponse) bool

CompareResponses returns a bool indicating if the actual and expected PingResponses are equal

func RegisterPingServiceServer

func RegisterPingServiceServer(s grpc.ServiceRegistrar, srv PingServiceServer)

Types

type PingRequest

type PingRequest struct {
	Error    int32             `protobuf:"varint,1,opt,name=error,proto3" json:"error,omitempty"`
	Message  string            `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	Headers  map[string]string `` /* 155-byte string literal not displayed */
	Trailers map[string]string `` /* 157-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*PingRequest) Descriptor deprecated

func (*PingRequest) Descriptor() ([]byte, []int)

Deprecated: Use PingRequest.ProtoReflect.Descriptor instead.

func (*PingRequest) GetError

func (x *PingRequest) GetError() int32

func (*PingRequest) GetHeaders

func (x *PingRequest) GetHeaders() map[string]string

func (*PingRequest) GetMessage

func (x *PingRequest) GetMessage() string

func (*PingRequest) GetTrailers

func (x *PingRequest) GetTrailers() map[string]string

func (*PingRequest) ProtoMessage

func (*PingRequest) ProtoMessage()

func (*PingRequest) ProtoReflect

func (x *PingRequest) ProtoReflect() protoreflect.Message

func (*PingRequest) Reset

func (x *PingRequest) Reset()

func (*PingRequest) String

func (x *PingRequest) String() string

type PingResponse

type PingResponse struct {
	Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

func (*PingResponse) Descriptor deprecated

func (*PingResponse) Descriptor() ([]byte, []int)

Deprecated: Use PingResponse.ProtoReflect.Descriptor instead.

func (*PingResponse) GetMessage

func (x *PingResponse) GetMessage() string

func (*PingResponse) ProtoMessage

func (*PingResponse) ProtoMessage()

func (*PingResponse) ProtoReflect

func (x *PingResponse) ProtoReflect() protoreflect.Message

func (*PingResponse) Reset

func (x *PingResponse) Reset()

func (*PingResponse) String

func (x *PingResponse) String() string

type PingServiceClient

type PingServiceClient interface {
	Ping(ctx context.Context, in *PingRequest, opts ...grpc.CallOption) (*PingResponse, error)
}

PingServiceClient is the client API for PingService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type PingServiceServer

type PingServiceServer interface {
	Ping(context.Context, *PingRequest) (*PingResponse, error)
	// contains filtered or unexported methods
}

PingServiceServer is the server API for PingService service. All implementations must embed UnimplementedPingServiceServer for forward compatibility

func NewPingServer

func NewPingServer() PingServiceServer

NewPingServer returns an instance of the default PingServiceServer

type UnimplementedPingServiceServer

type UnimplementedPingServiceServer struct {
}

UnimplementedPingServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedPingServiceServer) Ping

type UnsafePingServiceServer

type UnsafePingServiceServer interface {
	// contains filtered or unexported methods
}

UnsafePingServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to PingServiceServer will result in compilation errors.

Jump to

Keyboard shortcuts

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