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

Function NoChangeInStatusTest

server/topic_test.go:1271–1322  ·  view source on GitHub ↗
(t *testing.T, subscriptionStatus int, what string)

Source from the content-addressed store, hash-verified

1269)
1270
1271func NoChangeInStatusTest(t *testing.T, subscriptionStatus int, what string) *TopicTestHelper {
1272 t.Helper()
1273 topicName := "usrMe"
1274 numUsers := 1
1275 helper := &TopicTestHelper{}
1276 helper.setUp(t, numUsers, types.TopicCatMe, topicName, true)
1277
1278 uid := helper.uids[0]
1279 srcUid := types.Uid(10)
1280 helper.topic.perSubs = make(map[string]perSubsData)
1281 enabled := false
1282 switch subscriptionStatus {
1283 case NoSub:
1284 case ExistingSubEnabled:
1285 enabled = true
1286 fallthrough
1287 case ExistingSubDisabled:
1288 helper.topic.perSubs[srcUid.UserId()] = perSubsData{enabled: enabled, online: false}
1289 }
1290
1291 msg := &ServerComMessage{
1292 AsUser: uid.UserId(),
1293 RcptTo: uid.UserId(),
1294 Pres: &MsgServerPres{
1295 Topic: "me",
1296 Src: srcUid.UserId(),
1297 // No change in online status.
1298 What: what,
1299 },
1300 }
1301
1302 helper.topic.handleServerMsg(msg)
1303 helper.finish()
1304
1305 // Check for errors from testHubLoop
1306 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
1307 t.Fatal(errorMsgs[0].Ctrl.Text)
1308 }
1309
1310 // Topic metadata.
1311 if online := helper.topic.perSubs[srcUid.UserId()].online; online {
1312 t.Errorf("User %s is expected to be offline.", srcUid.UserId())
1313 }
1314 // Server messages.
1315 if len(helper.results[0].messages) != 0 {
1316 t.Fatalf("Session 0 is not expected to receive messages. Received %d.", len(helper.results[0].messages))
1317 }
1318 if len(helper.hubMessages) != 0 {
1319 t.Errorf("Hubhelper.route isn't expected to receive messages. Received %d", len(helper.hubMessages))
1320 }
1321 return helper
1322}
1323
1324func TestHandleBroadcastPresUnkn(t *testing.T) {
1325 NoChangeInStatusTest(t, ExistingSubEnabled, "?unkn").tearDown()

Calls 5

setUpMethod · 0.95
finishMethod · 0.95
UidTypeAlias · 0.92
UserIdMethod · 0.80
handleServerMsgMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…