[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Add tests for session descripion functions



commit 32bec89a848b4b5d2c9be20420e39a50190930d5
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date:   Mon Nov 4 13:48:22 2019 -0500

    Add tests for session descripion functions
    
    Also removed some unnecessary code
---
 proxy-go/proxy-go_test.go | 82 +++++++++++++++++++++++++++++++++++++++++++++++
 proxy-go/snowflake.go     |  4 ---
 2 files changed, 82 insertions(+), 4 deletions(-)

diff --git a/proxy-go/proxy-go_test.go b/proxy-go/proxy-go_test.go
index 2413207..c6df31c 100644
--- a/proxy-go/proxy-go_test.go
+++ b/proxy-go/proxy-go_test.go
@@ -4,6 +4,9 @@ import (
 	"net"
 	"strings"
 	"testing"
+
+	"github.com/pion/webrtc"
+	. "github.com/smartystreets/goconvey/convey"
 )
 
 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() {
+	})
+}
diff --git a/proxy-go/snowflake.go b/proxy-go/snowflake.go
index ea2a986..9e52fd6 100644
--- a/proxy-go/snowflake.go
+++ b/proxy-go/snowflake.go
@@ -493,10 +493,6 @@ func deserializeSessionDescription(msg string) *webrtc.SessionDescription {
 		stype = webrtc.SDPTypeRollback
 	}
 
-	if err != nil {
-		log.Println(err)
-		return nil
-	}
 	return &webrtc.SessionDescription{
 		Type: stype,
 		SDP:  parsed["sdp"].(string),



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits