testutil

package
v0.1.0-dev8 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 FindRepoRoot

func FindRepoRoot(t *testing.T) string

FindRepoRoot finds the repository root. Checks REPO_ROOT env var, then git, then walks up to find marker files.

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 "extension/messagequeue/mysql/schema"

Types

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) *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