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