diff --git a/server/channels/api4/apitestlib.go b/server/channels/api4/apitestlib.go index fdc34d85b0..4eece6ac23 100644 --- a/server/channels/api4/apitestlib.go +++ b/server/channels/api4/apitestlib.go @@ -71,9 +71,10 @@ type TestHelper struct { IncludeCacheLayer bool - LogBuffer *mlog.Buffer - TestLogger *mlog.Logger - boardsProductEnvValue string + LogBuffer *mlog.Buffer + TestLogger *mlog.Logger + boardsProductEnvValue string + playbooksDisableEnvValue string } var mainHelper *testlib.MainHelper @@ -316,6 +317,11 @@ func SetupConfigWithStoreMock(tb testing.TB, updateConfig func(cfg *model.Config } func SetupWithStoreMock(tb testing.TB) *TestHelper { + // disable Playbooks (temporarily) as it causes many more mocked methods to get + // called, and cannot receieve a mocked database. Boards is already disabled here. + playbooksDisableEnvValue := os.Getenv("MM_DISABLE_PLAYBOOKS") + os.Setenv("MM_DISABLE_PLAYBOOKS", "true") + th := setupTestHelper(testlib.GetMockStoreForSetupFunctions(), nil, false, false, nil, nil) statusMock := mocks.StatusStore{} statusMock.On("UpdateExpiredDNDStatuses").Return([]*model.Status{}, nil) @@ -326,6 +332,8 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper { emptyMockStore.On("Close").Return(nil) emptyMockStore.On("Status").Return(&statusMock) th.App.Srv().SetStore(&emptyMockStore) + + th.playbooksDisableEnvValue = playbooksDisableEnvValue return th } @@ -379,11 +387,17 @@ func (th *TestHelper) ShutdownApp() { } func (th *TestHelper) TearDown() { - // reset board product setting to original + // reset board and playbooks product setting to original if th.boardsProductEnvValue != "" { os.Setenv("MM_FEATUREFLAGS_BoardsProduct", th.boardsProductEnvValue) } + if th.playbooksDisableEnvValue != "" { + os.Setenv("MM_DISABLE_PLAYBOOKS", th.playbooksDisableEnvValue) + } else { + os.Unsetenv("MM_DISABLE_PLAYBOOKS") + } + if th.IncludeCacheLayer { // Clean all the caches th.App.Srv().InvalidateAllCaches() diff --git a/server/channels/web/web_test.go b/server/channels/web/web_test.go index 9d23ada5af..dbf2864237 100644 --- a/server/channels/web/web_test.go +++ b/server/channels/web/web_test.go @@ -49,7 +49,8 @@ type TestHelper struct { TestLogger *mlog.Logger - boardsProductEnvValue string + boardsProductEnvValue string + playbooksDisableEnvValue string } func SetupWithStoreMock(tb testing.TB) *TestHelper { @@ -57,10 +58,17 @@ func SetupWithStoreMock(tb testing.TB) *TestHelper { tb.SkipNow() } + // disable Playbooks (temporarily) as it causes many more mocked methods to get + // called, and cannot receieve a mocked database. Boards is already disabled here. + playbooksDisableEnvValue := os.Getenv("MM_DISABLE_PLAYBOOKS") + os.Setenv("MM_DISABLE_PLAYBOOKS", "true") + th := setupTestHelper(tb, false) emptyMockStore := mocks.Store{} emptyMockStore.On("Close").Return(nil) th.App.Srv().SetStore(&emptyMockStore) + + th.playbooksDisableEnvValue = playbooksDisableEnvValue return th } @@ -187,11 +195,17 @@ func (th *TestHelper) InitBasic() *TestHelper { } func (th *TestHelper) TearDown() { - // reset board product setting to original + // reset board and playbooks product setting to original if th.boardsProductEnvValue != "" { os.Setenv("MM_FEATUREFLAGS_BoardsProduct", th.boardsProductEnvValue) } + if th.playbooksDisableEnvValue != "" { + os.Setenv("MM_DISABLE_PLAYBOOKS", th.playbooksDisableEnvValue) + } else { + os.Unsetenv("MM_DISABLE_PLAYBOOKS") + } + if th.IncludeCacheLayer { // Clean all the caches th.App.Srv().InvalidateAllCaches()