diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2026-03-16 11:46:04 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2026-03-16 11:46:04 -0700 |
| commit | 2f46f87177234070044b5304ca3e0db471699ad8 (patch) | |
| tree | 6dc72ce596e95850a587001a85b3f45e394b0e34 /hotline/client_manager_test.go | |
| parent | 92f4b7af1073b6cdd0786ce2090d6e446e0903ad (diff) | |
Improve test coverage for hotline and internal/mobius packages
Add comprehensive test cases across both packages to increase coverage:
- hotline: 52.4% → ~55% (Disconnect, handleTransaction, SendAll,
sendBanMessage, MemClientMgr, and other tests)
- internal/mobius: 75.9% → ~80% (HandleUpdateUser, HandleDeleteUser,
HandleSetUser, HandleNewUser, HandleUserBroadcast success paths)
Diffstat (limited to 'hotline/client_manager_test.go')
| -rw-r--r-- | hotline/client_manager_test.go | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/hotline/client_manager_test.go b/hotline/client_manager_test.go new file mode 100644 index 0000000..a2a0320 --- /dev/null +++ b/hotline/client_manager_test.go @@ -0,0 +1,62 @@ +package hotline + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestMemClientMgr_Add(t *testing.T) { + mgr := NewMemClientMgr() + + c1 := &ClientConn{} + c2 := &ClientConn{} + mgr.Add(c1) + mgr.Add(c2) + + assert.NotEqual(t, c1.ID, c2.ID) + assert.Len(t, mgr.List(), 2) +} + +func TestMemClientMgr_Get(t *testing.T) { + mgr := NewMemClientMgr() + + assert.Nil(t, mgr.Get(ClientID{0xFF, 0xFF})) + + c := &ClientConn{} + mgr.Add(c) + assert.Equal(t, c, mgr.Get(c.ID)) +} + +func TestMemClientMgr_Delete(t *testing.T) { + mgr := NewMemClientMgr() + + c := &ClientConn{} + mgr.Add(c) + id := c.ID + + mgr.Delete(id) + assert.Nil(t, mgr.Get(id)) +} + +func TestMemClientMgr_List_Sorted(t *testing.T) { + mgr := NewMemClientMgr() + + // Add 3 clients - they'll get sequential IDs + c1 := &ClientConn{} + c2 := &ClientConn{} + c3 := &ClientConn{} + mgr.Add(c1) + mgr.Add(c2) + mgr.Add(c3) + + list := mgr.List() + assert.Len(t, list, 3) + + // Verify sorted by ID + for i := 1; i < len(list); i++ { + assert.True(t, list[i-1].ID[0] < list[i].ID[0] || + (list[i-1].ID[0] == list[i].ID[0] && list[i-1].ID[1] <= list[i].ID[1]), + "clients should be sorted by ID") + } +} |