-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_integration_test.go
More file actions
51 lines (39 loc) · 1.31 KB
/
array_integration_test.go
File metadata and controls
51 lines (39 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// +build integrate
package postgres
import (
"context"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/neuronlabs/neuron-extensions/repository/postgres/internal"
"github.com/neuronlabs/neuron-extensions/repository/postgres/tests"
"github.com/neuronlabs/neuron/database"
"github.com/neuronlabs/neuron/query/filter"
)
func TestArrayIntegrationModel(t *testing.T) {
c := testingController(t, true, &tests.ArrayModel{})
p := testingRepository(c)
ctx := context.Background()
mStruct, err := c.ModelStruct(&tests.ArrayModel{})
require.NoError(t, err)
defer func() {
_ = internal.DropTables(ctx, p.ConnPool, mStruct.DatabaseName, mStruct.DatabaseSchemaName)
}()
db := database.New(c)
model := &tests.ArrayModel{
ID: uuid.New(),
SliceInt: []int{1, 2, 3},
SliceString: []string{"4", "5", "6"},
}
mStruct = c.MustModelStruct(model)
err = db.QueryCtx(ctx, mStruct, model).Insert()
require.NoError(t, err)
fromDB, err := db.QueryCtx(ctx, mStruct).Filter(filter.New(mStruct.Primary(), filter.OpEqual, model.ID)).Get()
require.NoError(t, err)
fromDBA, ok := fromDB.(*tests.ArrayModel)
require.True(t, ok)
assert.True(t, fromDBA.ID == model.ID)
assert.Len(t, fromDBA.SliceInt, 3)
assert.Len(t, fromDBA.SliceString, 3)
}