MM-31082: Use a base path for test assets (#16478)
* MM-31082: Use a base path for test assets Tests can be run from other tools using a different base path. We need to respect the MM_SERVER_PATH variable for that. https://mattermost.atlassian.net/browse/MM-31082 ```release-note NONE ``` * do not append mattermost-server if env var is set * fix typo
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f4cbecea81
Коммит
d137cf0aa5
@@ -9,6 +9,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
@@ -139,14 +140,28 @@ func (h *MainHelper) setupResources() {
|
||||
func (h *MainHelper) PreloadMigrations() {
|
||||
var buf []byte
|
||||
var err error
|
||||
basePath := os.Getenv("MM_SERVER_PATH")
|
||||
relPath := "testlib/testdata"
|
||||
switch *h.Settings.DriverName {
|
||||
case model.DATABASE_DRIVER_POSTGRES:
|
||||
buf, err = ioutil.ReadFile("mattermost-server/testlib/testdata/postgres_migration_warmup.sql")
|
||||
var finalPath string
|
||||
if basePath != "" {
|
||||
finalPath = filepath.Join(basePath, relPath, "postgres_migration_warmup.sql")
|
||||
} else {
|
||||
finalPath = filepath.Join("mattermost-server", relPath, "postgres_migration_warmup.sql")
|
||||
}
|
||||
buf, err = ioutil.ReadFile(finalPath)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot read file: %v", err))
|
||||
}
|
||||
case model.DATABASE_DRIVER_MYSQL:
|
||||
buf, err = ioutil.ReadFile("mattermost-server/testlib/testdata/mysql_migration_warmup.sql")
|
||||
var finalPath string
|
||||
if basePath != "" {
|
||||
finalPath = filepath.Join(basePath, relPath, "mysql_migration_warmup.sql")
|
||||
} else {
|
||||
finalPath = filepath.Join("mattermost-server", relPath, "mysql_migration_warmup.sql")
|
||||
}
|
||||
buf, err = ioutil.ReadFile(finalPath)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot read file: %v", err))
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user