-
Notifications
You must be signed in to change notification settings - Fork 0
/
frame_utils_test.go
63 lines (53 loc) · 1.21 KB
/
frame_utils_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
package websocket
import "testing"
func TestOpcodeExist(t *testing.T) {
type testCase struct {
o int
v bool
}
testCases := []testCase{
// Should return false when opcode is invalid
{o: 15, v: false},
// Should return true when opcode is valid.
{o: OpcodeText, v: true},
}
for i, c := range testCases {
if v := opcodeExist(c.o); v != c.v {
t.Errorf("test case %d: expected '%t' for '%d'", i, c.v, c.o)
}
}
}
func TestValidateKey(t *testing.T) {
type testCase struct {
k []byte
r bool
}
testCases := []testCase{
{k: []byte{1, 2, 3, 4}, r: true},
{k: []byte{}, r: true},
{k: []byte{1, 2, 3, 4, 5}, r: false},
{k: []byte{1, 2, 3}, r: false},
}
for i, c := range testCases {
if validateKey(c.k) != c.r {
t.Errorf("test case %d: expected '%t' for %v", i, c.r, c.k)
}
}
}
func TestValidatePayload(t *testing.T) {
type testCase struct {
l uint64
r bool
}
testCases := []testCase{
{l: 125, r: true},
// testCase{l: 9223372036854775807, r: true},
// testCase{l: 9223372036854775808, r: false},
}
for i, c := range testCases {
b := make([]byte, c.l)
if validatePayload(b) != c.r {
t.Errorf("test case %d: expected '%t' for payload of size '%d'", i, c.r, c.l)
}
}
}