mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
33 lines
689 B
Go
33 lines
689 B
Go
package codec
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.mills.io/prologic/bitcask/v2/internal"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEncode(t *testing.T) {
|
|
t.Parallel()
|
|
assert := assert.New(t)
|
|
|
|
var buf bytes.Buffer
|
|
mockTime := time.Date(2020, 10, 1, 0, 0, 0, 0, time.UTC)
|
|
encoder := NewEncoder(&buf)
|
|
_, err := encoder.Encode(internal.Entry{
|
|
Key: []byte("mykey"),
|
|
Value: []byte("myvalue"),
|
|
Checksum: 414141,
|
|
Offset: 424242,
|
|
Expiry: &mockTime,
|
|
})
|
|
|
|
expectedHex := "0000000500000000000000076d796b65796d7976616c7565000651bd000000005f751c00"
|
|
if assert.NoError(err) {
|
|
assert.Equal(expectedHex, hex.EncodeToString(buf.Bytes()))
|
|
}
|
|
}
|