testutils

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(tb testing.TB) context.Context

func ContextWithTimeout

func ContextWithTimeout(tb testing.TB, timeout time.Duration) context.Context

func MustMarshal

func MustMarshal[T proto.Message](t testingT, r *ads.Resource[T]) *ads.RawResource

func ProtoEquals

func ProtoEquals(t testingT, expected, actual proto.Message)

func ResourceEquals

func ResourceEquals[T proto.Message](t testingT, expected, actual *ads.Resource[T])

func WithTimeout

func WithTimeout(t *testing.T, name string, timeout time.Duration, f func(t *testing.T))

Types

type ChanSubscriptionHandler

type ChanSubscriptionHandler[T proto.Message] chan Notification[T]

func (ChanSubscriptionHandler[T]) Notify

func (c ChanSubscriptionHandler[T]) Notify(name string, r *ads.Resource[T], metadata ads.SubscriptionMetadata)

func (ChanSubscriptionHandler[T]) WaitForDelete

func (c ChanSubscriptionHandler[T]) WaitForDelete(
	t testingT,
	expectedName string,
) Notification[T]

func (ChanSubscriptionHandler[T]) WaitForNotifications

func (c ChanSubscriptionHandler[T]) WaitForNotifications(t testingT, notifications ...ExpectedNotification[T]) (out []Notification[T])

func (ChanSubscriptionHandler[T]) WaitForUpdate

func (c ChanSubscriptionHandler[T]) WaitForUpdate(t testingT, r *ads.Resource[T]) Notification[T]

type ExpectedNotification

type ExpectedNotification[T proto.Message] struct {
	Name     string
	Resource *ads.Resource[T]
}

func ExpectDelete

func ExpectDelete[T proto.Message](name string) ExpectedNotification[T]

func ExpectUpdate

func ExpectUpdate[T proto.Message](r *ads.Resource[T]) ExpectedNotification[T]

type FuncHandler

type FuncHandler[T proto.Message] struct {
	// contains filtered or unexported fields
}

FuncHandler is a SubscriptionHandler implementation that simply invokes a function. Note that the usual pattern of having a literal func type implement the interface (e.g. http.HandlerFunc) does not work in this case because funcs are not hashable and therefore cannot be used as map keys, which is often how SubscriptionHandlers are used.

func NewSubscriptionHandler

func NewSubscriptionHandler[T proto.Message](
	notify func(name string, r *ads.Resource[T], metadata ads.SubscriptionMetadata),
) *FuncHandler[T]

NewSubscriptionHandler returns a SubscriptionHandler that invokes the given function when SubscriptionHandler.Notify is invoked.

func (*FuncHandler[T]) Notify

func (f *FuncHandler[T]) Notify(name string, r *ads.Resource[T], metadata ads.SubscriptionMetadata)

type Notification

type Notification[T proto.Message] struct {
	Name     string
	Resource *ads.Resource[T]
	Metadata ads.SubscriptionMetadata
}

type RawFuncHandler

type RawFuncHandler struct {
	// contains filtered or unexported fields
}

func NewRawSubscriptionHandler

func NewRawSubscriptionHandler(
	t testingT,
	notify func(name string, r *ads.RawResource, metadata ads.SubscriptionMetadata),
) *RawFuncHandler

NewRawSubscriptionHandler returns a RawSubscriptionHandler that invokes the given function when SubscriptionHandler.Notify is invoked.

func (*RawFuncHandler) Notify

func (r *RawFuncHandler) Notify(name string, raw *ads.RawResource, metadata ads.SubscriptionMetadata)

func (*RawFuncHandler) ResourceMarshalError

func (r *RawFuncHandler) ResourceMarshalError(name string, resource proto.Message, err error)

type TestServer

type TestServer struct {
	*grpc.Server
	net.Listener
	// contains filtered or unexported fields
}

TestServer is instantiated with NewTestGRPCServer and serves to facilitate local testing against gRPC service implementations.

func NewTestGRPCServer

func NewTestGRPCServer(t *testing.T, opts ...grpc.ServerOption) *TestServer

NewTestGRPCServer is a utility function that spins up a TCP listener on a random local port along with a grpc.Server. It cleans up any associated state using the Cleanup methods. Sample usage is as follows:

ts := NewTestGRPCServer(t)
discovery.RegisterAggregatedDiscoveryServiceServer(ts.Server, s)
ts.Start()
conn := ts.Dial()

func (*TestServer) AddrString

func (ts *TestServer) AddrString() string

func (*TestServer) Dial

func (ts *TestServer) Dial(opts ...grpc.DialOption) *grpc.ClientConn

Dial invokes DialContext with the given options and a context generated using Context.

func (*TestServer) Start

func (ts *TestServer) Start()

Start starts the backing gRPC server in a goroutine. Must be invoked _after_ registering the services.

Jump to

Keyboard shortcuts

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