1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-27 13:48:52 +02:00
focalboard/server/services/store/sqlstore/helpers_test.go
Miguel de la Cruz feb49eaf19
Add foundation tests (#3670)
* Add foundation and its instrumentation code

* Add migration 18 and deletedMembershipBoardsMigration tests

* Update go sum
2022-08-18 17:03:33 +02:00

47 lines
1.1 KiB
Go

package sqlstore
import (
"database/sql"
"os"
"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()) {
dbType, connectionString, err := PrepareNewTestDatabase()
require.NoError(t, err)
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.NoError(t, err)
tearDown := func() {
defer func() { _ = logger.Shutdown() }()
err = store.Shutdown()
require.Nil(t, err)
if err = os.Remove(connectionString); err == nil {
logger.Debug("Removed test database", mlog.String("file", connectionString))
}
}
return store, tearDown
}