39 lines
867 B
Go
39 lines
867 B
Go
package db0304
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRowEncode(t *testing.T) {
|
|
schema := &Schema{
|
|
Table: "link",
|
|
Cols: []Column{
|
|
{Name: "time", Type: TypeI64},
|
|
{Name: "src", Type: TypeStr},
|
|
{Name: "dst", Type: TypeStr},
|
|
},
|
|
PKey: []int{1, 2}, // (src, dst)
|
|
}
|
|
|
|
row := Row{
|
|
Cell{Type: TypeI64, I64: 123},
|
|
Cell{Type: TypeStr, Str: []byte("a")},
|
|
Cell{Type: TypeStr, Str: []byte("b")},
|
|
}
|
|
key := []byte{'l', 'i', 'n', 'k', 0, 1, 0, 0, 0, 'a', 1, 0, 0, 0, 'b'}
|
|
val := []byte{123, 0, 0, 0, 0, 0, 0, 0}
|
|
assert.Equal(t, key, row.EncodeKey(schema))
|
|
assert.Equal(t, val, row.EncodeVal(schema))
|
|
|
|
decoded := schema.NewRow()
|
|
err := decoded.DecodeKey(schema, key)
|
|
assert.Nil(t, err)
|
|
err = decoded.DecodeVal(schema, val)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, row, decoded)
|
|
}
|
|
|
|
// QzBQWVJJOUhU https://trialofcode.org/
|