File: fmtp_test.go

package info (click to toggle)
golang-github-pion-webrtc.v3 3.1.56-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,392 kB
  • sloc: javascript: 595; sh: 28; makefile: 5
file content (131 lines) | stat: -rw-r--r-- 3,182 bytes parent folder | download | duplicates (2)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package fmtp

import (
	"reflect"
	"testing"
)

func TestGenericParseFmtp(t *testing.T) {
	testCases := map[string]struct {
		input    string
		expected FMTP
	}{
		"OneParam": {
			input: "key-name=value",
			expected: &genericFMTP{
				mimeType: "generic",
				parameters: map[string]string{
					"key-name": "value",
				},
			},
		},
		"OneParamWithWhiteSpeces": {
			input: "\tkey-name=value ",
			expected: &genericFMTP{
				mimeType: "generic",
				parameters: map[string]string{
					"key-name": "value",
				},
			},
		},
		"TwoParams": {
			input: "key-name=value;key2=value2",
			expected: &genericFMTP{
				mimeType: "generic",
				parameters: map[string]string{
					"key-name": "value",
					"key2":     "value2",
				},
			},
		},
		"TwoParamsWithWhiteSpeces": {
			input: "key-name=value;  \n\tkey2=value2 ",
			expected: &genericFMTP{
				mimeType: "generic",
				parameters: map[string]string{
					"key-name": "value",
					"key2":     "value2",
				},
			},
		},
	}
	for name, testCase := range testCases {
		testCase := testCase
		t.Run(name, func(t *testing.T) {
			f := Parse("generic", testCase.input)
			if !reflect.DeepEqual(testCase.expected, f) {
				t.Errorf("Expected Fmtp params: %v, got: %v", testCase.expected, f)
			}

			if f.MimeType() != "generic" {
				t.Errorf("Expected MimeType of generic, got: %s", f.MimeType())
			}
		})
	}
}

func TestGenericFmtpCompare(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) {
			aa := Parse("", a)
			bb := Parse("", b)
			c := aa.Match(bb)
			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],
				)
			}

			// test reverse case here
			c = bb.Match(aa)
			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)
		})
	}
}