package persistence import ( "testing" "time" ) func TestDefaultDBConfig(t *testing.T) { config := DefaultDBConfig("postgres", "test-dsn") if config.DriverName != "postgres" { t.Errorf("expected DriverName to be 'postgres', got %s", config.DriverName) } if config.DSN != "test-dsn" { t.Errorf("expected DSN to be 'test-dsn', got %s", config.DSN) } if config.MaxOpenConns != 25 { t.Errorf("expected MaxOpenConns to be 25, got %d", config.MaxOpenConns) } if config.MaxIdleConns != 5 { t.Errorf("expected MaxIdleConns to be 5, got %d", config.MaxIdleConns) } if config.ConnMaxLifetime != time.Hour { t.Errorf("expected ConnMaxLifetime to be 1 hour, got %v", config.ConnMaxLifetime) } if config.ConnMaxIdleTime != 10*time.Minute { t.Errorf("expected ConnMaxIdleTime to be 10 minutes, got %v", config.ConnMaxIdleTime) } } func TestDBConfig_CustomValues(t *testing.T) { config := DBConfig{ DriverName: "mysql", DSN: "user:pass@tcp(localhost:3306)/dbname", MaxOpenConns: 50, MaxIdleConns: 10, ConnMaxLifetime: 2 * time.Hour, ConnMaxIdleTime: 20 * time.Minute, } if config.DriverName != "mysql" { t.Errorf("expected DriverName to be 'mysql', got %s", config.DriverName) } if config.MaxOpenConns != 50 { t.Errorf("expected MaxOpenConns to be 50, got %d", config.MaxOpenConns) } }