1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-11-30 08:36:54 +02:00

GH-2745 Don't init default templates when unit testing (#2748)

* Don't warn when  appears in card followed by text that is not a username

* Selectively initalize default templates for unit tests that need them to reduce test times. Reduce log noise.
This commit is contained in:
Doug Lauder 2022-04-08 07:46:16 -04:00 committed by GitHub
parent 4411bdddb3
commit 30e6bc477d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 17 deletions

View File

@ -115,6 +115,8 @@ watch-server-test: modd-precheck ## Run server tests watching for changes
server-test: server-test-sqlite server-test-mysql server-test-postgres ## Run server tests
server-test-sqlite: export FB_UNIT_TESTING=1
server-test-sqlite: templates-archive ## Run server tests using sqlite
cd server; go test -tags '$(BUILD_TAGS)' -race -v -count=1 -timeout=30m ./...

View File

@ -344,7 +344,8 @@ func (a *App) GetBlocksForBoard(boardID string) ([]model.Block, error) {
}
func (a *App) notifyBlockChanged(action notify.Action, block *model.Block, oldBlock *model.Block, modifiedByID string) {
if a.notifications == nil {
// don't notify if notifications service disabled, or block change is generated via system user.
if a.notifications == nil || modifiedByID == model.SystemUserID {
return
}

View File

@ -49,7 +49,7 @@ func (a *App) initializeTemplates() (bool, error) {
opt := model.ImportArchiveOptions{
TeamID: model.GlobalTeamID,
ModifiedBy: "system",
ModifiedBy: model.SystemUserID,
BlockModifier: fixTemplateBlock,
BoardModifier: fixTemplateBoard,
}
@ -69,7 +69,7 @@ func (a *App) isInitializationNeeded(boards []*model.Board) (bool, string) {
// look for any built-in template boards with the wrong version number (or no version #).
for _, board := range boards {
// if not built-in board...skip
if board.CreatedBy != "system" {
if board.CreatedBy != model.SystemUserID {
continue
}
if board.TemplateVersion < defaultTemplateVersion {

View File

@ -1479,6 +1479,9 @@ func TestGetTemplates(t *testing.T) {
th := SetupTestHelper(t).InitBasic()
defer th.TearDown()
err := th.Server.App().InitTemplates()
require.NoError(t, err, "InitTemplates should not fail")
teamID := "my-team-id"
rBoards, resp := th.Client.GetTemplatesForTeam("0")
th.CheckOK(resp)

View File

@ -259,6 +259,9 @@ func TestPermissionsGetTeamTemplates(t *testing.T) {
testData := setupData(t, th)
clients := setupClients(th)
err := th.Server.App().InitTemplates()
require.NoError(t, err, "InitTemplates should succeed")
builtInTemplateCount := 7
ttCases := []TestCase{
@ -2075,6 +2078,9 @@ func TestPermissionsOnboard(t *testing.T) {
testData := setupData(t, th)
clients := setupClients(th)
err := th.Server.App().InitTemplates()
require.NoError(t, err, "InitTemplates should not fail")
ttCases := []TestCase{
{"/teams/test-team/onboard", methodPost, "", userAnon, http.StatusUnauthorized, 0},
{"/teams/test-team/onboard", methodPost, "", userNoTeamMember, http.StatusForbidden, 0},

View File

@ -8,6 +8,7 @@ import (
const (
SingleUser = "single-user"
GlobalTeamID = "0"
SystemUserID = "system"
)
// User is a user

View File

@ -130,14 +130,15 @@ func New(params Params) (*Server, error) {
}
appServices := app.Services{
Auth: authenticator,
Store: params.DBStore,
FilesBackend: filesBackend,
Webhook: webhookClient,
Metrics: metricsService,
Notifications: notificationService,
Logger: params.Logger,
Permissions: params.PermissionsService,
Auth: authenticator,
Store: params.DBStore,
FilesBackend: filesBackend,
Webhook: webhookClient,
Metrics: metricsService,
Notifications: notificationService,
Logger: params.Logger,
Permissions: params.PermissionsService,
SkipTemplateInit: utils.IsRunningUnitTests(),
}
app := app.New(params.Cfg, wsAdapter, appServices)
@ -203,11 +204,6 @@ func New(params Params) (*Server, error) {
server.initHandlers()
if err := app.InitTemplates(); err != nil {
params.Logger.Error("Unable initialize team templates", mlog.Err(err))
return nil, err
}
return &server, nil
}

View File

@ -18,7 +18,7 @@ var (
func (s *SQLStore) removeDefaultTemplates(db sq.BaseRunner, boards []*model.Board) error {
count := 0
for _, board := range boards {
if board.CreatedBy != "system" {
if board.CreatedBy != model.SystemUserID {
continue
}
// default template deletion does not need to go to blocks_history

20
server/utils/debug.go Normal file
View File

@ -0,0 +1,20 @@
package utils
import (
"os"
"strings"
)
// IsRunningUnitTests returns true if this instance of FocalBoard is running unit or integration tests.
func IsRunningUnitTests() bool {
testing := os.Getenv("FB_UNIT_TESTING")
if testing == "" {
return false
}
switch strings.ToLower(testing) {
case "1", "t", "y", "true", "yes":
return true
}
return false
}