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:
Zachary Wasserman 2016-11-08 13:46:36 -08:00 committed by GitHub
parent 00d479a3b6
commit 991fd6c146

View file

@ -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)
})
}
}