testutil

package
v0.3.0-20260805154417-... Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySchema

func ApplySchema(t *testing.T, log *TestLogger, db *sql.DB, schemaDirectory string)

ApplySchema reads all .sql files from the schema directory and executes them on the database.

func Runfile

func Runfile(relativePath string) string

Runfile resolves a workspace-relative path (e.g. "service/submitqueue/docker-compose.yml") to an absolute path inside the Bazel runfiles tree. Every resolved path must be declared as a `data` dependency of the test target — that is what keeps Docker-based tests hermetic. Outside Bazel (plain `go test` from the repo root) the path is returned unchanged.

func SchemaDir

func SchemaDir(relativePath string) string

SchemaDir returns the path to a schema directory. It checks for both Bazel runfiles and direct go test paths. relativePath should be like "submitqueue/extension/storage/mysql/schema" or "platform/extension/messagequeue/mysql/schema"

Types

type ComposeOption

type ComposeOption func(*composeOptions)

ComposeOption customizes how a ComposeStack is created.

func WithBuildContext

func WithBuildContext(files map[string]string) ComposeOption

WithBuildContext stages the given files into a synthesized docker build context directory and points the compose build context variable (REPO_ROOT) at it. Keys are context-relative destination paths that must match the Dockerfile COPY sources and the compose `dockerfile:` path (e.g. ".docker-bin/gateway", "service/submitqueue/gateway/server/Dockerfile"); values are workspace-relative runfile paths, each of which must be declared as a `data` dependency of the test target. This keeps image builds hermetic: docker only ever sees files Bazel knows about, never the source checkout.

type ComposeStack

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

ComposeStack manages a docker-compose stack for testing.

func NewComposeStack

func NewComposeStack(t *testing.T, log *TestLogger, ctx context.Context, composeFile, testContext string, opts ...ComposeOption) *ComposeStack

NewComposeStack creates a new compose stack from the given docker-compose file. Automatically registers cleanup to tear down the stack. testContext should describe what's being tested (e.g., "gateway", "storage", "e2e-submitqueue").

func (*ComposeStack) ConnectGRPC

func (s *ComposeStack) ConnectGRPC(serviceName string, containerPort int) (*grpc.ClientConn, error)

ConnectGRPC creates a gRPC client connection to a service.

func (*ComposeStack) ConnectMySQLService

func (s *ComposeStack) ConnectMySQLService(serviceName string) (*sql.DB, error)

ConnectMySQLService connects to a MySQL service by name in the compose stack. Requires that Up() has been called first — the TCP-based healthcheck in docker-compose ensures MySQL is accepting TCP connections before Up() returns.

func (*ComposeStack) MySQLServiceDSN

func (s *ComposeStack) MySQLServiceDSN(serviceName string) (string, error)

MySQLServiceDSN returns the DSN string for a MySQL service. Useful when the implementation manages its own database connection.

func (*ComposeStack) ServiceExitCode

func (s *ComposeStack) ServiceExitCode(serviceName string) (int, error)

ServiceExitCode returns the exit code of a stopped service container. Must be called after the service has exited.

func (*ComposeStack) ServiceHost

func (s *ComposeStack) ServiceHost(serviceName string, containerPort int) (string, error)

ServiceHost returns the host:port address for a service.

func (*ComposeStack) ServicePort

func (s *ComposeStack) ServicePort(serviceName string, containerPort int) (int, error)

ServicePort returns the mapped host port for a service's container port.

func (*ComposeStack) StopService

func (s *ComposeStack) StopService(serviceName string, timeoutSec int) error

StopService sends SIGTERM to a service and waits for it to stop. timeoutSec is the maximum time to wait before Docker sends SIGKILL.

func (*ComposeStack) Up

func (s *ComposeStack) Up() error

Up starts all services in the compose stack. Uses --wait to block until all services with healthcheck directives are healthy.

type TestLogger

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

TestLogger is a simple test-aware logger that records elapsed time between logs.

func NewTestLogger

func NewTestLogger(t *testing.T) *TestLogger

NewTestLogger creates a TestLogger for the current test.

func (*TestLogger) Logf

func (l *TestLogger) Logf(format string, args ...any)

Logf prints a formatted log message with timestamp and elapsed time since last log.

Jump to

Keyboard shortcuts

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