testutil

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMySQLContainer

func NewMySQLContainer(t *testing.T, serviceName string, schemaFiles ...string) *sql.DB

NewMySQLContainer starts a named MariaDB container for the given service, applies the given schema files, and returns a *sql.DB connection.

The container is named "osdbe-test-<serviceName>" so it's easy to identify via `docker ps`. The container is cleaned up automatically when the test ends.

func RunCollectorTests

func RunCollectorTests[T prometheus.Collector](t *testing.T, tests []CollectorTestCase, newCollector CollectorFactory[T])

func SeedSQL

func SeedSQL(t *testing.T, db *sql.DB, statements ...string)

SeedSQL executes raw SQL statements against the database. Multiple statements can be separated by semicolons.

func SkipIfNoDocker

func SkipIfNoDocker(t *testing.T)

SkipIfNoDocker skips the test if Docker is not available.

Types

type CollectorFactory

type CollectorFactory[T prometheus.Collector] func(*sql.DB, *slog.Logger) T

type CollectorTestCase

type CollectorTestCase struct {
	Name            string
	SetupMock       func(sqlmock.Sqlmock)
	ExpectedMetrics string
	ExpectError     bool
}

type MySQLContainerResult

type MySQLContainerResult struct {
	DB  *sql.DB
	URL string // oslo.db format, e.g. mysql+pymysql://test:test@host:port/testdb
	// contains filtered or unexported fields
}

MySQLContainerResult holds a database connection and oslo.db-format URL returned by NewMySQLContainerWithURL.

func NewMySQLContainerWithURL

func NewMySQLContainerWithURL(t *testing.T, serviceName string, schemaFiles ...string) MySQLContainerResult

NewMySQLContainerWithURL is like NewMySQLContainer but also returns an oslo.db-format connection URL suitable for passing to collector.Config.

func (MySQLContainerResult) Terminate

func (r MySQLContainerResult) Terminate(ctx context.Context) error

Terminate stops and removes the underlying MariaDB container. This is useful for testing resilience when a database becomes unavailable.

Jump to

Keyboard shortcuts

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