snowflake/client/client_test.go
Cecylia Bocovich 92520f681d Choose a random subset from given STUN servers
Only chooses a subset as long as we have over 2 STUN servers to choose
from.
2020-07-23 11:30:36 -04:00

59 lines
1 KiB
Go

package main
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestICEServerParser(t *testing.T) {
Convey("Test parsing of ICE servers", t, func() {
for _, test := range []struct {
input string
urls [][]string
length int
}{
{
"",
nil,
0,
},
{
" ",
nil,
0,
},
{
"stun:stun.l.google.com:19302",
[][]string{[]string{"stun:stun.l.google.com:19302"}},
1,
},
{
"stun:stun.l.google.com:19302,stun.ekiga.net",
[][]string{[]string{"stun:stun.l.google.com:19302"}, []string{"stun.ekiga.net"}},
2,
},
{
"stun:stun.l.google.com:19302, stun.ekiga.net",
[][]string{[]string{"stun:stun.l.google.com:19302"}, []string{"stun.ekiga.net"}},
2,
},
} {
servers := parseIceServers(test.input)
if test.urls == nil {
So(servers, ShouldBeNil)
} else {
So(servers, ShouldNotBeNil)
}
So(len(servers), ShouldEqual, test.length)
for _, server := range servers {
So(test.urls, ShouldContain, server.URLs)
}
}
})
}