-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepository_test.go
162 lines (108 loc) · 4.06 KB
/
repository_test.go
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package mgorepo
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewRepository(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := NewRepository[
testModel,
testDAO,
searchFilters,
SearchOrders,
SearchOptions[searchFilters, SearchOrders],
updateFields,
](
d,
collection,
getFilterBuilders(),
getUpdateBuilders(),
)
assert.NotNil(t, repo.clock, "clock should not be nil")
assert.NotEmpty(t, repo.db, "db should not be empty")
assert.NotEmpty(t, repo.collectionName, "collectionName should not be empty")
assert.NotEmpty(t, repo.filterBuilders, "filterBuilders should not be empty")
assert.NotEmpty(t, repo.updateBuilders, "updateBuilders should not be empty")
repo = repo.SetCreatedAtField("created")
assert.Equal(t, "created", repo.createdAtField, "createdAtField should be equal")
}
func TestRepository_SetDefaultSearchLimit(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := newTestRepository(d)
assert.Equal(t, DefaultSearchLimit, repo.searchLimit, "defaultSearchLimit should be equal")
repo = repo.SetDefaultSearchLimit(100)
assert.Equal(t, 100, repo.searchLimit, "defaultSearchLimit should be equal")
repo = repo.SetDefaultSearchLimit(0)
assert.Equal(t, DefaultSearchLimit, repo.searchLimit, "defaultSearchLimit should be equal")
}
func TestRepository_SetLogger(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := newTestRepository(d)
assert.NotNil(t, repo.Logger(), "logger should not be nil")
repo = repo.SetLogger(nil)
assert.Nil(t, repo.Logger(), "logger should be nil")
}
func TestRepository_SetUpdatedAtField(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := newTestRepository(d)
assert.Equal(t, DefaultUpdatedAtField, repo.updatedAtField, "updatedAtField should be equal")
repo = repo.SetUpdatedAtField("updated")
assert.Equal(t, "updated", repo.updatedAtField, "updatedAtField should be equal")
repo = repo.SetUpdatedAtField("")
assert.Equal(t, DefaultUpdatedAtField, repo.updatedAtField, "updatedAtField should be equal")
}
func TestRepository_SetCreatedAtField(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := newTestRepository(d)
assert.Equal(t, DefaultCreatedAtField, repo.createdAtField, "createdAtField should be equal")
repo = repo.SetCreatedAtField("created")
assert.Equal(t, "created", repo.createdAtField, "createdAtField should be equal")
repo = repo.SetCreatedAtField("")
assert.Equal(t, DefaultCreatedAtField, repo.createdAtField, "createdAtField should be equal")
}
func TestRepository_SetDeletedAtField(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := newTestRepository(d)
assert.Equal(t, DefaultDeletedAtField, repo.deletedAtField, "deletedAtField should be equal")
repo = repo.SetDeletedAtField("deleted")
assert.Equal(t, "deleted", repo.deletedAtField, "deletedAtField should be equal")
repo = repo.SetDeletedAtField("")
assert.Equal(t, DefaultDeletedAtField, repo.deletedAtField, "deletedAtField should be equal")
}
func TestRepository_WithTimestamps(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := newTestRepository(d)
assert.True(t, repo.withTimestamps, "timestamps should be true")
repo = repo.WithTimestamps(false)
assert.False(t, repo.withTimestamps, "timestamps should be false")
}
func TestRepository_Db(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := newTestRepository(d)
assert.NotNil(t, repo.db, "db should not be nil")
assert.Equal(t, repo.db, repo.Db(), "db should be equal")
}
func TestRepository_Clock(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := newTestRepository(d)
assert.NotNil(t, repo.clock, "clock should not be nil")
assert.Equal(t, repo.clock, repo.Clock(), "clock should be equal")
repo = repo.SetClock(nil)
assert.Nil(t, repo.clock, "clock should be nil")
}
func TestRepository_CollectionName(t *testing.T) {
t.Parallel()
d := getTestDriver(t)
repo := newTestRepository(d)
assert.NotEmpty(t, repo.collectionName, "collectionName should not be empty")
assert.Equal(t, repo.collectionName, repo.CollectionName(), "collectionName should be equal")
}