forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 58
/
client_tools_test.go
51 lines (44 loc) · 1.1 KB
/
client_tools_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
package tarantool_test
import (
"bytes"
"testing"
"github.com/vmihailenco/msgpack/v5"
"github.com/tarantool/go-tarantool/v2"
)
func TestOperations_EncodeMsgpack(t *testing.T) {
ops := tarantool.NewOperations().
Add(1, 2).
Subtract(1, 2).
BitwiseAnd(1, 2).
BitwiseOr(1, 2).
BitwiseXor(1, 2).
Splice(1, 2, 3, "a").
Insert(1, 2).
Delete(1, 2).
Assign(1, 2)
refOps := []interface{}{
[]interface{}{"+", 1, 2},
[]interface{}{"-", 1, 2},
[]interface{}{"&", 1, 2},
[]interface{}{"|", 1, 2},
[]interface{}{"^", 1, 2},
[]interface{}{":", 1, 2, 3, "a"},
[]interface{}{"!", 1, 2},
[]interface{}{"#", 1, 2},
[]interface{}{"=", 1, 2},
}
var refBuf bytes.Buffer
encRef := msgpack.NewEncoder(&refBuf)
if err := encRef.Encode(refOps); err != nil {
t.Errorf("error while encoding: %v", err.Error())
}
var buf bytes.Buffer
enc := msgpack.NewEncoder(&buf)
if err := enc.Encode(ops); err != nil {
t.Errorf("error while encoding: %v", err.Error())
}
if !bytes.Equal(refBuf.Bytes(), buf.Bytes()) {
t.Errorf("encode response is wrong:\n expected %v\n got: %v",
refBuf, buf.Bytes())
}
}