forked from calebdoxsey/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtcsessiondescription_test.go
59 lines (50 loc) · 1.43 KB
/
rtcsessiondescription_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
package webrtc
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRTCSessionDescription_JSON(t *testing.T) {
testCases := []struct {
desc RTCSessionDescription
expectedString string
unmarshalErr error
}{
{RTCSessionDescription{Type: RTCSdpTypeOffer, Sdp: "sdp"}, `{"type":"offer","sdp":"sdp"}`, nil},
{RTCSessionDescription{Type: RTCSdpTypePranswer, Sdp: "sdp"}, `{"type":"pranswer","sdp":"sdp"}`, nil},
{RTCSessionDescription{Type: RTCSdpTypeAnswer, Sdp: "sdp"}, `{"type":"answer","sdp":"sdp"}`, nil},
{RTCSessionDescription{Type: RTCSdpTypeRollback, Sdp: "sdp"}, `{"type":"rollback","sdp":"sdp"}`, nil},
{RTCSessionDescription{Type: RTCSdpType(Unknown), Sdp: "sdp"}, `{"type":"unknown","sdp":"sdp"}`, ErrUnknownType},
}
for i, testCase := range testCases {
descData, err := json.Marshal(testCase.desc)
assert.Nil(t,
err,
"testCase: %d %v marshal err: %v", i, testCase, err,
)
assert.Equal(t,
string(descData),
testCase.expectedString,
"testCase: %d %v", i, testCase,
)
var desc RTCSessionDescription
err = json.Unmarshal(descData, &desc)
if testCase.unmarshalErr != nil {
assert.Equal(t,
err,
testCase.unmarshalErr,
"testCase: %d %v", i, testCase,
)
continue
}
assert.Nil(t,
err,
"testCase: %d %v unmarshal err: %v", i, testCase, err,
)
assert.Equal(t,
desc,
testCase.desc,
"testCase: %d %v", i, testCase,
)
}
}