2021-05-26 12:38:43 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
|
|
|
|
"github.com/mattermost/focalboard/server/auth"
|
|
|
|
"github.com/mattermost/focalboard/server/services/config"
|
2021-06-04 16:38:49 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/metrics"
|
2023-02-14 18:17:33 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/permissions/mmpermissions"
|
|
|
|
mmpermissionsMocks "github.com/mattermost/focalboard/server/services/permissions/mmpermissions/mocks"
|
|
|
|
permissionsMocks "github.com/mattermost/focalboard/server/services/permissions/mocks"
|
2021-05-26 12:38:43 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/store/mockstore"
|
|
|
|
"github.com/mattermost/focalboard/server/services/webhook"
|
|
|
|
"github.com/mattermost/focalboard/server/ws"
|
2021-05-29 08:23:10 +02:00
|
|
|
|
2024-06-07 20:00:08 +02:00
|
|
|
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
|
|
|
"github.com/mattermost/mattermost/server/v8/platform/shared/filestore/mocks"
|
2021-05-26 12:38:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type TestHelper struct {
|
2022-03-31 00:10:11 +02:00
|
|
|
App *App
|
|
|
|
Store *mockstore.MockStore
|
|
|
|
FilesBackend *mocks.FileBackend
|
2022-07-18 19:21:57 +02:00
|
|
|
logger mlog.LoggerIFace
|
2023-02-14 18:17:33 +02:00
|
|
|
API *mmpermissionsMocks.MockAPI
|
2021-05-26 12:38:43 +02:00
|
|
|
}
|
|
|
|
|
2021-08-25 22:08:01 +02:00
|
|
|
func SetupTestHelper(t *testing.T) (*TestHelper, func()) {
|
2021-05-26 12:38:43 +02:00
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
cfg := config.Configuration{}
|
|
|
|
store := mockstore.NewMockStore(ctrl)
|
2022-03-31 00:10:11 +02:00
|
|
|
filesBackend := &mocks.FileBackend{}
|
2022-03-22 16:24:34 +02:00
|
|
|
auth := auth.New(&cfg, store, nil)
|
2024-06-07 20:00:08 +02:00
|
|
|
logger, _ := mlog.NewLogger()
|
2021-05-26 12:38:43 +02:00
|
|
|
sessionToken := "TESTTOKEN"
|
2022-03-22 16:24:34 +02:00
|
|
|
wsserver := ws.NewServer(auth, sessionToken, false, logger, store)
|
2021-05-29 08:23:10 +02:00
|
|
|
webhook := webhook.NewClient(&cfg, logger)
|
2021-06-04 16:38:49 +02:00
|
|
|
metricsService := metrics.NewMetrics(metrics.InstanceInfo{})
|
|
|
|
|
2023-02-14 18:17:33 +02:00
|
|
|
mockStore := permissionsMocks.NewMockStore(ctrl)
|
|
|
|
mockAPI := mmpermissionsMocks.NewMockAPI(ctrl)
|
2024-06-07 20:00:08 +02:00
|
|
|
permissions := mmpermissions.New(mockStore, mockAPI, mlog.CreateConsoleTestLogger(t))
|
2023-02-14 18:17:33 +02:00
|
|
|
|
2021-06-11 14:24:51 +02:00
|
|
|
appServices := Services{
|
2022-02-02 20:25:06 +02:00
|
|
|
Auth: auth,
|
|
|
|
Store: store,
|
2022-03-31 00:10:11 +02:00
|
|
|
FilesBackend: filesBackend,
|
2022-02-02 20:25:06 +02:00
|
|
|
Webhook: webhook,
|
|
|
|
Metrics: metricsService,
|
|
|
|
Logger: logger,
|
|
|
|
SkipTemplateInit: true,
|
2023-02-14 18:17:33 +02:00
|
|
|
Permissions: permissions,
|
2021-06-04 16:38:49 +02:00
|
|
|
}
|
|
|
|
app2 := New(&cfg, wsserver, appServices)
|
2021-05-26 12:38:43 +02:00
|
|
|
|
2021-08-25 22:08:01 +02:00
|
|
|
tearDown := func() {
|
2022-03-22 16:24:34 +02:00
|
|
|
app2.Shutdown()
|
2021-08-25 22:08:01 +02:00
|
|
|
if logger != nil {
|
|
|
|
_ = logger.Shutdown()
|
|
|
|
}
|
2021-05-26 12:38:43 +02:00
|
|
|
}
|
2021-08-25 22:08:01 +02:00
|
|
|
|
|
|
|
return &TestHelper{
|
2022-03-31 00:10:11 +02:00
|
|
|
App: app2,
|
|
|
|
Store: store,
|
|
|
|
FilesBackend: filesBackend,
|
|
|
|
logger: logger,
|
2023-02-14 18:17:33 +02:00
|
|
|
API: mockAPI,
|
2021-08-25 22:08:01 +02:00
|
|
|
}, tearDown
|
2021-05-26 12:38:43 +02:00
|
|
|
}
|