-
Notifications
You must be signed in to change notification settings - Fork 1
/
default_codec_test.go
55 lines (47 loc) · 1.21 KB
/
default_codec_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 mgcache
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestString(t *testing.T) {
codec := NewDefaultCodec()
value := "testing string value"
bytes, err := codec.Encode(value)
assert.Nil(t, err)
var decodeValue string
err = codec.Decode(bytes, &decodeValue)
assert.Nil(t, err)
assert.Equal(t, value, decodeValue)
}
func TestInt64(t *testing.T) {
codec := NewDefaultCodec()
var value int64 = 1
bytes, err := codec.Encode(value)
assert.Nil(t, err)
var decodeValue int64
err = codec.Decode(bytes, &decodeValue)
assert.Nil(t, err)
assert.Equal(t, value, decodeValue)
}
func TestMapStringString(t *testing.T) {
codec := NewDefaultCodec()
var value = map[string]string{"a": "b"}
bytes, err := codec.Encode(value)
assert.Nil(t, err)
var decodeValue = make(map[string]string)
err = codec.Decode(bytes, &decodeValue)
assert.Nil(t, err)
for k, v := range value {
assert.Equal(t, v, decodeValue[k])
}
}
func TestByteSlice(t *testing.T) {
codec := NewDefaultCodec()
var value = []byte{1, 2, 3}
bytes, err := codec.Encode(value)
assert.Nil(t, err)
var decodeValue = make([]byte, 0)
err = codec.Decode(bytes, &decodeValue)
assert.Nil(t, err)
assert.Equal(t, 3, len(decodeValue))
}