focalboard/server/services/store/sqlstore/sqlstore_test.go

56 lines
1.1 KiB
Go
Raw Normal View History

package sqlstore
import (
"os"
"testing"
2021-01-26 23:13:46 +01:00
"github.com/mattermost/focalboard/server/model"
"github.com/stretchr/testify/require"
)
func SetupTests(t *testing.T) (*SQLStore, func()) {
dbType := os.Getenv("OT_STORE_TEST_DB_TYPE")
if dbType == "" {
dbType = "sqlite3"
}
connectionString := os.Getenv("OT_STORE_TEST_CONN_STRING")
if connectionString == "" {
connectionString = ":memory:"
}
store, err := New(dbType, connectionString)
require.Nil(t, err)
tearDown := func() {
2020-10-18 02:07:35 +02:00
err = store.Shutdown()
require.Nil(t, err)
}
return store, tearDown
}
2020-11-12 19:48:08 +01:00
func InsertBlocks(t *testing.T, s *SQLStore, blocks []model.Block) {
for _, block := range blocks {
err := s.InsertBlock(block)
require.NoError(t, err)
}
}
2021-01-12 20:16:25 +01:00
func DeleteBlocks(t *testing.T, s *SQLStore, blocks []model.Block, modifiedBy string) {
2020-11-12 19:48:08 +01:00
for _, block := range blocks {
2021-01-12 20:16:25 +01:00
err := s.DeleteBlock(block.ID, modifiedBy)
2020-11-12 19:48:08 +01:00
require.NoError(t, err)
}
}
func ContainsBlockWithID(blocks []model.Block, blockID string) bool {
for _, block := range blocks {
if block.ID == blockID {
return true
}
}
return false
}