Dockerized build updated tests (#9943)
* testlib: introduce and leverage This doesn't yet factor out the individual test helpers: many packages still rely on `api4` directly to do this, but now wire up the test store setup through this package. `app` and `store`, in particular, don't use `testlib` because of circular dependencies at the moment. * cmd: command_test.go: use api4 testlib * cmd: plugin_test.go: remove dependence on test-config.json * cmd: config_test.go use configured database settings * ensure test-(te|ee) exit with status code * test-server: run all tests, deprecating test-te/test-ee * cmd/mattermost/commands: fix unit tests Instead of relying on (and modifying) a config.json found in the current path, explicitly create a temporary one from defaults for each test. This was likely the source of various bugs over time, but specifically allows us to override the SqlSettings to point at the configured test database for all tests simultaneously. * wrap run/check into a test helper It was insufficient to set a config for each invocation of CheckCommand or RunCommand: some tests relied on the config having changed in a subsequent assertion. Instead, create a new test helper embedding api4.TestHelper. This has the nice advantage of cleaning up all the teardown. * additional TestConfigGet granularity * customized config path to avoid default location * be explicit if the storetest initialization fails * generate safe coverprofile names in the presence of subtests * additional TestConfigShow granularity * fix permission_test.go typo * fix webhook tests * actually flag.Parse() to skip database setup on os.Execed tests * fix recent regression in #9962, not caught by unit tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2708ed6d1f
Коммит
d39d9a5caf
@@ -18,7 +18,7 @@ func handlerForHTTPErrors(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func TestHandlerServeHTTPErrors(t *testing.T) {
|
||||
s, err := app.NewServer(app.StoreOverride(testStore), app.DisableConfigWatch)
|
||||
s, err := app.NewServer(app.StoreOverride(mainHelper.Store), app.DisableConfigWatch)
|
||||
defer s.Shutdown()
|
||||
|
||||
web := New(s, s.AppOptions, s.Router)
|
||||
@@ -61,7 +61,7 @@ func handlerForHTTPSecureTransport(c *Context, w http.ResponseWriter, r *http.Re
|
||||
}
|
||||
|
||||
func TestHandlerServeHTTPSecureTransport(t *testing.T) {
|
||||
s, err := app.NewServer(app.StoreOverride(testStore), app.DisableConfigWatch)
|
||||
s, err := app.NewServer(app.StoreOverride(mainHelper.Store), app.DisableConfigWatch)
|
||||
defer s.Shutdown()
|
||||
|
||||
a := s.FakeApp()
|
||||
|
||||
19
web/main_test.go
Обычный файл
19
web/main_test.go
Обычный файл
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package web
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/testlib"
|
||||
)
|
||||
|
||||
var mainHelper *testlib.MainHelper
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
mainHelper = testlib.NewMainHelper()
|
||||
defer mainHelper.Close()
|
||||
|
||||
mainHelper.Main(m)
|
||||
}
|
||||
@@ -5,37 +5,15 @@ package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"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"
|
||||
)
|
||||
|
||||
var ApiClient *model.Client4
|
||||
var URL string
|
||||
|
||||
type persistentTestStore struct {
|
||||
store.Store
|
||||
}
|
||||
|
||||
func (*persistentTestStore) Close() {}
|
||||
|
||||
var testStoreContainer *storetest.RunningContainer
|
||||
var testStore *persistentTestStore
|
||||
|
||||
func StopTestStore() {
|
||||
if testStoreContainer != nil {
|
||||
testStoreContainer.Stop()
|
||||
testStoreContainer = nil
|
||||
}
|
||||
}
|
||||
|
||||
type TestHelper struct {
|
||||
App *app.App
|
||||
Server *app.Server
|
||||
@@ -48,7 +26,9 @@ type TestHelper struct {
|
||||
}
|
||||
|
||||
func Setup() *TestHelper {
|
||||
s, err := app.NewServer(app.StoreOverride(testStore), app.DisableConfigWatch)
|
||||
mainHelper.Store.DropAllTables()
|
||||
|
||||
s, err := app.NewServer(app.StoreOverride(mainHelper.Store), app.DisableConfigWatch)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -103,7 +83,6 @@ func (th *TestHelper) InitBasic() *TestHelper {
|
||||
func (th *TestHelper) TearDown() {
|
||||
th.Server.Shutdown()
|
||||
if err := recover(); err != nil {
|
||||
StopTestStore()
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -125,37 +104,6 @@ func TestStatic(t *testing.T) {
|
||||
}
|
||||
*/
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
// 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()
|
||||
|
||||
status := 0
|
||||
|
||||
container, settings, err := storetest.NewPostgreSQLContainer()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
testStoreContainer = container
|
||||
testStore = &persistentTestStore{store.NewLayeredStore(sqlstore.NewSqlSupplier(*settings, nil), nil, nil)}
|
||||
|
||||
defer func() {
|
||||
StopTestStore()
|
||||
os.Exit(status)
|
||||
}()
|
||||
|
||||
status = m.Run()
|
||||
|
||||
}
|
||||
|
||||
func TestCheckClientCompatability(t *testing.T) {
|
||||
//Browser Name, UA String, expected result (if the browser should fail the test false and if it should pass the true)
|
||||
type uaTest struct {
|
||||
|
||||
Ссылка в новой задаче
Block a user