-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacket_test.go
More file actions
52 lines (47 loc) · 920 Bytes
/
packet_test.go
File metadata and controls
52 lines (47 loc) · 920 Bytes
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
package eiop
import (
"fmt"
"testing"
)
func TestParseType(t *testing.T) {
type testCase struct {
arg string
want PacketType
}
cases := []testCase{
{"message", Message},
{"noop", Noop},
{"4", Message},
{"2", Ping},
{"", Error},
{"fail", Error},
{"-2", Error},
{"7", Error},
}
for _, tc := range cases {
t.Run(fmt.Sprintf("%s=%d", tc.arg, tc.want), func(t *testing.T) {
got, _ := ParseType(tc.arg)
if tc.want != got {
t.Errorf("Expected '%d', but got '%d'", tc.want, got)
}
})
}
}
func TestPacketType_String(t *testing.T) {
type testCase struct {
arg PacketType
want string
}
cases := []testCase{
{Upgrade, StrUpgrade},
{Open, StrOpen},
}
for _, tc := range cases {
t.Run(fmt.Sprintf("%d=%s", tc.arg, tc.want), func(t *testing.T) {
got := tc.arg.String()
if tc.want != got {
t.Errorf("Expected '%s', but got '%s'", tc.want, got)
}
})
}
}