forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmtp_test.go
107 lines (103 loc) · 2.53 KB
/
fmtp_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package webrtc
import (
"reflect"
"testing"
)
func TestParseFmtp(t *testing.T) {
testCases := map[string]struct {
input string
expected fmtp
}{
"OneParam": {
input: "key-name=value",
expected: fmtp{
"key-name": "value",
},
},
"OneParamWithWhiteSpeces": {
input: "\tkey-name=value ",
expected: fmtp{
"key-name": "value",
},
},
"TwoParams": {
input: "key-name=value;key2=value2",
expected: fmtp{
"key-name": "value",
"key2": "value2",
},
},
"TwoParamsWithWhiteSpeces": {
input: "key-name=value; \n\tkey2=value2 ",
expected: fmtp{
"key-name": "value",
"key2": "value2",
},
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
f := parseFmtp(testCase.input)
if !reflect.DeepEqual(testCase.expected, f) {
t.Errorf("Expected Fmtp params: %v, got: %v", testCase.expected, f)
}
})
}
}
func TestFmtpConsist(t *testing.T) {
consistString := map[bool]string{true: "consist", false: "inconsist"}
testCases := map[string]struct {
a, b string
consist bool
}{
"Equal": {
a: "key1=value1;key2=value2;key3=value3",
b: "key1=value1;key2=value2;key3=value3",
consist: true,
},
"EqualWithWhitespaceVariants": {
a: "key1=value1;key2=value2;key3=value3",
b: " key1=value1; \nkey2=value2;\t\nkey3=value3",
consist: true,
},
"EqualWithCase": {
a: "key1=value1;key2=value2;key3=value3",
b: "key1=value1;key2=Value2;Key3=value3",
consist: true,
},
"OneHasExtraParam": {
a: "key1=value1;key2=value2;key3=value3",
b: "key1=value1;key2=value2;key3=value3;key4=value4",
consist: true,
},
"Inconsistent": {
a: "key1=value1;key2=value2;key3=value3",
b: "key1=value1;key2=different_value;key3=value3",
consist: false,
},
"Inconsistent_OneHasExtraParam": {
a: "key1=value1;key2=value2;key3=value3;key4=value4",
b: "key1=value1;key2=different_value;key3=value3",
consist: false,
},
}
for name, testCase := range testCases {
testCase := testCase
check := func(t *testing.T, a, b string) {
c := fmtpConsist(parseFmtp(a), parseFmtp(b))
if c != testCase.consist {
t.Errorf(
"'%s' and '%s' are expected to be %s, but treated as %s",
a, b, consistString[testCase.consist], consistString[c],
)
}
}
t.Run(name, func(t *testing.T) {
check(t, testCase.a, testCase.b)
})
t.Run(name+"_Reversed", func(t *testing.T) {
check(t, testCase.b, testCase.a)
})
}
}