-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclose_complete_test.go
85 lines (72 loc) · 1.55 KB
/
close_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 CloseCompleteTestSuite struct {
suite.Suite
}
func TestCloseCompleteTestSuite(t *testing.T) {
suite.Run(t, new(CloseCompleteTestSuite))
}
func (s *CloseCompleteTestSuite) Test_ParseCloseComplete() {
raw := []byte{
// Tag
'3',
// Length
'\x00', '\x00', '\x00', '\x04',
}
close, err := pgproto.ParseCloseComplete(bytes.NewReader(raw))
s.Nil(err)
s.NotNil(close)
s.Equal(raw, close.Encode())
}
func BenchmarkCloseCompleteParse(b *testing.B) {
raw := []byte{
// Tag
'3',
// Length
'\x00', '\x00', '\x00', '\x04',
}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
_, err := pgproto.ParseCloseComplete(bytes.NewReader(raw))
if err != nil {
b.Error(err)
}
}
})
}
func (s *CloseCompleteTestSuite) Test_ParseCloseComplete_Empty() {
close, err := pgproto.ParseCloseComplete(bytes.NewReader([]byte{}))
s.NotNil(err)
s.Nil(close)
}
func BenchmarkCloseCompleteParse_Empty(b *testing.B) {
raw := []byte{}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
pgproto.ParseCloseComplete(bytes.NewReader(raw))
}
})
}
func (s *CloseCompleteTestSuite) Test_EncodeCloseComplete() {
expected := []byte{
// Tag
'3',
// Length
'\x00', '\x00', '\x00', '\x04',
}
close := &pgproto.CloseComplete{}
s.Equal(expected, close.Encode())
}
func BenchmarkCloseCompleteEncode(b *testing.B) {
close := &pgproto.CloseComplete{}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
close.Encode()
}
})
}