1 Star 2 Fork 0

GoLangLibs / bigcache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
encoding_test.go 1011 Bytes
一键复制 编辑 原始数据 按行查看 历史
janisz 提交于 2019-12-03 22:49 . Remove dependecy to testify (#190)
package bigcache
import (
"testing"
"time"
)
func TestEncodeDecode(t *testing.T) {
// given
now := uint64(time.Now().Unix())
hash := uint64(42)
key := "key"
data := []byte("data")
buffer := make([]byte, 100)
// when
wrapped := wrapEntry(now, hash, key, data, &buffer)
// then
assertEqual(t, key, readKeyFromEntry(wrapped))
assertEqual(t, hash, readHashFromEntry(wrapped))
assertEqual(t, now, readTimestampFromEntry(wrapped))
assertEqual(t, data, readEntry(wrapped))
assertEqual(t, 100, len(buffer))
}
func TestAllocateBiggerBuffer(t *testing.T) {
//given
now := uint64(time.Now().Unix())
hash := uint64(42)
key := "1"
data := []byte("2")
buffer := make([]byte, 1)
// when
wrapped := wrapEntry(now, hash, key, data, &buffer)
// then
assertEqual(t, key, readKeyFromEntry(wrapped))
assertEqual(t, hash, readHashFromEntry(wrapped))
assertEqual(t, now, readTimestampFromEntry(wrapped))
assertEqual(t, data, readEntry(wrapped))
assertEqual(t, 2+headersSizeInBytes, len(buffer))
}
Go
1
https://gitee.com/GoLangLibs/bigcache.git
git@gitee.com:GoLangLibs/bigcache.git
GoLangLibs
bigcache
bigcache
master

搜索帮助