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"
|
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
|
|
|
|
2021-08-24 12:13:58 +02:00
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/filestore/mocks"
|
2021-08-25 22:08:01 +02:00
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
2021-05-26 12:38:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type TestHelper struct {
|
2021-08-25 22:08:01 +02:00
|
|
|
App *App
|
|
|
|
Store *mockstore.MockStore
|
|
|
|
logger *mlog.Logger
|
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)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
cfg := config.Configuration{}
|
|
|
|
store := mockstore.NewMockStore(ctrl)
|
|
|
|
auth := auth.New(&cfg, store)
|
2021-08-25 22:08:01 +02:00
|
|
|
logger := mlog.CreateConsoleTestLogger(false, mlog.LvlDebug)
|
2021-05-26 12:38:43 +02:00
|
|
|
sessionToken := "TESTTOKEN"
|
2021-05-29 08:23:10 +02:00
|
|
|
wsserver := ws.NewServer(auth, sessionToken, false, logger)
|
|
|
|
webhook := webhook.NewClient(&cfg, logger)
|
2021-06-04 16:38:49 +02:00
|
|
|
metricsService := metrics.NewMetrics(metrics.InstanceInfo{})
|
|
|
|
|
2021-06-11 14:24:51 +02:00
|
|
|
appServices := Services{
|
2021-06-04 16:38:49 +02:00
|
|
|
Auth: auth,
|
|
|
|
Store: store,
|
|
|
|
FilesBackend: &mocks.FileBackend{},
|
|
|
|
Webhook: webhook,
|
|
|
|
Metrics: metricsService,
|
|
|
|
Logger: logger,
|
|
|
|
}
|
|
|
|
app2 := New(&cfg, wsserver, appServices)
|
2021-05-26 12:38:43 +02:00
|
|
|
|
2021-08-25 22:08:01 +02:00
|
|
|
tearDown := func() {
|
|
|
|
if logger != nil {
|
|
|
|
_ = logger.Shutdown()
|
|
|
|
}
|
2021-05-26 12:38:43 +02:00
|
|
|
}
|
2021-08-25 22:08:01 +02:00
|
|
|
|
|
|
|
return &TestHelper{
|
|
|
|
App: app2,
|
|
|
|
Store: store,
|
|
|
|
logger: logger,
|
|
|
|
}, tearDown
|
2021-05-26 12:38:43 +02:00
|
|
|
}
|