* MM-12083: unittest using externally managed database * cherry-pick Makefile changes from @cpanato * Jenkins changes (#9915) * add docker compose * udpate * when using minio dont need to set the region * update * add wait for it script * using old minio * add new jenkins file * update makefile * add dockerfile * rename the docker-compose proj to avoid colision (#9917) * rename the docker-compose proj to avoid colision * enable debug * enable debug to double checkt the branchs and fix docker-compose name (#9919) * add ee hash to check (#9920) * fix name (#9921) * update jenkins file to push from branch and prs * if a new push comes in stop the running build * split mysql and postgres variables * add script to run jenkins-like env in local dev env * update docker-compose project name to use uuid to make it more randon * fix DCNAME definition * update elasticsearch docker image * revert test * tidy up stages, and wait for mysql differently * update docker image and add check for postgres * checking if is ready * update docker compose to have a wait for deps * add readme and rename dockerfile * fix -unittest setup * using mm docker image * restore parallel unit tests at the package level Spin up a dedicated database for each package under test to avoid races in accessing the same tables. Simplify the interface for configuring the test database to just a DSN instead of multiple exports for each field. * try to work around root mysql access in CI * update local-test-env.sh too * MYSQL_ROOT_HOST: % * fix missing quotes * setting some memory limits for mysql * revert memory docker compose does not support * fix env name for postgres * expose errors in app/export_test.go * fix test label, better error checking on teardown * increase query timeout for tests * fix export_test * update local dev script * add configurable mysql root passwd
70 строки
1.7 KiB
Go
70 строки
1.7 KiB
Go
// 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
|
|
}
|