-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
test.go
33 lines (26 loc) · 735 Bytes
/
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
package tlvparse
import (
"bufio"
"bytes"
"testing"
"github.com/pires/go-proxyproto"
)
func checkTLVs(t *testing.T, name string, raw []byte, expected []proxyproto.PP2Type) []proxyproto.TLV {
header, err := proxyproto.Read(bufio.NewReader(bytes.NewReader(raw)))
if err != nil {
t.Fatalf("%s: Unexpected error reading header %#v", name, err)
}
tlvs, err := header.TLVs()
if err != nil {
t.Fatalf("%s: Unexpected error splitting TLVS %#v", name, err)
}
if len(tlvs) != len(expected) {
t.Fatalf("%s: Expected %d TLVs, actual %d", name, len(expected), len(tlvs))
}
for i, et := range expected {
if at := tlvs[i].Type; at != et {
t.Fatalf("%s: Expected type %X, actual %X", name, et, at)
}
}
return tlvs
}