-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommand_test.go
More file actions
103 lines (89 loc) · 2.04 KB
/
command_test.go
File metadata and controls
103 lines (89 loc) · 2.04 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package pgproto_test
import (
"bytes"
"testing"
"github.com/c653labs/pgproto"
"github.com/stretchr/testify/suite"
)
type CommandCompletionTestSuite struct {
suite.Suite
}
func TestCommandCompletionTestSuite(t *testing.T) {
suite.Run(t, new(CommandCompletionTestSuite))
}
func (s *CommandCompletionTestSuite) Test_ParseCommandCompletion() {
raw := []byte{
// Tag
'C',
// Length
'\x00', '\x00', '\x00', '\x0f',
// Tag
'\x73', '\x65', '\x6c', '\x65', '\x63', '\x74', '\x20', '\x31', '\x32', '\x31',
// \0
'\x00',
}
command, err := pgproto.ParseCommandCompletion(bytes.NewReader(raw))
s.Nil(err)
s.NotNil(command)
s.Equal(command.Tag, []byte("select 121"))
s.Equal(raw, command.Encode())
}
func BenchmarkCommandCompletionParse(b *testing.B) {
raw := []byte{
// Tag
'C',
// Length
'\x00', '\x00', '\x00', '\x0f',
// Tag
'\x73', '\x65', '\x6c', '\x65', '\x63', '\x74', '\x20', '\x31', '\x32', '\x31',
// \0
'\x00',
}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
_, err := pgproto.ParseCommandCompletion(bytes.NewReader(raw))
if err != nil {
b.Error(err)
}
}
})
}
func (s *CommandCompletionTestSuite) Test_ParseCommandCompletion_Empty() {
command, err := pgproto.ParseCommandCompletion(bytes.NewReader([]byte{}))
s.NotNil(err)
s.Nil(command)
}
func BenchmarkCommandCompletionParse_Empty(b *testing.B) {
raw := []byte{}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
pgproto.ParseCommandCompletion(bytes.NewReader(raw))
}
})
}
func (s *CommandCompletionTestSuite) Test_CommandCompletionEncode() {
expected := []byte{
// Tag
'C',
// Length
'\x00', '\x00', '\x00', '\x0f',
// Tag
'\x73', '\x65', '\x6c', '\x65', '\x63', '\x74', '\x20', '\x31', '\x32', '\x31',
// \0
'\x00',
}
c := &pgproto.CommandCompletion{
Tag: []byte("select 121"),
}
s.Equal(expected, c.Encode())
}
func BenchmarkCommandCompletionEncode(b *testing.B) {
c := &pgproto.CommandCompletion{
Tag: []byte("select 121"),
}
b.RunParallel(func(p *testing.PB) {
for p.Next() {
c.Encode()
}
})
}