-
Notifications
You must be signed in to change notification settings - Fork 8
/
message_builders_test.go
99 lines (94 loc) · 1.68 KB
/
message_builders_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
package gobayeux
import "testing"
func TestHandshakeRequestBuilder_AddSupportedConnectionType(t *testing.T) {
testCases := []struct {
name string
ct string
shouldErr bool
}{
{
"valid long-polling",
"long-polling",
false,
},
{
"valid callback-polling",
"callback-polling",
false,
},
{
"valid iframe",
"iframe",
false,
},
{
"invalid connection type",
"invalid-polling",
true,
},
}
for _, testCase := range testCases {
tc := testCase
t.Run(tc.name, func(t *testing.T) {
b := NewHandshakeRequestBuilder()
err := b.AddSupportedConnectionType(tc.ct)
if err != nil && !tc.shouldErr {
t.Errorf("expected connection type %s to be valid but got err %q", tc.ct, err)
}
if err == nil && tc.shouldErr {
t.Error("expected an error but didn't get one")
}
})
}
}
func TestHandshakeRequestBuilder_AddVersion(t *testing.T) {
testCases := []struct {
name string
version string
shouldErr bool
}{
{
"valid version 1.0",
"1.0",
false,
},
{
"valid version 1.0beta",
"1.0beta",
false,
},
{
"valid version 10.0",
"10.0",
false,
},
{
"invalid version .0",
".0",
true,
},
{
"invalid version a.0",
"a.0",
true,
},
{
"invalid version (empty)",
"",
true,
},
}
for _, testCase := range testCases {
tc := testCase
t.Run(tc.name, func(t *testing.T) {
b := NewHandshakeRequestBuilder()
err := b.AddVersion(tc.version)
if err != nil && !tc.shouldErr {
t.Errorf("expected version %s to be valid but got err %q", tc.version, err)
}
if err == nil && tc.shouldErr {
t.Error("expected an error but didn't get one")
}
})
}
}