feat: 完善后端脚手架基础能力
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package ws
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestHubRegisterBroadcastAndUnregister(t *testing.T) {
|
||||
hub := NewHub()
|
||||
client := &Client{hub: hub, room: "test", clientID: "one", send: make(chan OutgoingMessage, 1)}
|
||||
if online := hub.Register(client); online != 1 {
|
||||
t.Fatalf("Register() online = %d", online)
|
||||
}
|
||||
hub.Broadcast("test", OutgoingMessage{Type: EventMessage, Data: "hello"})
|
||||
message := <-client.send
|
||||
if message.Data != "hello" {
|
||||
t.Fatalf("Broadcast() data = %q", message.Data)
|
||||
}
|
||||
if online := hub.Unregister(client); online != 0 || hub.Count("test") != 0 {
|
||||
t.Fatalf("Unregister() online = %d", online)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user