-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompat_test.go
More file actions
37 lines (34 loc) · 775 Bytes
/
compat_test.go
File metadata and controls
37 lines (34 loc) · 775 Bytes
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
package tarantool
import (
"bytes"
"encoding/hex"
"testing"
"github.com/vmihailenco/msgpack"
)
func TestOpEncode(t *testing.T) {
buf := new(bytes.Buffer)
e := newEncoder(buf)
op := []interface{}{[]interface{}{"=", uint32(1), "bye"}, []interface{}{"#", uint32(2), uint32(1)}}
if err := e.Encode(op); err != nil {
t.Fatal(err)
}
data := buf.Bytes()
d := msgpack.NewDecoder(buf)
decoded := make([]Op, 0, 2)
if err := d.Decode(&decoded); err != nil {
t.Fatal(err)
}
if len(decoded) != 2 {
t.Error("bad length")
}
newBuf := new(bytes.Buffer)
e = newEncoder(newBuf)
if err := e.Encode(decoded); err != nil {
t.Fatal(err)
}
if !bytes.Equal(newBuf.Bytes(), data) {
t.Error("not equal")
t.Log(hex.Dump(newBuf.Bytes()))
t.Log(hex.Dump(data))
}
}