testutil

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package testutil provides testing utilities for database integration tests.

Environment Variables:

Database connection strings can be customized via environment variables:

  • TEST_POSTGRES_DSN: PostgreSQL connection string (default: postgres://testuser:testpassword@localhost:5433/testdb?sslmode=disable)

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

Migration Path:

Migrations are automatically discovered by walking up from the current working directory until a "migrations" directory is found.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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, 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, 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 CreateTestDek added in v0.22.0

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

CreateTestDek creates a minimal test DEK (Data Encryption Key) for repository tests. Returns the DEK ID. The DEK is associated with the provided KEK ID.

func CreateTestKek added in v0.9.0

func CreateTestKek(t *testing.T, db *sql.DB, 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. The KEK is created with algorithm 'aes-gcm' and random encrypted key data.

func GetPostgresTestDSN added in v0.22.0

func GetPostgresTestDSN() string

GetPostgresTestDSN returns the PostgreSQL test DSN, checking environment variable first.

func SetupPostgresDB

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

SetupPostgresDB creates a new PostgreSQL database connection and runs migrations.

func SkipIfNoPostgres added in v0.22.0

func SkipIfNoPostgres(t *testing.T)

SkipIfNoPostgres skips the test if PostgreSQL test database is not available. Useful for running tests in environments without database access.

func TeardownDB

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

TeardownDB closes the database connection and cleans up.

func ValidateTestClient added in v0.22.0

func ValidateTestClient(t *testing.T, db *sql.DB, clientID uuid.UUID) bool

ValidateTestClient verifies that a test client was created with expected values. Returns true if the client exists and is active, false if it does not exist. Fails the test if a database error occurs.

func ValidateTestDek added in v0.23.0

func ValidateTestDek(t *testing.T, db *sql.DB, dekID uuid.UUID) bool

ValidateTestDek verifies that a test DEK was created with expected values. Returns true if the DEK exists, false if it does not exist. Fails the test if a database error occurs.

func ValidateTestKek added in v0.22.0

func ValidateTestKek(t *testing.T, db *sql.DB, kekID uuid.UUID) bool

ValidateTestKek verifies that a test KEK was created with expected values. Returns true if the KEK exists, false if it does not exist. Fails the test if a database error occurs.

Types

This section is empty.

Jump to

Keyboard shortcuts

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