Add tests for array store (#1922)

Fix #504

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1922
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
Lunny Xiao 2021-06-07 17:36:22 +08:00
parent 0f69f1eda2
commit 43977186d3
1 changed files with 35 additions and 0 deletions

View File

@ -450,3 +450,38 @@ func TestDecimal(t *testing.T) {
assert.NotNil(t, m.Account) assert.NotNil(t, m.Account)
assert.EqualValues(t, 10000000000000000, m.Account.AsInt64()) assert.EqualValues(t, 10000000000000000, m.Account.AsInt64())
} }
type MyArray [20]byte
func (d *MyArray) FromDB(data []byte) error {
for i, b := range data[:20] {
(*d)[i] = b
}
return nil
}
func (d MyArray) ToDB() ([]byte, error) {
return d[:], nil
}
func TestMyArray(t *testing.T) {
type MyArrayStruct struct {
Id int64
Content MyArray
}
assert.NoError(t, PrepareEngine())
assertSync(t, new(MyArrayStruct))
var v = [20]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
_, err := testEngine.Insert(&MyArrayStruct{
Content: v,
})
assert.NoError(t, err)
var m MyArrayStruct
has, err := testEngine.Get(&m)
assert.NoError(t, err)
assert.True(t, has)
assert.EqualValues(t, v, m.Content)
}