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

Function TestHandleBroadcastDataGroup

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

Source from the content-addressed store, hash-verified

387}
388
389func TestHandleBroadcastDataGroup(t *testing.T) {
390 topicName := "grp-test"
391 numUsers := 4
392 helper := TopicTestHelper{}
393 helper.setUp(t, numUsers, types.TopicCatGrp, topicName, true)
394 defer func() {
395 store.Messages = nil
396 helper.tearDown()
397 }()
398 helper.mm.EXPECT().Save(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, true)
399
400 // User 3 isn't allowed to read.
401 pu3 := helper.topic.perUser[helper.uids[3]]
402 pu3.modeWant = types.ModeJoin | types.ModeWrite | types.ModePres
403 pu3.modeGiven = pu3.modeWant
404 helper.topic.perUser[helper.uids[3]] = pu3
405
406 from := helper.uids[0].UserId()
407 msg := &ClientComMessage{
408 AsUser: from,
409 Original: topicName,
410 Pub: &MsgClientPub{
411 Topic: topicName,
412 Content: "test",
413 NoEcho: true,
414 },
415 sess: helper.sessions[0],
416 }
417
418 if helper.topic.lastID != 0 {
419 t.Errorf("Topic.lastID: expected 0, found %d", helper.topic.lastID)
420 }
421 helper.topic.handleClientMsg(msg)
422 helper.finish()
423
424 // Check for errors from testHubLoop
425 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
426 t.Fatal(errorMsgs[0].Ctrl.Text)
427 }
428
429 if helper.topic.lastID != 1 {
430 t.Errorf("Topic.lastID: expected 1, found %d", helper.topic.lastID)
431 }
432 // Message uid0 -> uid1, uid2, uid3.
433 // Uid0 is the sender.
434 if len(helper.results[0].messages) != 0 {
435 t.Fatalf("Uid0 is the sender: expected 0 messages, got %d", len(helper.results[0].messages))
436 }
437 // Uid3 is not a topic reader.
438 if len(helper.results[3].messages) != 0 {
439 t.Fatalf("Uid3 isn't allowed to read messages: expected 0 messages, got %d", len(helper.results[3].messages))
440 }
441 for i := 1; i < 3; i++ {
442 m := helper.results[i]
443 if len(m.messages) != 1 {
444 t.Fatalf("Uid%d: expected 1 messages, got %d", i, len(m.messages))
445 }
446 r := m.messages[0].(*ServerComMessage)

Callers

nothing calls this directly

Calls 7

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
handleClientMsgMethod · 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…