mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
12f8c0b671
This PR reorganizes a bunch of the files in datastore such that all datastore implementations are consistently broken up into multiple files. Additionally, the datastore tests follow a similar pattern and can easily be applied to any complete datastore implementation.
37 lines
683 B
Go
37 lines
683 B
Go
package datastore
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func setupGorm(t *testing.T) kolide.Datastore {
|
|
db, err := gorm.Open("sqlite3", ":memory:")
|
|
require.Nil(t, err)
|
|
|
|
ds := gormDB{DB: db, Driver: "sqlite3"}
|
|
|
|
err = ds.Migrate()
|
|
assert.Nil(t, err)
|
|
return ds
|
|
}
|
|
|
|
func teardownGorm(t *testing.T, ds kolide.Datastore) {
|
|
err := ds.Drop()
|
|
assert.Nil(t, err)
|
|
}
|
|
|
|
func TestGorm(t *testing.T) {
|
|
for _, f := range testFunctions {
|
|
t.Run(functionName(f), func(t *testing.T) {
|
|
ds := setupGorm(t)
|
|
defer teardownGorm(t, ds)
|
|
f(t, ds)
|
|
})
|
|
}
|
|
}
|