@@ -89,6 +89,7 @@ func (s *StoreSuite) TestStoreMustFind() {
89
89
query := NewStoreFixtureQuery ()
90
90
s .NotPanics (func () {
91
91
rs := store .MustFind (query )
92
+ defer rs .Close ()
92
93
s .NotNil (rs )
93
94
})
94
95
}
@@ -111,6 +112,64 @@ func (s *StoreSuite) TestStoreFindOneReturnValues() {
111
112
s .resultOrError (doc , err )
112
113
}
113
114
115
+ func (s * StoreSuite ) TestStoreFindAllReturnValues () {
116
+ store := NewStoreWithConstructFixtureStore (s .db )
117
+ s .Nil (store .Insert (NewStoreWithConstructFixture ("foo" )))
118
+ s .Nil (store .Insert (NewStoreWithConstructFixture ("bar" )))
119
+
120
+ notFoundQuery := NewStoreWithConstructFixtureQuery ()
121
+ notFoundQuery .Where (kallax .Eq (Schema .ResultSetFixture .ID , kallax .NewULID ()))
122
+ docs , err := store .FindAll (notFoundQuery )
123
+ s .resultsOrError (docs , err )
124
+ s .NotPanics (func () {
125
+ s .Equal (0 , len (docs ))
126
+ })
127
+
128
+ docs , err = store .FindAll (NewStoreWithConstructFixtureQuery ().Order (kallax .Asc (Schema .StoreWithConstructFixture .Foo )))
129
+ s .resultsOrError (docs , err )
130
+ s .NotPanics (func () {
131
+ s .Equal (2 , len (docs ))
132
+ s .Equal ("bar" , docs [0 ].Foo )
133
+ s .Equal ("foo" , docs [1 ].Foo )
134
+ })
135
+ }
136
+
137
+ func (s * StoreSuite ) TestStoreCount () {
138
+ store := NewStoreWithConstructFixtureStore (s .db )
139
+ s .Nil (store .Insert (NewStoreWithConstructFixture ("foo" )))
140
+ s .Nil (store .Insert (NewStoreWithConstructFixture ("bar" )))
141
+
142
+ notFoundQuery := NewStoreWithConstructFixtureQuery ()
143
+ notFoundQuery .Where (kallax .Eq (Schema .ResultSetFixture .ID , kallax .NewULID ()))
144
+ count , err := store .Count (notFoundQuery )
145
+ s .Nil (err )
146
+ s .NotPanics (func () {
147
+ s .Equal (int64 (0 ), count )
148
+ })
149
+
150
+ count , err = store .Count (NewStoreWithConstructFixtureQuery ())
151
+ s .Nil (err )
152
+ s .NotPanics (func () {
153
+ s .Equal (int64 (2 ), count )
154
+ })
155
+ }
156
+
157
+ func (s * StoreSuite ) TestStoreReload () {
158
+ store := NewStoreWithConstructFixtureStore (s .db )
159
+ s .Nil (store .Insert (NewStoreWithConstructFixture ("bar" )))
160
+
161
+ doc , err := store .FindOne (NewStoreWithConstructFixtureQuery ().FindByFoo ("bar" ).Select (Schema .StoreWithConstructFixture .ID ))
162
+ s .Nil (err )
163
+ s .NotPanics (func () {
164
+ s .Equal ("" , doc .Foo )
165
+ })
166
+ err = store .Reload (doc )
167
+ s .Nil (err )
168
+ s .NotPanics (func () {
169
+ s .Equal ("bar" , doc .Foo )
170
+ })
171
+ }
172
+
114
173
func (s * StoreSuite ) TestStoreInsertUpdateMustFind () {
115
174
store := NewStoreWithConstructFixtureStore (s .db )
116
175
0 commit comments