forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathresponse_test.go
55 lines (47 loc) · 1.06 KB
/
response_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
package tarantool_test
import (
"bytes"
"io"
"testing"
"github.com/stretchr/testify/require"
"github.com/tarantool/go-iproto"
"github.com/tarantool/go-tarantool/v2"
"github.com/vmihailenco/msgpack/v5"
)
func encodeResponseData(t *testing.T, data interface{}) io.Reader {
t.Helper()
buf := bytes.NewBuffer([]byte{})
enc := msgpack.NewEncoder(buf)
enc.EncodeMapLen(1)
enc.EncodeUint8(uint8(iproto.IPROTO_DATA))
enc.Encode([]interface{}{data})
return buf
}
func TestDecodeBaseResponse(t *testing.T) {
tests := []struct {
name string
header tarantool.Header
body interface{}
}{
{
"test1",
tarantool.Header{},
nil,
},
{
"test2",
tarantool.Header{RequestId: 123},
[]byte{'v', '2'},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res, err := tarantool.DecodeBaseResponse(tt.header, encodeResponseData(t, tt.body))
require.NoError(t, err)
require.Equal(t, tt.header, res.Header())
got, err := res.Decode()
require.NoError(t, err)
require.Equal(t, []interface{}{tt.body}, got)
})
}
}