File: const_test.go

package info (click to toggle)
golang-github-hashicorp-yamux 0.0~git20180605.35205983-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 196 kB
  • sloc: makefile: 2
file content (72 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download | duplicates (5)
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
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 := header(make([]byte, headerSize))
	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)
	}
}