MCPcopy
hub / github.com/tinode/chat / TestHandleBroadcastCall

Function TestHandleBroadcastCall

server/topic_test.go:279–387  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

277}
278
279func TestHandleBroadcastCall(t *testing.T) {
280 numUsers := 2
281 helper := TopicTestHelper{}
282 helper.setUp(t, numUsers, types.TopicCatP2P, "p2p-test" /*attach=*/, true)
283 globals.iceServers = []iceServer{{Username: "dummy"}}
284 helper.topic.lastID = 5
285 defer helper.tearDown()
286 helper.mm.EXPECT().Save(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, true)
287
288 from := helper.uids[0].UserId()
289 msg := &ClientComMessage{
290 AsUser: from,
291 Original: from,
292 Pub: &MsgClientPub{
293 Topic: "p2p",
294 Head: map[string]any{"webrtc": "started"},
295 Content: "test",
296 NoEcho: true,
297 },
298 sess: helper.sessions[0],
299 }
300 helper.topic.handleClientMsg(msg)
301 helper.finish()
302
303 // Check for errors from testHubLoop
304 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
305 t.Fatal(errorMsgs[0].Ctrl.Text)
306 }
307
308 globals.iceServers = nil
309
310 // Message uid1 -> uid2.
311 for i, m := range helper.results {
312 if i == 0 {
313 if len(m.messages) != 0 {
314 t.Fatalf("Uid1: expected 0 messages, got %d", len(m.messages))
315 }
316 } else {
317 if len(m.messages) != 1 {
318 t.Fatalf("Uid2: expected 1 messages, got %d", len(m.messages))
319 }
320 r := m.messages[0].(*ServerComMessage)
321 if r.Data == nil {
322 t.Fatalf("Response[0] must have a ctrl message")
323 }
324 if r.Data.Topic != from {
325 t.Errorf("Response[0] topic: expected '%s', got '%s'", from, r.Data.Topic)
326 }
327 if r.Data.Content.(string) != "test" {
328 t.Errorf("Response[0] content: expected 'test', got '%s'", r.Data.Content.(string))
329 }
330 if r.Data.Head == nil || r.Data.Head["webrtc"].(string) != "started" {
331 t.Errorf("Response[0] head: expected {'webrtc': 'started'}', got '%s'", r.Data.Content.(string))
332 }
333 if r.Data.From != from {
334 t.Errorf("Response[0] from: expected '%s', got '%s'", from, r.Data.From)
335 }
336 }

Callers

nothing calls this directly

Calls 8

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
handleClientMsgMethod · 0.80
ErrorMethod · 0.80
SaveMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…