testutil

package
v0.0.0-...-f7ef4ee Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTestGRPCServer

func NewTestGRPCServer(t *testing.T, register func(s *grpc.Server), serverOpts ...grpc.ServerOption) *grpc.ClientConn

NewTestGRPCServer creates an in-process gRPC server using bufconn. The register function should register service handlers on the server. Returns a client connection ready to use with generated gRPC clients.

Both server and connection are automatically cleaned up when the test finishes.

Usage:

conn := testutil.NewTestGRPCServer(t, func(s *grpc.Server) {
    authv1.RegisterAuthServiceServer(s, myHandler)
})
client := authv1.NewAuthServiceClient(conn)
resp, err := client.Login(ctx, &authv1.LoginRequest{...})

Pass serverOpts to install the interceptor chain under test, e.g.:

conn := testutil.NewTestGRPCServer(t, register,
    grpc.ChainUnaryInterceptor(grpcutil.AuthUnaryInterceptor(validator)))

func SampleAPIKey

func SampleAPIKey() map[string]any

SampleAPIKey returns a test API key for gateway/auth tests.

func SampleModelMetadata

func SampleModelMetadata() map[string]any

SampleModelMetadata returns test model metadata for registry tests.

func SampleUser

func SampleUser() map[string]any

SampleUser returns a test user for authentication tests.

func SkipIfNoDocker

func SkipIfNoDocker(t *testing.T)

SkipIfNoDocker skips the test if Docker daemon is not available. Integration tests require Docker for testcontainers.

func StartMinIO

func StartMinIO(t *testing.T) string

StartMinIO spins up a real MinIO (S3-compatible) object store via testcontainers. Returns the endpoint URL (http://host:port).

Default credentials: minioadmin / minioadmin

Usage:

endpoint := testutil.StartMinIO(t)
client, err := minio.New(endpoint, &minio.Options{...})

func StartNATS

func StartNATS(t *testing.T) string

StartNATS spins up a real NATS server with JetStream enabled via testcontainers. Returns the NATS connection URL.

JetStream is enabled by default in the testcontainers NATS module (the module passes -DV -js flags automatically).

Usage:

url := testutil.StartNATS(t)
conn, js, err := natsutil.Connect(url)

func StartPostgres

func StartPostgres(t *testing.T) string

StartPostgres spins up a real PostgreSQL instance via testcontainers. Returns the DSN (connection string) ready for database/sql or pgx.

The container is automatically cleaned up when the test finishes. Each test gets its own Postgres instance — no shared state.

Usage:

dsn := testutil.StartPostgres(t)
db, err := sql.Open("pgx", dsn)

func StartRedis

func StartRedis(t *testing.T) string

StartRedis spins up a real Redis instance via testcontainers. Returns the address (host:port) ready for go-redis client.

Usage:

addr := testutil.StartRedis(t)
rdb := redis.NewClient(&redis.Options{Addr: addr})

Types

This section is empty.

Jump to

Keyboard shortcuts

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