Moving tests outside the sqlstore to allow future no-sql implementations
This commit is contained in:
parent
b0d8d5a025
commit
baad055cc9
3 changed files with 70 additions and 43 deletions
|
@ -4,11 +4,12 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/store"
|
||||
"github.com/mattermost/focalboard/server/services/store/storetests"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func SetupTests(t *testing.T) (*SQLStore, func()) {
|
||||
func SetupTests(t *testing.T) (store.Store, func()) {
|
||||
dbType := os.Getenv("OT_STORE_TEST_DB_TYPE")
|
||||
if dbType == "" {
|
||||
dbType = "sqlite3"
|
||||
|
@ -30,26 +31,6 @@ func SetupTests(t *testing.T) (*SQLStore, func()) {
|
|||
return store, tearDown
|
||||
}
|
||||
|
||||
func InsertBlocks(t *testing.T, s *SQLStore, blocks []model.Block) {
|
||||
for _, block := range blocks {
|
||||
err := s.InsertBlock(block)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteBlocks(t *testing.T, s *SQLStore, blocks []model.Block, modifiedBy string) {
|
||||
for _, block := range blocks {
|
||||
err := s.DeleteBlock(block.ID, modifiedBy)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func ContainsBlockWithID(blocks []model.Block, blockID string) bool {
|
||||
for _, block := range blocks {
|
||||
if block.ID == blockID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
func TestBlocksStore(t *testing.T) {
|
||||
t.Run("BlocksStore", func(t *testing.T) { storetests.StoreTestBlocksStore(t, SetupTests) })
|
||||
}
|
||||
|
|
|
@ -1,15 +1,30 @@
|
|||
package sqlstore
|
||||
package storetests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/store"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestInsertBlock(t *testing.T) {
|
||||
store, tearDown := SetupTests(t)
|
||||
func StoreTestBlocksStore(t *testing.T, setup func(t *testing.T) (store.Store, func())) {
|
||||
t.Run("InsertBlock", func(t *testing.T) {
|
||||
store, tearDown := setup(t)
|
||||
testInsertBlock(t, store, tearDown)
|
||||
})
|
||||
t.Run("GetSubTree2", func(t *testing.T) {
|
||||
store, tearDown := setup(t)
|
||||
testGetSubTree2(t, store, tearDown)
|
||||
})
|
||||
t.Run("GetSubTree3", func(t *testing.T) {
|
||||
store, tearDown := setup(t)
|
||||
testGetSubTree3(t, store, tearDown)
|
||||
})
|
||||
}
|
||||
|
||||
func testInsertBlock(t *testing.T, store store.Store, tearDown func()) {
|
||||
defer tearDown()
|
||||
|
||||
userID := "user-id"
|
||||
|
@ -41,8 +56,7 @@ func TestInsertBlock(t *testing.T) {
|
|||
require.Len(t, blocks, initialCount)
|
||||
}
|
||||
|
||||
func TestGetSubTree2(t *testing.T) {
|
||||
store, tearDown := SetupTests(t)
|
||||
func testGetSubTree2(t *testing.T, store store.Store, tearDown func()) {
|
||||
defer tearDown()
|
||||
|
||||
userID := "user-id"
|
||||
|
@ -52,36 +66,36 @@ func TestGetSubTree2(t *testing.T) {
|
|||
initialCount := len(blocks)
|
||||
|
||||
blocksToInsert := []model.Block{
|
||||
model.Block{
|
||||
{
|
||||
ID: "parent",
|
||||
RootID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "child1",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "child2",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "grandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "child1",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "grandchild2",
|
||||
RootID: "parent",
|
||||
ParentID: "child2",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "greatgrandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "grandchild1",
|
||||
|
@ -111,8 +125,7 @@ func TestGetSubTree2(t *testing.T) {
|
|||
require.Len(t, blocks, initialCount)
|
||||
}
|
||||
|
||||
func TestGetSubTree3(t *testing.T) {
|
||||
store, tearDown := SetupTests(t)
|
||||
func testGetSubTree3(t *testing.T, store store.Store, tearDown func()) {
|
||||
defer tearDown()
|
||||
|
||||
userID := "user-id"
|
||||
|
@ -122,36 +135,36 @@ func TestGetSubTree3(t *testing.T) {
|
|||
initialCount := len(blocks)
|
||||
|
||||
blocksToInsert := []model.Block{
|
||||
model.Block{
|
||||
{
|
||||
ID: "parent",
|
||||
RootID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "child1",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "child2",
|
||||
RootID: "parent",
|
||||
ParentID: "parent",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "grandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "child1",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "grandchild2",
|
||||
RootID: "parent",
|
||||
ParentID: "child2",
|
||||
ModifiedBy: userID,
|
||||
},
|
||||
model.Block{
|
||||
{
|
||||
ID: "greatgrandchild1",
|
||||
RootID: "parent",
|
||||
ParentID: "grandchild1",
|
33
server/services/store/storetests/helpers.go
Normal file
33
server/services/store/storetests/helpers.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package storetests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/focalboard/server/model"
|
||||
"github.com/mattermost/focalboard/server/services/store"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func InsertBlocks(t *testing.T, s store.Store, blocks []model.Block) {
|
||||
for _, block := range blocks {
|
||||
err := s.InsertBlock(block)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteBlocks(t *testing.T, s store.Store, blocks []model.Block, modifiedBy string) {
|
||||
for _, block := range blocks {
|
||||
err := s.DeleteBlock(block.ID, modifiedBy)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func ContainsBlockWithID(blocks []model.Block, blockID string) bool {
|
||||
for _, block := range blocks {
|
||||
if block.ID == blockID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
Loading…
Reference in a new issue