Centralize the GetPackagePath (#27004)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e96db725ea
Коммит
cd51dec6e5
@@ -15,11 +15,11 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"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"
|
||||
)
|
||||
@@ -198,13 +198,13 @@ func (h *MainHelper) PreloadMigrations() {
|
||||
|
||||
switch *h.Settings.DriverName {
|
||||
case model.DatabaseDriverPostgres:
|
||||
finalPath := filepath.Join(testdata.GetPackagePath(), "postgres_migration_warmup.sql")
|
||||
finalPath := filepath.Join(server.GetPackagePath(), "channels", "testlib", "testdata", "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(testdata.GetPackagePath(), "mysql_migration_warmup.sql")
|
||||
finalPath := filepath.Join(server.GetPackagePath(), "channels", "testlib", "testdata", "mysql_migration_warmup.sql")
|
||||
buf, err = os.ReadFile(finalPath)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("cannot read file: %v", err))
|
||||
|
||||
@@ -14,7 +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"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils/fileutils"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/shared/filestore"
|
||||
)
|
||||
@@ -41,7 +41,7 @@ type testResourceDetails struct {
|
||||
func findFile(path string) string {
|
||||
// Use the testdata path to search from the root of the monorepo.
|
||||
searchPaths := fileutils.CommonBaseSearchPaths()
|
||||
searchPaths = append(searchPaths, filepath.Join(testdata.GetPackagePath(), "../../../"))
|
||||
searchPaths = append(searchPaths, filepath.Join(server.GetPackagePath(), "channels", "testlib", "testdata", "../../../"))
|
||||
|
||||
return fileutils.FindPath(path, searchPaths, func(fileInfo os.FileInfo) bool {
|
||||
return !fileInfo.IsDir()
|
||||
@@ -60,7 +60,7 @@ func findDir(dir string) (string, bool) {
|
||||
|
||||
// Use the testdata path to search from the root of the monorepo.
|
||||
searchPaths := fileutils.CommonBaseSearchPaths()
|
||||
searchPaths = append(searchPaths, filepath.Join(testdata.GetPackagePath(), "../../../"))
|
||||
searchPaths = append(searchPaths, filepath.Join(server.GetPackagePath(), "channels", "testlib", "testdata", "../../../"))
|
||||
|
||||
found := fileutils.FindPath(dir, searchPaths, func(fileInfo os.FileInfo) bool {
|
||||
return fileInfo.IsDir()
|
||||
|
||||
18
server/channels/testlib/testdata/path.go
поставляемый
18
server/channels/testlib/testdata/path.go
поставляемый
@@ -1,18 +0,0 @@
|
||||
// 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)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user