mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-26 17:43:21 +01:00
refactor(channelserver): replace init() handler registration with explicit construction
The handler table was a package-level global populated by init(), making registration implicit and untestable. Move it to buildHandlerTable() which returns the map, store it as a Server struct field initialized in NewServer(), and add a missing-handler guard in handlePacketGroup to log a warning instead of panicking on unknown opcodes.
This commit is contained in:
@@ -168,7 +168,8 @@ func TestHandlerTableRegistered(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify handler table is populated
|
||||
if len(handlerTable) == 0 {
|
||||
table := buildHandlerTable()
|
||||
if len(table) == 0 {
|
||||
t.Error("handlers table should not be empty")
|
||||
}
|
||||
|
||||
@@ -181,8 +182,8 @@ func TestHandlerTableRegistered(t *testing.T) {
|
||||
_ = criticalHandlers // We just verify the table is non-empty since handler function names aren't directly accessible
|
||||
|
||||
// Verify minimum handler count
|
||||
if len(handlerTable) < 50 {
|
||||
t.Errorf("handlers count = %d, expected at least 50", len(handlerTable))
|
||||
if len(table) < 50 {
|
||||
t.Errorf("handlers count = %d, expected at least 50", len(table))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,8 +192,9 @@ func TestHandlerTableNilSession(t *testing.T) {
|
||||
// but doesn't call handlers (which would require a real session)
|
||||
_ = createMockServer()
|
||||
|
||||
table := buildHandlerTable()
|
||||
count := 0
|
||||
for range handlerTable {
|
||||
for range table {
|
||||
count++
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user