testutils

package
v1.78.0-dev Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testutils contains testing helpers for xDS and LRS clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalAny

func MarshalAny(t *testing.T, m proto.Message) *anypb.Any

MarshalAny is a convenience function to marshal protobuf messages into any protos. function will fail the test with a fatal error if the marshaling fails.

Types

type Channel

type Channel struct {
	// C is the underlying channel on which values sent using the SendXxx()
	// methods are delivered. Tests which cannot use ReceiveXxx() for whatever
	// reasons can use C to read the values.
	C chan any
}

Channel wraps a generic channel and provides a timed receive operation.

func NewChannelWithSize

func NewChannelWithSize(bufSize int) *Channel

NewChannelWithSize returns a new Channel with a buffer of bufSize.

func (*Channel) Drain

func (c *Channel) Drain()

Drain drains the channel by repeatedly reading from it until it is empty.

func (*Channel) Receive

func (c *Channel) Receive(ctx context.Context) (any, error)

Receive returns the value received on the underlying channel, or the error returned by ctx if it is closed or cancelled.

func (*Channel) Replace

func (c *Channel) Replace(value any)

Replace clears the value on the underlying channel, and sends the new value.

It's expected to be used with a size-1 channel, to only keep the most up-to-date item. This method is inherently racy when invoked concurrently from multiple goroutines.

func (*Channel) Send

func (c *Channel) Send(value any)

Send sends value on the underlying channel.

func (*Channel) SendContext

func (c *Channel) SendContext(ctx context.Context, value any) error

SendContext sends value on the underlying channel, or returns an error if the context expires.

type ConnWrapper

type ConnWrapper struct {
	net.Conn
	CloseCh *Channel
}

ConnWrapper wraps a net.Conn and pushes on a channel when closed.

func (*ConnWrapper) Close

func (cw *ConnWrapper) Close() error

Close closes the connection and sends a value on the close channel.

type ListenerWrapper

type ListenerWrapper struct {
	net.Listener
	NewConnCh *Channel
}

ListenerWrapper wraps a net.Listener and the returned net.Conn.

It pushes on a channel whenever it accepts a new connection.

func NewListenerWrapper

func NewListenerWrapper(t *testing.T, lis net.Listener) *ListenerWrapper

NewListenerWrapper returns a ListenerWrapper.

func (*ListenerWrapper) Accept

func (l *ListenerWrapper) Accept() (net.Conn, error)

Accept wraps the Listener Accept and sends the accepted connection on a channel.

type RestartableListener

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

RestartableListener wraps a net.Listener and supports stopping and restarting the latter.

func NewRestartableListener

func NewRestartableListener(l net.Listener) *RestartableListener

NewRestartableListener returns a new RestartableListener wrapping l.

func (*RestartableListener) Accept

func (l *RestartableListener) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

If the listener is currently not accepting new connections, because `Stop` was called on it, the connection is immediately closed after accepting without any bytes being sent on it.

func (*RestartableListener) Addr

func (l *RestartableListener) Addr() net.Addr

Addr returns the listener's network address.

func (*RestartableListener) Close

func (l *RestartableListener) Close() error

Close closes the listener.

func (*RestartableListener) Restart

func (l *RestartableListener) Restart()

Restart gets a previously stopped listener to start accepting connections.

func (*RestartableListener) Stop

func (l *RestartableListener) Stop()

Stop closes existing connections on the listener and prevents new connections from being accepted.

Directories

Path Synopsis
Package e2e provides utilities for end2end testing of xDS and LRS clients functionalities.
Package e2e provides utilities for end2end testing of xDS and LRS clients functionalities.
Package fakeserver provides a fake implementation of the management server.
Package fakeserver provides a fake implementation of the management server.

Jump to

Keyboard shortcuts

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