Skip to content

Testing: Missing tests for database manager and connection pool #11

@kusold

Description

@kusold

Description

The db/db.go package manages database connections, migrations, and RLS tenant context, but has no tests.

Untested Code

// db/db.go
func (m *Manager) Connect(ctx context.Context) error {
    // Connection pool setup
    // Schema creation
    // Multitenancy hooks
}

func (m *Manager) setupMultitenancy(cfg *pgxpool.Config) *pgxpool.Config {
    // BeforeAcquire: sets tenant context
    // AfterRelease: clears tenant context
}

func (m *Manager) RunMigrations(ctx context.Context) error {
    // Goose migration execution
}

Tests Needed

// db/db_test.go
func TestManager_Connect(t *testing.T) {
    // Successful connection
    // Invalid database URL
    // Schema creation when specified
}

func TestManager_RunMigrations(t *testing.T) {
    // Empty migration list → no error
    // Single migration source
    // Multiple migration sources
    // Failed migration → error
    // Idempotent migrations
}

func TestManager_MultitenancyHooks(t *testing.T) {
    // BeforeAcquire sets tenant context
    // BeforeAcquire skips system tenant
    // AfterRelease clears tenant context
}

func TestManager_AdminContext(t *testing.T) {
    // AdminContext sets system tenant
}

Test Infrastructure

Need test database:

func setupTestDB(t *testing.T) *Manager {
    t.Helper()
    // Use testcontainers or dockertest
    // Create ephemeral postgres
    // Return manager connected to it
}

Impact

  • Effort: Medium
  • Benefit: High (verify core database functionality)
  • Priority: Medium

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions