2021-11-11 17:01:43 +01:00
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mattermost/focalboard/server/services/store"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetupTests(t *testing.T) (store.Store, func()) {
|
2021-12-17 18:30:47 +01:00
|
|
|
dbType, connectionString, err := PrepareNewTestDatabase()
|
|
|
|
require.NoError(t, err)
|
2021-11-11 17:01:43 +01:00
|
|
|
|
|
|
|
logger := mlog.CreateConsoleTestLogger(false, mlog.LvlDebug)
|
|
|
|
|
|
|
|
sqlDB, err := sql.Open(dbType, connectionString)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = sqlDB.Ping()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
storeParams := Params{
|
|
|
|
DBType: dbType,
|
|
|
|
ConnectionString: connectionString,
|
|
|
|
TablePrefix: "test_",
|
|
|
|
Logger: logger,
|
|
|
|
DB: sqlDB,
|
|
|
|
IsPlugin: false,
|
|
|
|
}
|
|
|
|
store, err := New(storeParams)
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
tearDown := func() {
|
|
|
|
defer func() { _ = logger.Shutdown() }()
|
|
|
|
err = store.Shutdown()
|
|
|
|
require.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return store, tearDown
|
|
|
|
}
|