forked from algorand/go-yamux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
const_test.go
71 lines (63 loc) · 1.24 KB
/
const_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
package yamux
import (
"testing"
)
func TestConst(t *testing.T) {
if protoVersion != 0 {
t.Fatalf("bad: %v", protoVersion)
}
if typeData != 0 {
t.Fatalf("bad: %v", typeData)
}
if typeWindowUpdate != 1 {
t.Fatalf("bad: %v", typeWindowUpdate)
}
if typePing != 2 {
t.Fatalf("bad: %v", typePing)
}
if typeGoAway != 3 {
t.Fatalf("bad: %v", typeGoAway)
}
if flagSYN != 1 {
t.Fatalf("bad: %v", flagSYN)
}
if flagACK != 2 {
t.Fatalf("bad: %v", flagACK)
}
if flagFIN != 4 {
t.Fatalf("bad: %v", flagFIN)
}
if flagRST != 8 {
t.Fatalf("bad: %v", flagRST)
}
if goAwayNormal != 0 {
t.Fatalf("bad: %v", goAwayNormal)
}
if goAwayProtoErr != 1 {
t.Fatalf("bad: %v", goAwayProtoErr)
}
if goAwayInternalErr != 2 {
t.Fatalf("bad: %v", goAwayInternalErr)
}
if headerSize != 12 {
t.Fatalf("bad header size")
}
}
func TestEncodeDecode(t *testing.T) {
hdr := encode(typeWindowUpdate, flagACK|flagRST, 1234, 4321)
if hdr.Version() != protoVersion {
t.Fatalf("bad: %v", hdr)
}
if hdr.MsgType() != typeWindowUpdate {
t.Fatalf("bad: %v", hdr)
}
if hdr.Flags() != flagACK|flagRST {
t.Fatalf("bad: %v", hdr)
}
if hdr.StreamID() != 1234 {
t.Fatalf("bad: %v", hdr)
}
if hdr.Length() != 4321 {
t.Fatalf("bad: %v", hdr)
}
}