savinmax e4523df602
Some checks failed
CI / test (push) Successful in 1m10s
CI / lint (push) Successful in 30s
Release / release (push) Failing after 31s
Init
2025-08-02 18:33:50 +02:00

40 lines
662 B
Go

package hub
import (
"testing"
"time"
)
func TestNew(t *testing.T) {
h := New()
if h == nil {
t.Fatal("New returned nil")
}
if h.clients == nil {
t.Error("clients map not initialized")
}
if h.broadcast == nil {
t.Error("broadcast channel not initialized")
}
}
func TestClientCount(t *testing.T) {
h := New()
go h.Run()
if count := h.ClientCount(); count != 0 {
t.Errorf("Expected 0 clients, got %d", count)
}
}
func TestBroadcastChannel(t *testing.T) {
h := New()
go h.Run()
select {
case h.broadcast <- []byte("test"):
// Channel is working
case <-time.After(100 * time.Millisecond):
t.Error("broadcast channel blocked")
}
}