main

mattermost/focalboard

Last updated at: 29/12/2023 09:52

helpers.go

TLDR

This file (helpers.go) is located at server/services/store/storetests in the Demo Projects project. It contains helper functions for testing the store package.

Methods

InsertBlocks

This method is used to insert blocks into the store. It takes in a testing.T object, a store.Store object, an array of model.Block objects, and a userID. The method iterates over the blocks and inserts each block into the store using the provided store object and userID. It uses require.NoError from the github.com/stretchr/testify/require package to handle any errors.

DeleteBlocks

This method is used to delete blocks from the store. It takes in a testing.T object, a store.Store object, an array of model.Block objects, and a modifiedBy string. The method iterates over the blocks and deletes each block from the store using the provided store object and modifiedBy parameter. It uses require.NoError from the github.com/stretchr/testify/require package to handle any errors.

ContainsBlockWithID

This method is used to check if an array of blocks contains a block with a specific ID. It takes in an array of model.Block objects and a blockID string. The method iterates over the blocks and compares the ID of each block with the provided blockID. If a match is found, it returns true. Otherwise, it returns false.

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, userID string) {
	for i := range blocks {
		err := s.InsertBlock(blocks[i], userID)
		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
}