progress with a bit of tests
This commit is contained in:
+13
-12
@@ -1,7 +1,6 @@
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
@@ -15,29 +14,31 @@ func TestRoomJoin(t *testing.T) {
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
t.Run("joining returns existing participant data", func(t *testing.T) {
|
||||
rm := newRoomWithParticipants(t, mockCtrl, 3)
|
||||
numExisting := 3
|
||||
rm := newRoomWithParticipants(mockCtrl, numExisting)
|
||||
assert.NotNil(t, rm)
|
||||
pc := newMockPeerConnection(mockCtrl)
|
||||
sc := NewMockSignalConnection(mockCtrl)
|
||||
p, err := NewParticipant(pc, sc, "newparticipant")
|
||||
assert.NoError(t, err)
|
||||
p := newMockParticipant(mockCtrl)
|
||||
assert.NotNil(t, p)
|
||||
|
||||
// expect new participant to get a JoinReply
|
||||
p.EXPECT().SendJoinResponse(gomock.Any()).Return(nil).Do(
|
||||
func(otherParticipants []Participant) {
|
||||
assert.Len(t, otherParticipants, numExisting)
|
||||
})
|
||||
|
||||
rm.Join(p)
|
||||
|
||||
assert.Len(t, rm.participants, numExisting+1)
|
||||
})
|
||||
}
|
||||
|
||||
func newRoomWithParticipants(t *testing.T, mockCtrl *gomock.Controller, num int) *Room {
|
||||
func newRoomWithParticipants(mockCtrl *gomock.Controller, num int) *Room {
|
||||
rm, err := NewRoomForRequest(&livekit.CreateRoomRequest{}, &WebRTCConfig{})
|
||||
if err != nil {
|
||||
panic("could not create a room")
|
||||
}
|
||||
for i := 0; i < num; i++ {
|
||||
pc := newMockPeerConnection(mockCtrl)
|
||||
participant, err := NewParticipant(pc,
|
||||
NewMockSignalConnection(mockCtrl),
|
||||
fmt.Sprintf("p%d", i))
|
||||
assert.NoError(t, err, "could not create participant for room")
|
||||
participant := newMockParticipant(mockCtrl)
|
||||
rm.participants[participant.ID()] = participant
|
||||
}
|
||||
return rm
|
||||
|
||||
Reference in New Issue
Block a user