2020-10-18 01:09:12 +02:00
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
import (
|
2021-06-25 16:49:06 +02:00
|
|
|
"database/sql"
|
2020-10-18 01:09:12 +02:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-01-29 17:50:20 +01:00
|
|
|
"github.com/mattermost/focalboard/server/services/store"
|
|
|
|
"github.com/mattermost/focalboard/server/services/store/storetests"
|
2020-10-18 01:09:12 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-08-25 22:08:01 +02:00
|
|
|
|
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
2020-10-18 01:09:12 +02:00
|
|
|
)
|
|
|
|
|
2021-01-29 17:50:20 +01:00
|
|
|
func SetupTests(t *testing.T) (store.Store, func()) {
|
2021-04-17 09:06:57 +02:00
|
|
|
dbType := os.Getenv("FB_STORE_TEST_DB_TYPE")
|
2020-10-18 01:09:12 +02:00
|
|
|
if dbType == "" {
|
2021-04-22 22:53:01 +02:00
|
|
|
dbType = sqliteDBType
|
2020-10-18 01:09:12 +02:00
|
|
|
}
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2021-04-17 09:06:57 +02:00
|
|
|
connectionString := os.Getenv("FB_STORE_TEST_CONN_STRING")
|
2020-10-18 01:09:12 +02:00
|
|
|
if connectionString == "" {
|
|
|
|
connectionString = ":memory:"
|
|
|
|
}
|
|
|
|
|
2021-08-25 22:08:01 +02:00
|
|
|
logger := mlog.CreateConsoleTestLogger(false, mlog.LvlDebug)
|
2021-05-29 08:23:10 +02:00
|
|
|
|
2021-06-25 16:49:06 +02:00
|
|
|
sqlDB, err := sql.Open(dbType, connectionString)
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = sqlDB.Ping()
|
|
|
|
require.NoError(t, err)
|
|
|
|
store, err := New(dbType, connectionString, "test_", logger, sqlDB)
|
2020-10-18 01:09:12 +02:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
tearDown := func() {
|
2021-06-21 11:21:42 +02:00
|
|
|
defer func() { _ = logger.Shutdown() }()
|
2020-10-18 02:07:35 +02:00
|
|
|
err = store.Shutdown()
|
|
|
|
require.Nil(t, err)
|
2020-10-18 01:09:12 +02:00
|
|
|
}
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-18 01:09:12 +02:00
|
|
|
return store, tearDown
|
|
|
|
}
|
2020-11-12 19:48:08 +01:00
|
|
|
|
2021-01-29 17:50:20 +01:00
|
|
|
func TestBlocksStore(t *testing.T) {
|
|
|
|
t.Run("BlocksStore", func(t *testing.T) { storetests.StoreTestBlocksStore(t, SetupTests) })
|
2021-01-29 20:27:43 +01:00
|
|
|
t.Run("SharingStore", func(t *testing.T) { storetests.StoreTestSharingStore(t, SetupTests) })
|
2021-04-30 16:48:45 +02:00
|
|
|
t.Run("SystemStore", func(t *testing.T) { storetests.StoreTestSystemStore(t, SetupTests) })
|
2021-06-04 15:23:15 +02:00
|
|
|
t.Run("UserStore", func(t *testing.T) { storetests.StoreTestUserStore(t, SetupTests) })
|
2021-07-22 13:56:25 +02:00
|
|
|
t.Run("SessionStore", func(t *testing.T) { storetests.StoreTestSessionStore(t, SetupTests) })
|
2021-07-29 11:56:57 +02:00
|
|
|
t.Run("WorkspaceStore", func(t *testing.T) { storetests.StoreTestWorkspaceStore(t, SetupTests) })
|
2020-11-12 19:48:08 +01:00
|
|
|
}
|