focalboard/server/services/store/sqlstore/helpers_test.go
Miguel de la Cruz e7c38c8822
Adds data migrations and the unique IDs migration (#1776)
* Adds data migrations and the unique IDs migration

* Adds GetSystemSetting tests

* Add log statements to data migrations

* Move migrations to the store and ensure they follow an order mixing database and data migrations

* Fix system settings

* Add tests for unique id migration

* Small comment change

* Make a couple of methods private and wrap the migration in a transaction

* Update public methods

* Add database mutex to data migrations

* Create server params and pass a mutex factory to the store

* Fix plugin linter

* Make isPlugin private

* Fix comment typo

Co-authored-by: Doug Lauder <wiggin77@warpmail.net>

Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
2021-11-11 17:01:43 +01:00

50 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 := os.Getenv("FB_STORE_TEST_DB_TYPE")
if dbType == "" {
dbType = sqliteDBType
}
connectionString := os.Getenv("FB_STORE_TEST_CONN_STRING")
if connectionString == "" {
connectionString = ":memory:"
}
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
}