mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Ensure tables are dropped after panic in test (#456)
Prior to this, a panic in the test function would leave data in the database. Now we ensure that tables are dropped even after a panic.
This commit is contained in:
parent
00d479a3b6
commit
991fd6c146
1 changed files with 3 additions and 6 deletions
|
|
@ -29,6 +29,7 @@ func setupGorm(t *testing.T) (ds kolide.Datastore, teardown func()) {
|
|||
if !ok {
|
||||
panic("expected gormDB datastore")
|
||||
}
|
||||
require.Nil(t, db.Drop())
|
||||
db.DB.Close()
|
||||
}
|
||||
return ds, teardown
|
||||
|
|
@ -38,15 +39,11 @@ func TestGorm(t *testing.T) {
|
|||
if _, ok := os.LookupEnv("MYSQL_TEST"); !ok {
|
||||
t.SkipNow()
|
||||
}
|
||||
ds, teardown := setupGorm(t)
|
||||
defer teardown()
|
||||
for _, f := range testFunctions {
|
||||
t.Run(functionName(f), func(t *testing.T) {
|
||||
err := ds.Migrate()
|
||||
require.Nil(t, err)
|
||||
ds, teardown := setupGorm(t)
|
||||
defer teardown()
|
||||
f(t, ds)
|
||||
err = ds.Drop()
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue