Этот коммит содержится в:
Jesse Hallam
2024-05-10 18:13:05 -03:00
коммит произвёл GitHub
родитель daf84488cc
Коммит 630bd40141
17 изменённых файлов: 95 добавлений и 91 удалений

Просмотреть файл

@@ -19,6 +19,7 @@ import (
"github.com/mattermost/mattermost/server/v8/channels/store/searchlayer"
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
"github.com/mattermost/mattermost/server/v8/channels/testlib/testdata"
"github.com/mattermost/mattermost/server/v8/channels/utils"
"github.com/mattermost/mattermost/server/v8/platform/services/searchengine"
)
@@ -195,25 +196,15 @@ func (h *MainHelper) PreloadMigrations() {
var buf []byte
var err error
basePath := os.Getenv("MM_SERVER_PATH")
if basePath == "" {
_, errFile := os.Stat("mattermost-server/server")
if os.IsNotExist(errFile) {
basePath = "mattermost/server"
} else {
basePath = "mattermost-server/server"
}
}
relPath := "channels/testlib/testdata"
switch *h.Settings.DriverName {
case model.DatabaseDriverPostgres:
finalPath := filepath.Join(basePath, relPath, "postgres_migration_warmup.sql")
finalPath := filepath.Join(testdata.GetPackagePath(), "postgres_migration_warmup.sql")
buf, err = os.ReadFile(finalPath)
if err != nil {
panic(fmt.Errorf("cannot read file: %v", err))
}
case model.DatabaseDriverMysql:
finalPath := filepath.Join(basePath, relPath, "mysql_migration_warmup.sql")
finalPath := filepath.Join(testdata.GetPackagePath(), "mysql_migration_warmup.sql")
buf, err = os.ReadFile(finalPath)
if err != nil {
panic(fmt.Errorf("cannot read file: %v", err))

Просмотреть файл

@@ -14,6 +14,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/utils"
"github.com/mattermost/mattermost/server/v8/channels/testlib/testdata"
"github.com/mattermost/mattermost/server/v8/channels/utils/fileutils"
"github.com/mattermost/mattermost/server/v8/platform/shared/filestore"
)
@@ -38,7 +39,11 @@ type testResourceDetails struct {
}
func findFile(path string) string {
return fileutils.FindPath(path, fileutils.CommonBaseSearchPaths(), func(fileInfo os.FileInfo) bool {
// Use the testdata path to search from the root of the monorepo.
searchPaths := fileutils.CommonBaseSearchPaths()
searchPaths = append(searchPaths, filepath.Join(testdata.GetPackagePath(), "../../../"))
return fileutils.FindPath(path, searchPaths, func(fileInfo os.FileInfo) bool {
return !fileInfo.IsDir()
})
}
@@ -53,7 +58,11 @@ func findDir(dir string) (string, bool) {
return path.Dir(srcPath), true
}
found := fileutils.FindPath(dir, fileutils.CommonBaseSearchPaths(), func(fileInfo os.FileInfo) bool {
// Use the testdata path to search from the root of the monorepo.
searchPaths := fileutils.CommonBaseSearchPaths()
searchPaths = append(searchPaths, filepath.Join(testdata.GetPackagePath(), "../../../"))
found := fileutils.FindPath(dir, searchPaths, func(fileInfo os.FileInfo) bool {
return fileInfo.IsDir()
})
if found == "" {

18
server/channels/testlib/testdata/path.go поставляемый Обычный файл
Просмотреть файл

@@ -0,0 +1,18 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package testdata
import (
"path/filepath"
"runtime"
)
// GetPackagePath returns the filepath to this package for in tests that need to read data here.
func GetPackagePath() string {
// Find the path to this file
_, filename, _, _ := runtime.Caller(0)
// Return the containing directory
return filepath.Dir(filename)
}