From 43977186d339162eb9cade55d0e96cbae952a598 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 7 Jun 2021 17:36:22 +0800 Subject: [PATCH] Add tests for array store (#1922) Fix #504 Reviewed-on: https://gitea.com/xorm/xorm/pulls/1922 Co-authored-by: Lunny Xiao Co-committed-by: Lunny Xiao --- integrations/types_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/integrations/types_test.go b/integrations/types_test.go index 4fc123ec..91f334d9 100644 --- a/integrations/types_test.go +++ b/integrations/types_test.go @@ -450,3 +450,38 @@ func TestDecimal(t *testing.T) { assert.NotNil(t, m.Account) 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) +}