mirror of
https://github.com/mattermost/focalboard.git
synced 2024-11-27 08:31:20 +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:
parent
4411bdddb3
commit
30e6bc477d
2
Makefile
2
Makefile
@ -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 ./...
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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},
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
const (
|
||||
SingleUser = "single-user"
|
||||
GlobalTeamID = "0"
|
||||
SystemUserID = "system"
|
||||
)
|
||||
|
||||
// User is a user
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
20
server/utils/debug.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user