forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iceserver_test.go
84 lines (78 loc) · 2.35 KB
/
iceserver_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// +build !js
package webrtc
import (
"testing"
"github.com/pion/ice"
"github.com/pion/webrtc/v2/pkg/rtcerr"
"github.com/stretchr/testify/assert"
)
func TestICEServer_validate(t *testing.T) {
t.Run("Success", func(t *testing.T) {
testCases := []struct {
iceServer ICEServer
expectedValidate bool
}{
{ICEServer{
URLs: []string{"turn:192.158.29.39?transport=udp"},
Username: "unittest",
Credential: "placeholder",
CredentialType: ICECredentialTypePassword,
}, true},
{ICEServer{
URLs: []string{"turn:192.158.29.39?transport=udp"},
Username: "unittest",
Credential: OAuthCredential{
MACKey: "WmtzanB3ZW9peFhtdm42NzUzNG0=",
AccessToken: "AAwg3kPHWPfvk9bDFL936wYvkoctMADzQ5VhNDgeMR3+ZlZ35byg972fW8QjpEl7bx91YLBPFsIhsxloWcXPhA==",
},
CredentialType: ICECredentialTypeOauth,
}, true},
}
for i, testCase := range testCases {
_, err := testCase.iceServer.urls()
assert.Nil(t, err, "testCase: %d %v", i, testCase)
}
})
t.Run("Failure", func(t *testing.T) {
testCases := []struct {
iceServer ICEServer
expectedErr error
}{
{ICEServer{
URLs: []string{"turn:192.158.29.39?transport=udp"},
}, &rtcerr.InvalidAccessError{Err: ErrNoTurnCredentials}},
{ICEServer{
URLs: []string{"turn:192.158.29.39?transport=udp"},
Username: "unittest",
Credential: false,
CredentialType: ICECredentialTypePassword,
}, &rtcerr.InvalidAccessError{Err: ErrTurnCredentials}},
{ICEServer{
URLs: []string{"turn:192.158.29.39?transport=udp"},
Username: "unittest",
Credential: false,
CredentialType: ICECredentialTypeOauth,
}, &rtcerr.InvalidAccessError{Err: ErrTurnCredentials}},
{ICEServer{
URLs: []string{"turn:192.158.29.39?transport=udp"},
Username: "unittest",
Credential: false,
CredentialType: Unknown,
}, &rtcerr.InvalidAccessError{Err: ErrTurnCredentials}},
{ICEServer{
URLs: []string{"stun:google.de?transport=udp"},
Username: "unittest",
Credential: false,
CredentialType: ICECredentialTypeOauth,
}, ice.ErrSTUNQuery},
}
for i, testCase := range testCases {
_, err := testCase.iceServer.urls()
assert.EqualError(t,
err,
testCase.expectedErr.Error(),
"testCase: %d %v", i, testCase,
)
}
})
}