Documentation
¶
Index ¶
- func NewTestGRPCServer(t *testing.T, register func(s *grpc.Server), serverOpts ...grpc.ServerOption) *grpc.ClientConn
- func SampleAPIKey() map[string]any
- func SampleModelMetadata() map[string]any
- func SampleUser() map[string]any
- func SkipIfNoDocker(t *testing.T)
- func StartMinIO(t *testing.T) string
- func StartNATS(t *testing.T) string
- func StartPostgres(t *testing.T) string
- func StartRedis(t *testing.T) string
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 ¶
SampleAPIKey returns a test API key for gateway/auth tests.
func SampleModelMetadata ¶
SampleModelMetadata returns test model metadata for registry tests.
func SampleUser ¶
SampleUser returns a test user for authentication tests.
func SkipIfNoDocker ¶
SkipIfNoDocker skips the test if Docker daemon is not available. Integration tests require Docker for testcontainers.
func StartMinIO ¶
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 ¶
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 ¶
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 ¶
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.