diff --git a/server/services/store/sqlstore/sqlstore_test.go b/server/services/store/sqlstore/sqlstore_test.go index 13e0a2497..edb55bcd5 100644 --- a/server/services/store/sqlstore/sqlstore_test.go +++ b/server/services/store/sqlstore/sqlstore_test.go @@ -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) }) } diff --git a/server/services/store/sqlstore/blocks_test.go b/server/services/store/storetests/blocks.go similarity index 82% rename from server/services/store/sqlstore/blocks_test.go rename to server/services/store/storetests/blocks.go index 0e65eae4b..08acf3304 100644 --- a/server/services/store/sqlstore/blocks_test.go +++ b/server/services/store/storetests/blocks.go @@ -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", diff --git a/server/services/store/storetests/helpers.go b/server/services/store/storetests/helpers.go new file mode 100644 index 000000000..c294dcf1a --- /dev/null +++ b/server/services/store/storetests/helpers.go @@ -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 +}