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
- func CleanupMySQLDB(t *testing.T, db *sql.DB)
- func CleanupPostgresDB(t *testing.T, db *sql.DB)
- func CreateTestClient(t *testing.T, db *sql.DB, driver, name string) uuid.UUID
- func CreateTestClientAndKek(t *testing.T, db *sql.DB, driver, baseName string) (clientID, kekID uuid.UUID)
- func CreateTestKek(t *testing.T, db *sql.DB, driver, name string) uuid.UUID
- func SetupMySQLDB(t *testing.T) *sql.DB
- func SetupPostgresDB(t *testing.T) *sql.DB
- func TeardownDB(t *testing.T, db *sql.DB)
Constants ¶
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 ¶
CleanupMySQLDB truncates all tables in the MySQL database.
func CleanupPostgresDB ¶
CleanupPostgresDB truncates all tables in the PostgreSQL database.
func CreateTestClient ¶ added in v0.9.0
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
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 ¶
SetupMySQLDB creates a new MySQL database connection and runs migrations.
func SetupPostgresDB ¶
SetupPostgresDB creates a new PostgreSQL database connection and runs migrations.
Types ¶
This section is empty.