natstest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package natstest provides an embedded NATS server fixture for tests.

Future hold/coord tests consume this instead of requiring an external NATS server. The fixture binds to a random loopback port so parallel tests do not collide, and teardown is idempotent.

Usage:

func TestSomething(t *testing.T) {
    nc, cleanup := natstest.NewTestServer(t)
    defer cleanup()
    // nc is a connected *nats.Conn on a random port.
}

The default fixture runs without JetStream. Tests that need the KV substrate (holds/coord) should call NewJetStreamServer instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJetStreamServer

func NewJetStreamServer(t *testing.T) (*nats.Conn, func())

NewJetStreamServer starts an in-process nats-server with JetStream enabled, storing state in a temporary directory that is removed when cleanup runs. Use this for tests that exercise JetStream KV.

The returned cleanup is the single teardown point for connection, server, and store directory. Calling it more than once is a no-op.

func NewTestServer

func NewTestServer(t *testing.T) (*nats.Conn, func())

NewTestServer starts an in-process nats-server on a random loopback port and returns a client connection plus a cleanup func. The cleanup is also registered via t.Cleanup, so `defer cleanup()` is optional. Calling cleanup more than once is a no-op.

On any setup failure, NewTestServer calls t.Fatalf and does not return.

Types

This section is empty.

Jump to

Keyboard shortcuts

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