testing

package
v0.20.9 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package testing implements common grpc testing helpers.

Index

Constants

This section is empty.

Variables

View Source
var (

	// MethodPing is the Ping method.
	MethodPing = serviceName.NewMethod("Ping", PingQuery{}).
				WithNamespaceExtractor(func(ctx context.Context, req interface{}) (common.Namespace, error) {
			r, ok := req.(*PingQuery)
			if !ok {
				return common.Namespace{}, errInvalidRequestType
			}
			return r.Namespace, nil
		}).WithAccessControl(func(ctx context.Context, req interface{}) (bool, error) {
		return true, nil
	})

	// MethodWatchPings is the WatchPings method.
	MethodWatchPings = serviceName.NewMethod("WatchPings", PingQuery{}).
						WithNamespaceExtractor(func(ctx context.Context, req interface{}) (common.Namespace, error) {
			r, ok := req.(*PingQuery)
			if !ok {
				return common.Namespace{}, errInvalidRequestType
			}
			return r.Namespace, nil
		}).WithAccessControl(func(ctx context.Context, req interface{}) (bool, error) {
		return true, nil
	})
)
View Source
var ServiceDesc = grpc.ServiceDesc{
	ServiceName: string(serviceName),
	HandlerType: (*PingServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: MethodPing.ShortName(),
			Handler:    pingHandler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    MethodWatchPings.ShortName(),
			Handler:       watchPingsHandler,
			ServerStreams: true,
		},
	},
}

ServiceDesc is the PingService gRPC description.

Functions

func CreateCertificate

func CreateCertificate(t *testing.T) (*tls.Certificate, *x509.Certificate)

CreateCertificate creates gRPC TLS certificate for testing.

func RegisterService

func RegisterService(server *grpc.Server, service PingServer)

RegisterService registers a new ping server service with the given gRPC server.

Types

type PingClient

type PingClient interface {
	Ping(ctx context.Context, in *PingQuery, opts ...grpc.CallOption) (*PingResponse, error)
	WatchPings(ctx context.Context, in *PingQuery, opts ...grpc.CallOption) (<-chan *PingResponse, pubsub.ClosableSubscription, error)
	MissingMethod(ctx context.Context, in *PingQuery, opts ...grpc.CallOption) (*PingResponse, error)
}

PingClient is a testing PingServer client.

func NewPingClient

func NewPingClient(conn *grpc.ClientConn) PingClient

NewPingClient returns a new ping client.

type PingQuery

type PingQuery struct {
	common.Namespace
}

PingQuery is the PingServer query.

type PingResponse

type PingResponse struct {
}

PingResponse is the response of the PingServer.

type PingServer

type PingServer interface {
	Ping(context.Context, *PingQuery) (*PingResponse, error)
	WatchPings(context.Context, *PingQuery) (<-chan *PingResponse, pubsub.ClosableSubscription, error)
}

PingServer is a testing ping server interface.

func NewPingServer

func NewPingServer(authFunc func(ctx context.Context, fullMethodName string, req interface{}) error) PingServer

NewPingServer retruns a new Ping server.

Jump to

Keyboard shortcuts

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