mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Add tests for session descripion functions
Also removed some unnecessary code
This commit is contained in:
parent
3ec2e8b89e
commit
32bec89a84
2 changed files with 82 additions and 4 deletions
|
@ -4,6 +4,9 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pion/webrtc"
|
||||||
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRemoteIPFromSDP(t *testing.T) {
|
func TestRemoteIPFromSDP(t *testing.T) {
|
||||||
|
@ -107,3 +110,82 @@ a=sctpmap:5000 webrtc-datachannel 1024
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSessionDescriptions(t *testing.T) {
|
||||||
|
Convey("Session description deserialization", t, func() {
|
||||||
|
for _, test := range []struct {
|
||||||
|
msg string
|
||||||
|
ret *webrtc.SessionDescription
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"test",
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`{"type":"answer"}`,
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`{"sdp":"test"}`,
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`{"type":"test", "sdp":"test"}`,
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`{"type":"answer", "sdp":"test"}`,
|
||||||
|
&webrtc.SessionDescription{
|
||||||
|
Type: webrtc.SDPTypeAnswer,
|
||||||
|
SDP: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`{"type":"pranswer", "sdp":"test"}`,
|
||||||
|
&webrtc.SessionDescription{
|
||||||
|
Type: webrtc.SDPTypePranswer,
|
||||||
|
SDP: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`{"type":"rollback", "sdp":"test"}`,
|
||||||
|
&webrtc.SessionDescription{
|
||||||
|
Type: webrtc.SDPTypeRollback,
|
||||||
|
SDP: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`{"type":"offer", "sdp":"test"}`,
|
||||||
|
&webrtc.SessionDescription{
|
||||||
|
Type: webrtc.SDPTypeOffer,
|
||||||
|
SDP: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
desc := deserializeSessionDescription(test.msg)
|
||||||
|
So(desc, ShouldResemble, test.ret)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Convey("Session description serialization", t, func() {
|
||||||
|
for _, test := range []struct {
|
||||||
|
desc *webrtc.SessionDescription
|
||||||
|
ret string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
&webrtc.SessionDescription{
|
||||||
|
Type: webrtc.SDPTypeOffer,
|
||||||
|
SDP: "test",
|
||||||
|
},
|
||||||
|
`{"type":"offer","sdp":"test"}`,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
msg := serializeSessionDescription(test.desc)
|
||||||
|
So(msg, ShouldResemble, test.ret)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUtilityFuncs(t *testing.T) {
|
||||||
|
Convey("LimitedRead", t, func() {
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -493,10 +493,6 @@ func deserializeSessionDescription(msg string) *webrtc.SessionDescription {
|
||||||
stype = webrtc.SDPTypeRollback
|
stype = webrtc.SDPTypeRollback
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &webrtc.SessionDescription{
|
return &webrtc.SessionDescription{
|
||||||
Type: stype,
|
Type: stype,
|
||||||
SDP: parsed["sdp"].(string),
|
SDP: parsed["sdp"].(string),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue