forked from keroserene/go-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ice_test.go
52 lines (45 loc) · 1.41 KB
/
ice_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package webrtc
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestIceCandidate(t *testing.T) {
Convey("IceCandidate", t, func() {
SetLoggingVerbosity(0)
Convey("Serialize and Deserialize", func() {
ice := IceCandidate{
"fake",
"not real",
1337,
}
expected := `{"candidate":"fake","sdpMid":"not real","sdpMLineIndex":1337}`
So(ice.Serialize(), ShouldEqual, expected)
r := DeserializeIceCandidate(`{"candidate":"still fake","sdpMid":"illusory","sdpMLineIndex":1337}`)
So(r, ShouldNotBeNil)
So(r.Candidate, ShouldEqual, "still fake")
So(r.SdpMid, ShouldEqual, "illusory")
So(r.SdpMLineIndex, ShouldEqual, 1337)
r = DeserializeIceCandidate(`not valid {{{`)
So(r, ShouldBeNil)
// Missing fields should result in errors.
r = DeserializeIceCandidate(`{"sdpMid":"foo","sdpMLineIndex":1234}`)
So(r, ShouldBeNil)
r = DeserializeIceCandidate(`{"candidate":"something","sdpMLineIndex":1234}`)
So(r, ShouldBeNil)
r = DeserializeIceCandidate(`{"candidate":"something","sdpMid":"bar"}`)
So(r, ShouldBeNil)
Convey("Roundtrip", func() {
ice := IceCandidate{
"totally fake",
"fabricated",
1337,
}
r := DeserializeIceCandidate(ice.Serialize())
So(r, ShouldNotBeNil)
So(r.Candidate, ShouldEqual, ice.Candidate)
So(r.SdpMid, ShouldEqual, ice.SdpMid)
So(r.SdpMLineIndex, ShouldEqual, ice.SdpMLineIndex)
})
})
})
}