@@ -171,25 +171,23 @@ func (s *ImportTestSuite) Test_Ok() {
171
171
}()
172
172
173
173
// source DB should have expected
174
- validateRowCounts ( s . T (), s .inputDB , s .populatedRowCounts )
174
+ s . validateRowCounts ( s .inputDB , s .populatedRowCounts )
175
175
176
176
// initially, dest DB is empty
177
- validateRowCounts ( s . T (), s .outputDB , rowCounts {namespaces : 1 , experiments : 1 })
177
+ s . validateRowCounts ( s .outputDB , rowCounts {namespaces : 1 , experiments : 1 })
178
178
179
179
// invoke the Importer.Import() method
180
180
importer := database .NewImporter (s .inputDB , s .outputDB )
181
- err := importer .Import ()
182
- require .Nil (s .T (), err )
181
+ require .Nil (s .T (), importer .Import ())
183
182
184
183
// dest DB should now have the expected
185
- validateRowCounts ( s . T (), s .outputDB , s .populatedRowCounts )
184
+ s . validateRowCounts ( s .outputDB , s .populatedRowCounts )
186
185
187
186
// invoke the Importer.Import method a 2nd time
188
- err = importer .Import ()
189
- require .Nil (s .T (), err )
187
+ require .Nil (s .T (), importer .Import ())
190
188
191
189
// dest DB should still only have the expected (idempotent)
192
- validateRowCounts ( s . T (), s .outputDB , s .populatedRowCounts )
190
+ s . validateRowCounts ( s .outputDB , s .populatedRowCounts )
193
191
194
192
// confirm row-for-row equality
195
193
for _ , table := range []string {
@@ -203,78 +201,66 @@ func (s *ImportTestSuite) Test_Ok() {
203
201
"metrics" ,
204
202
"latest_metrics" ,
205
203
} {
206
- validateTable ( s . T (), s .inputDB , s .outputDB , table )
204
+ s . validateTable ( s .inputDB , s .outputDB , table )
207
205
}
208
206
}
209
207
210
208
// validateRowCounts will make assertions about the db based on the test setup.
211
209
// a db imported from the test setup db should also pass these
212
210
// assertions.
213
- func validateRowCounts ( t * testing. T , db * gorm.DB , counts rowCounts ) {
211
+ func ( s * ImportTestSuite ) validateRowCounts ( db * gorm.DB , counts rowCounts ) {
214
212
var countVal int64
215
- tx := db .Model (& models.Namespace {}).Count (& countVal )
216
- require .Nil (t , tx .Error )
217
- assert .Equal (t , counts .namespaces , int (countVal ), "Namespaces count incorrect" )
213
+ require .Nil (s .T (), db .Model (& models.Namespace {}).Count (& countVal ).Error )
214
+ assert .Equal (s .T (), counts .namespaces , int (countVal ), "Namespaces count incorrect" )
218
215
219
- tx = db .Model (& models.Experiment {}).Count (& countVal )
220
- require .Nil (t , tx .Error )
221
- assert .Equal (t , counts .experiments , int (countVal ), "Experiments count incorrect" )
216
+ require .Nil (s .T (), db .Model (& models.Experiment {}).Count (& countVal ).Error )
217
+ assert .Equal (s .T (), counts .experiments , int (countVal ), "Experiments count incorrect" )
222
218
223
- tx = db .Model (& models.Run {}).Count (& countVal )
224
- require .Nil (t , tx .Error )
225
- assert .Equal (t , counts .runs , int (countVal ), "Runs count incorrect" )
219
+ require .Nil (s .T (), db .Model (& models.Run {}).Count (& countVal ).Error )
220
+ assert .Equal (s .T (), counts .runs , int (countVal ), "Runs count incorrect" )
226
221
227
- tx = db .Model (& models.Metric {}).Count (& countVal )
228
- require .Nil (t , tx .Error )
229
- assert .Equal (t , counts .metrics , int (countVal ), "Metrics count incorrect" )
222
+ require .Nil (s .T (), db .Model (& models.Metric {}).Count (& countVal ).Error )
223
+ assert .Equal (s .T (), counts .metrics , int (countVal ), "Metrics count incorrect" )
230
224
231
- tx = db .Model (& models.LatestMetric {}).Count (& countVal )
232
- require .Nil (t , tx .Error )
233
- assert .Equal (t , counts .latestMetrics , int (countVal ), "Latest metrics count incorrect" )
225
+ require .Nil (s .T (), db .Model (& models.LatestMetric {}).Count (& countVal ).Error )
226
+ assert .Equal (s .T (), counts .latestMetrics , int (countVal ), "Latest metrics count incorrect" )
234
227
235
- tx = db .Model (& models.Tag {}).Count (& countVal )
236
- require .Nil (t , tx .Error )
237
- assert .Equal (t , counts .tags , int (countVal ), "Run tags count incorrect" )
228
+ require .Nil (s .T (), db .Model (& models.Tag {}).Count (& countVal ).Error )
229
+ assert .Equal (s .T (), counts .tags , int (countVal ), "Run tags count incorrect" )
238
230
239
- tx = db .Model (& models.Param {}).Count (& countVal )
240
- require .Nil (t , tx .Error )
241
- assert .Equal (t , counts .params , int (countVal ), "Run params count incorrect" )
231
+ require .Nil (s .T (), db .Model (& models.Param {}).Count (& countVal ).Error )
232
+ assert .Equal (s .T (), counts .params , int (countVal ), "Run params count incorrect" )
242
233
243
- tx = db .Model (& models.Run {}).Distinct ("experiment_id" ).Count (& countVal )
244
- require .Nil (t , tx .Error )
245
- assert .Equal (t , counts .distinctRunExperimentIDs , int (countVal ), "Runs experiment association incorrect" )
234
+ require .Nil (s .T (), db .Model (& models.Run {}).Distinct ("experiment_id" ).Count (& countVal ).Error )
235
+ assert .Equal (s .T (), counts .distinctRunExperimentIDs , int (countVal ), "Runs experiment association incorrect" )
246
236
247
- tx = db .Model (& database.App {}).Count (& countVal )
248
- require .Nil (t , tx .Error )
249
- assert .Equal (t , counts .apps , int (countVal ), "Apps count incorrect" )
237
+ require .Nil (s .T (), db .Model (& database.App {}).Count (& countVal ).Error )
238
+ assert .Equal (s .T (), counts .apps , int (countVal ), "Apps count incorrect" )
250
239
251
- tx = db .Model (& database.Dashboard {}).Count (& countVal )
252
- require .Nil (t , tx .Error )
253
- assert .Equal (t , counts .dashboards , int (countVal ), "Dashboard count incorrect" )
240
+ require .Nil (s .T (), db .Model (& database.Dashboard {}).Count (& countVal ).Error )
241
+ assert .Equal (s .T (), counts .dashboards , int (countVal ), "Dashboard count incorrect" )
254
242
}
255
243
256
244
// validateTable will scan source and dest table and confirm they are identical
257
- func validateTable ( t * testing. T , source , dest * gorm.DB , table string ) {
245
+ func ( s * ImportTestSuite ) validateTable ( source , dest * gorm.DB , table string ) {
258
246
sourceRows , err := source .Table (table ).Rows ()
259
- require .Nil (t , err )
260
- require .Nil (t , sourceRows .Err ())
247
+ require .Nil (s . T () , err )
248
+ require .Nil (s . T () , sourceRows .Err ())
261
249
destRows , err := dest .Table (table ).Rows ()
262
- require .Nil (t , err )
263
- require .Nil (t , destRows .Err ())
250
+ require .Nil (s . T () , err )
251
+ require .Nil (s . T () , destRows .Err ())
264
252
//nolint:errcheck
265
253
defer sourceRows .Close ()
266
254
//nolint:errcheck
267
255
defer destRows .Close ()
268
256
269
257
for sourceRows .Next () {
270
- var sourceRow , destRow map [string ]any
271
-
272
- err := source .ScanRows (sourceRows , & sourceRow )
273
- require .Nil (t , err )
258
+ // dest should have the same number of rows as source
259
+ require .True (s .T (), destRows .Next ())
274
260
275
- destRows . Next ()
276
- err = dest .ScanRows (destRows , & destRow )
277
- require .Nil (t , err )
261
+ var sourceRow , destRow map [ string ] any
262
+ require . Nil ( s . T (), source .ScanRows (sourceRows , & sourceRow ) )
263
+ require .Nil (s . T (), dest . ScanRows ( destRows , & destRow ) )
278
264
279
265
// TODO:DSuhinin delete this fields right now, because they
280
266
// cause comparison error when we compare `namespace` entities. Let's find smarter way to do that.
@@ -283,6 +269,8 @@ func validateTable(t *testing.T, source, dest *gorm.DB, table string) {
283
269
delete (sourceRow , "updated_at" )
284
270
delete (sourceRow , "created_at" )
285
271
286
- assert .Equal (t , sourceRow , destRow )
272
+ assert .Equal (s . T () , sourceRow , destRow )
287
273
}
274
+ // dest should have the same number of rows as source
275
+ require .False (s .T (), destRows .Next ())
288
276
}
0 commit comments