progress with a bit of tests

This commit is contained in:
David Zhao
2020-12-21 23:23:57 -08:00
parent 2a79bdb678
commit ed472c8569
3 changed files with 36 additions and 13 deletions
+23
View File
@@ -2,6 +2,9 @@ package rtc
import (
"github.com/golang/mock/gomock"
"github.com/livekit/livekit-server/pkg/utils"
"github.com/livekit/livekit-server/proto/livekit"
)
func newMockPeerConnection(mockCtrl *gomock.Controller) *MockPeerConnection {
@@ -13,3 +16,23 @@ func newMockPeerConnection(mockCtrl *gomock.Controller) *MockPeerConnection {
pc.EXPECT().OnTrack(gomock.Any()).AnyTimes()
return pc
}
func newMockSignalConnection(mockCtrl *gomock.Controller) *MockSignalConnection {
sc := NewMockSignalConnection(mockCtrl)
return sc
}
func newMockParticipant(mockCtrl *gomock.Controller) *MockParticipant {
p := NewMockParticipant(mockCtrl)
p.EXPECT().ID().Return(utils.NewGuid(utils.ParticipantPrefix)).AnyTimes()
p.EXPECT().Name().Return("tester").AnyTimes()
p.EXPECT().State().Return(livekit.ParticipantInfo_JOINED).AnyTimes()
// default callbacks
p.EXPECT().OnICECandidate(gomock.Any()).AnyTimes()
p.EXPECT().OnClose(gomock.Any()).AnyTimes()
p.EXPECT().OnOffer(gomock.Any()).AnyTimes()
p.EXPECT().OnStateChange(gomock.Any()).AnyTimes()
p.EXPECT().OnTrackPublished(gomock.Any()).AnyTimes()
return p
}
-1
View File
@@ -1 +0,0 @@
package rtc
+13 -12
View File
@@ -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