-
Notifications
You must be signed in to change notification settings - Fork 2
/
bind_complete_test.go
85 lines (72 loc) · 1.51 KB
/
bind_complete_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package pgproto_test
import (
"bytes"
"testing"
"github.com/c653labs/pgproto"
"github.com/stretchr/testify/suite"
)
type BindCompleteTestSuite struct {
suite.Suite
}
func TestBindCompleteTestSuite(t *testing.T) {
suite.Run(t, new(BindCompleteTestSuite))
}
func (s *BindCompleteTestSuite) Test_ParseBindComplete() {
raw := []byte{
// Tag
'2',
// Length
'\x00', '\x00', '\x00', '\x04',
}
bind, err := pgproto.ParseBindComplete(bytes.NewReader(raw))
s.Nil(err)
s.NotNil(bind)
s.Equal(raw, bind.Encode())
}
func BenchmarkBindCompleteParse(b *testing.B) {
raw := []byte{
// Tag
'2',
// Length
'\x00', '\x00', '\x00', '\x04',
}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
_, err := pgproto.ParseBindComplete(bytes.NewReader(raw))
if err != nil {
b.Error(err)
}
}
})
}
func (s *BindCompleteTestSuite) Test_ParseBindComplete_Empty() {
bind, err := pgproto.ParseBindComplete(bytes.NewReader([]byte{}))
s.NotNil(err)
s.Nil(bind)
}
func BenchmarkBindCompleteParse_Empty(b *testing.B) {
raw := []byte{}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
pgproto.ParseBindComplete(bytes.NewReader(raw))
}
})
}
func (s *BindCompleteTestSuite) Test_EncodeBindComplete() {
expected := []byte{
// Tag
'2',
// Length
'\x00', '\x00', '\x00', '\x04',
}
bind := &pgproto.BindComplete{}
s.Equal(expected, bind.Encode())
}
func BenchmarkBindComplete(b *testing.B) {
bind := &pgproto.BindComplete{}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
bind.Encode()
}
})
}