testutils

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: LGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServerStartTimeout indicates the NATS server failed to start within the timeout period.
	ErrServerStartTimeout = eris.New("NATS server failed to start within timeout")
	// ErrPublishTimeout indicates a publish operation timed out.
	ErrPublishTimeout = eris.New("publish operation timed out")
	// ErrSubscriberTimeout indicates waiting for subscribers timed out.
	ErrSubscriberTimeout = eris.New("timeout waiting for subscribers")
)

Functions

This section is empty.

Types

type NATS

type NATS struct {
	Server *server.Server
	Client *nats.Conn
	// contains filtered or unexported fields
}

NATS represents a test NATS server with its client.

func NewNATS

func NewNATS(t *testing.T) *NATS

NewNATS creates a new NATS test server with a connected client. It automatically registers cleanup with t.Cleanup().

func (*NATS) Publish

func (n *NATS) Publish(subject string, data []byte) error

Publish publishes a message to a subject. Returns an error if the publish operation fails.

func (*NATS) PublishWithReply

func (n *NATS) PublishWithReply(subject string, data []byte, timeout time.Duration) ([]byte, error)

PublishWithReply publishes a message to a subject and waits for a reply. Returns the reply data and any error that occurred.

func (*NATS) QueueSubscribeSync

func (n *NATS) QueueSubscribeSync(subject, queue string) *nats.Subscription

QueueSubscribeSync creates a synchronous queue subscription and returns it. The subscription is automatically cleaned up when the test ends.

func (*NATS) Shutdown

func (n *NATS) Shutdown()

Shutdown gracefully shuts down the NATS test server and client.

func (*NATS) SubscribeSync

func (n *NATS) SubscribeSync(subject string) *nats.Subscription

SubscribeSync creates a synchronous subscription and returns it. The subscription is automatically cleaned up when the test ends.

func (*NATS) WaitForMessage

func (n *NATS) WaitForMessage(sub *nats.Subscription, timeout time.Duration) *nats.Msg

WaitForMessage waits for a message on the given subscription. Returns the received message or fails the test if timeout is reached.

func (*NATS) WaitForSubscribers

func (n *NATS) WaitForSubscribers(numSubscribers int, timeout time.Duration) bool

WaitForSubscribers waits for the specified number of subscribers on a subject. Returns true if the expected number of subscribers is reached within the timeout.

Jump to

Keyboard shortcuts

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