-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels