(t *testing.T, numUsers int, cat types.TopicCat, topicName string, attachSessions bool)
| 80 | } |
| 81 | |
| 82 | func (b *TopicTestHelper) setUp(t *testing.T, numUsers int, cat types.TopicCat, topicName string, attachSessions bool) { |
| 83 | t.Helper() |
| 84 | b.numUsers = numUsers |
| 85 | b.uids = make([]types.Uid, numUsers) |
| 86 | for i := range numUsers { |
| 87 | // Can't use 0 as a valid uid. |
| 88 | b.uids[i] = types.Uid(i + 1) |
| 89 | } |
| 90 | |
| 91 | // Mocks. |
| 92 | b.ctrl = gomock.NewController(t) |
| 93 | b.mm = mock_store.NewMockMessagesPersistenceInterface(b.ctrl) |
| 94 | b.uu = mock_store.NewMockUsersPersistenceInterface(b.ctrl) |
| 95 | b.tt = mock_store.NewMockTopicsPersistenceInterface(b.ctrl) |
| 96 | b.ss = mock_store.NewMockSubsPersistenceInterface(b.ctrl) |
| 97 | store.Messages = b.mm |
| 98 | store.Users = b.uu |
| 99 | store.Topics = b.tt |
| 100 | store.Subs = b.ss |
| 101 | // Sessions. |
| 102 | b.sessions = make([]*Session, b.numUsers) |
| 103 | b.results = make([]*responses, b.numUsers) |
| 104 | b.sessWg = &sync.WaitGroup{} |
| 105 | for i := range b.sessions { |
| 106 | s, r := b.newSession(fmt.Sprintf("sid%d", i), b.uids[i]) |
| 107 | b.results[i] = r |
| 108 | b.sessions[i] = s |
| 109 | } |
| 110 | |
| 111 | // Hub. |
| 112 | b.hub = &Hub{ |
| 113 | routeCli: make(chan *ClientComMessage, 10), |
| 114 | routeSrv: make(chan *ServerComMessage, 10), |
| 115 | } |
| 116 | globals.hub = b.hub |
| 117 | b.hubMessages = make(map[string][]*ServerComMessage) |
| 118 | b.hubDone = make(chan bool) |
| 119 | go b.hub.testHubLoop(t, b.hubMessages, b.hubDone) |
| 120 | |
| 121 | // Topic. |
| 122 | pu := make(map[types.Uid]perUserData) |
| 123 | ps := make(map[*Session]perSessionData) |
| 124 | for i, uid := range b.uids { |
| 125 | puData := perUserData{ |
| 126 | modeWant: types.ModeCFull, |
| 127 | modeGiven: types.ModeCFull, |
| 128 | } |
| 129 | if cat == types.TopicCatP2P { |
| 130 | puData.topicName = b.uids[i^1].UserId() |
| 131 | } |
| 132 | if attachSessions { |
| 133 | ps[b.sessions[i]] = perSessionData{uid: uid} |
| 134 | puData.online = 1 |
| 135 | } |
| 136 | pu[uid] = puData |
| 137 | } |
| 138 | b.topic = &Topic{ |
| 139 | name: topicName, |
no test coverage detected