-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparse_complete_test.go
More file actions
85 lines (72 loc) · 1.54 KB
/
parse_complete_test.go
File metadata and controls
85 lines (72 loc) · 1.54 KB
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 ParseCompleteTestSuite struct {
suite.Suite
}
func TestParseCompleteTestSuite(t *testing.T) {
suite.Run(t, new(ParseCompleteTestSuite))
}
func (s *ParseCompleteTestSuite) Test_ParseParseComplete() {
raw := []byte{
// Tag
'1',
// Length
'\x00', '\x00', '\x00', '\x04',
}
parse, err := pgproto.ParseParseComplete(bytes.NewReader(raw))
s.Nil(err)
s.NotNil(parse)
s.Equal(raw, parse.Encode())
}
func BenchmarkParseCompleteParse(b *testing.B) {
raw := []byte{
// Tag
'1',
// Length
'\x00', '\x00', '\x00', '\x04',
}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
_, err := pgproto.ParseParseComplete(bytes.NewReader(raw))
if err != nil {
b.Error(err)
}
}
})
}
func (s *ParseCompleteTestSuite) Test_ParseParseComplete_Empty() {
parse, err := pgproto.ParseParseComplete(bytes.NewReader([]byte{}))
s.NotNil(err)
s.Nil(parse)
}
func BenchmarkParseCompleteParse_Empty(b *testing.B) {
raw := []byte{}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
pgproto.ParseParseComplete(bytes.NewReader(raw))
}
})
}
func (s *ParseCompleteTestSuite) Test_EncodeParseComplete() {
expected := []byte{
// Tag
'1',
// Length
'\x00', '\x00', '\x00', '\x04',
}
parse := &pgproto.ParseComplete{}
s.Equal(expected, parse.Encode())
}
func BenchmarkParseComplete(b *testing.B) {
parse := &pgproto.ParseComplete{}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
parse.Encode()
}
})
}