-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount.integration_test.go
More file actions
85 lines (71 loc) · 2.08 KB
/
count.integration_test.go
File metadata and controls
85 lines (71 loc) · 2.08 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// +build integrate
package postgres
import (
"context"
"testing"
"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/mapping"
)
var testModels = []mapping.Model{&tests.Model{}, &tests.SimpleModel{}, &tests.OmitModel{}}
// TestIntegrationCount does integration tests for the Count method.
func TestIntegrationCount(t *testing.T) {
c := testingController(t, true, testModels...)
p := testingRepository(c)
ctx := context.Background()
mStruct, err := c.ModelStruct(&tests.Model{})
require.NoError(t, err)
defer func() {
_ = internal.DropTables(ctx, p.ConnPool, mStruct.DatabaseName, mStruct.DatabaseSchemaName)
}()
db := database.New(c)
newModel := func() *tests.Model {
return &tests.Model{
AttrString: "Something",
Int: 3,
}
}
models := []mapping.Model{newModel(), newModel()}
// Insert models.
err = db.Query(mStruct, models...).Insert()
require.NoError(t, err)
assert.Len(t, models, 2)
countAll, err := db.Query(mStruct).Count()
require.NoError(t, err)
assert.Equal(t, int64(2), countAll)
}
// c, db := prepareIntegrateRepository(t)
//
// defer db.Close()
// defer deleteTestModelTable(t, db)
//
// s, err := query.NewC(c, &tests.Model{})
// require.NoError(t, err)
//
// count, err := s.Count()
// require.NoError(t, err)
//
// // there should be 4 created at 'prepareIntegrateRepository' instances
// assert.Equal(t, int64(len(testModelInstances)), count)
//
// for i := 0; i < 10; i++ {
// tm := &tests.Model{Int: i}
// s, err := query.NewC(c, tm)
// require.NoError(t, err)
//
// err = s.Create()
// require.NoError(t, err)
// }
//
// s, err = query.NewC(c, &tests.Model{})
// require.NoError(t, err)
//
// count, err = s.Count()
// require.NoError(t, err)
//
// // there should be 10 models + 4 created at 'prepareIntegrateRepository' instances
// assert.Equal(t, int64(10+len(testModelInstances)), count)
// }