2020-10-18 01:09:12 +02:00
|
|
|
package sqlstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-05-29 08:23:10 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/mlog"
|
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-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-05-29 08:23:10 +02:00
|
|
|
logger := mlog.CreateTestLogger(t)
|
|
|
|
|
|
|
|
store, err := New(dbType, connectionString, "test_", logger)
|
2020-10-18 01:09:12 +02:00
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
tearDown := func() {
|
2021-05-29 08:23:10 +02:00
|
|
|
defer 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) })
|
2020-11-12 19:48:08 +01:00
|
|
|
}
|