testutil

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package testutil provides testing utilities for database integration tests.

Database Setup:

db := testutil.SetupPostgresDB(t)
defer testutil.TeardownDB(t, db)
defer testutil.CleanupPostgresDB(t, db)

Test Fixtures (for foreign key constraints):

clientID := testutil.CreateTestClient(t, db, "postgres", "my-test-client")
kekID := testutil.CreateTestKek(t, db, "postgres", "my-test-kek")

// Or both:
clientID, kekID := testutil.CreateTestClientAndKek(t, db, "postgres", "my-test")

Index

Constants

View Source
const (
	//nolint:gosec // test database credentials
	PostgresTestDSN = "postgres://testuser:testpassword@localhost:5433/testdb?sslmode=disable"
	//nolint:gosec // test database credentials
	MySQLTestDSN = "testuser:testpassword@tcp(localhost:3307)/testdb?parseTime=true&multiStatements=true"
)

Variables

This section is empty.

Functions

func CleanupMySQLDB

func CleanupMySQLDB(t *testing.T, db *sql.DB)

CleanupMySQLDB truncates all tables in the MySQL database.

func CleanupPostgresDB

func CleanupPostgresDB(t *testing.T, db *sql.DB)

CleanupPostgresDB truncates all tables in the PostgreSQL database.

func CreateTestClient added in v0.9.0

func CreateTestClient(t *testing.T, db *sql.DB, driver, name string) uuid.UUID

CreateTestClient creates a minimal active test client for repository tests. Returns the client ID for use in foreign key relationships. The client is created with a wildcard policy allowing all capabilities on all paths.

func CreateTestClientAndKek added in v0.9.0

func CreateTestClientAndKek(t *testing.T, db *sql.DB, driver, baseName string) (clientID, kekID uuid.UUID)

CreateTestClientAndKek creates both a test client and KEK, returning both IDs. Convenience wrapper for tests that need both fixtures.

func CreateTestKek added in v0.9.0

func CreateTestKek(t *testing.T, db *sql.DB, driver, name string) uuid.UUID

CreateTestKek creates a minimal test KEK for repository tests that need to reference a KEK (e.g., signed audit logs). Returns the KEK ID.

func SetupMySQLDB

func SetupMySQLDB(t *testing.T) *sql.DB

SetupMySQLDB creates a new MySQL database connection and runs migrations.

func SetupPostgresDB

func SetupPostgresDB(t *testing.T) *sql.DB

SetupPostgresDB creates a new PostgreSQL database connection and runs migrations.

func TeardownDB

func TeardownDB(t *testing.T, db *sql.DB)

TeardownDB closes the database connection and cleans up.

Types

This section is empty.

Jump to

Keyboard shortcuts

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