forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.go
69 lines (54 loc) · 1.66 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package testlib
import (
"flag"
"os"
"testing"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
"github.com/mattermost/mattermost-server/store/sqlstore"
"github.com/mattermost/mattermost-server/store/storetest"
"github.com/mattermost/mattermost-server/utils"
)
type MainHelper struct {
Settings *model.SqlSettings
Store store.Store
SqlSupplier *sqlstore.SqlSupplier
ClusterInterface *FakeClusterInterface
status int
}
func NewMainHelper() *MainHelper {
flag.Parse()
// Setup a global logger to catch tests logging outside of app context
// The global logger will be stomped by apps initalizing but that's fine for testing.
// Ideally this won't happen.
mlog.InitGlobalLogger(mlog.NewLogger(&mlog.LoggerConfiguration{
EnableConsole: true,
ConsoleJson: true,
ConsoleLevel: "error",
EnableFile: false,
}))
utils.TranslationsPreInit()
settings := storetest.MakeSqlSettings(model.DATABASE_DRIVER_MYSQL)
clusterInterface := &FakeClusterInterface{}
sqlSupplier := sqlstore.NewSqlSupplier(*settings, nil)
testStore := &TestStore{
store.NewLayeredStore(sqlSupplier, nil, clusterInterface),
}
return &MainHelper{
Settings: settings,
Store: testStore,
SqlSupplier: sqlSupplier,
ClusterInterface: clusterInterface,
}
}
func (h *MainHelper) Main(m *testing.M) {
h.status = m.Run()
}
func (h *MainHelper) Close() error {
storetest.CleanupSqlSettings(h.Settings)
os.Exit(h.status)
return nil
}