diff --git a/server/Makefile b/server/Makefile index d9d2b4ec6db..e58c53e9c40 100644 --- a/server/Makefile +++ b/server/Makefile @@ -45,9 +45,6 @@ ifeq ($(BUILD_NUMBER),) BUILD_NUMBER := dev endif -# Ensure developer invocation and tests are anchored. -MM_SERVER_PATH ?= $(ROOT) - # Go test sum configuration GOTESTSUM_FORMAT ?= testname GOTESTSUM_JUNITFILE ?= report.xml @@ -425,7 +422,6 @@ else @echo Running only TE tests endif -test-server-race: export MM_SERVER_PATH := $(MM_SERVER_PATH) test-server-race: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT) test-server-race: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE) test-server-race: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE) @@ -444,7 +440,6 @@ ifneq ($(IS_CI),true) endif endif -test-server: export MM_SERVER_PATH := $(MM_SERVER_PATH) test-server: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT) test-server: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE) test-server: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE) @@ -459,7 +454,6 @@ ifneq ($(IS_CI),true) endif endif -test-server-ee: export MM_SERVER_PATH := $(MM_SERVER_PATH) test-server-ee: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT) test-server-ee: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE) test-server-ee: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE) @@ -467,7 +461,6 @@ test-server-ee: check-prereqs-enterprise start-docker gotestsum ## Runs EE tests @echo Running only EE tests $(GOBIN)/gotestsum --packages="$(EE_PACKAGES)" -- $(GOFLAGS) -timeout=20m -test-server-quick: export MM_SERVER_PATH := $(MM_SERVER_PATH) test-server-quick: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT) test-server-quick: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE) test-server-quick: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE) @@ -516,7 +509,6 @@ inject-test-data: # add test data to the local instance. @echo Login with a regular account username=user-1 password=SampleUs@r-1 @echo ======================================================================== -test-mmctl-unit: export MM_SERVER_PATH := $(MM_SERVER_PATH) test-mmctl-unit: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT) test-mmctl-unit: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE) test-mmctl-unit: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE) @@ -524,7 +516,6 @@ test-mmctl-unit: gotestsum @echo Running mmctl unit tests $(GOBIN)/gotestsum --packages="$(MMCTL_PACKAGES)" -- -tags 'unit $(MMCTL_BUILD_TAGS)' $(MMCTL_TESTFLAGS) -test-mmctl-e2e: export MM_SERVER_PATH := $(MM_SERVER_PATH) test-mmctl-e2e: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT) test-mmctl-e2e: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE) test-mmctl-e2e: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE) @@ -532,7 +523,6 @@ test-mmctl-e2e: gotestsum start-docker @echo Running mmctl e2e tests $(GOBIN)/gotestsum --packages="$(MMCTL_PACKAGES)" -- -tags 'e2e $(MMCTL_BUILD_TAGS)' $(MMCTL_TESTFLAGS) -test-mmctl: export MM_SERVER_PATH := $(MM_SERVER_PATH) test-mmctl: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT) test-mmctl: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE) test-mmctl: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE) @@ -540,7 +530,6 @@ test-mmctl: gotestsum start-docker @echo Running all mmctl tests $(GOBIN)/gotestsum --packages="$(MMCTL_PACKAGES)" -- -tags 'unit e2e $(MMCTL_BUILD_TAGS)' $(MMCTL_TESTFLAGS) -test-mmctl-coverage: export MM_SERVER_PATH := $(MM_SERVER_PATH) test-mmctl-coverage: export GOTESTSUM_FORMAT := $(GOTESTSUM_FORMAT) test-mmctl-coverage: export GOTESTSUM_JUNITFILE := $(GOTESTSUM_JUNITFILE) test-mmctl-coverage: export GOTESTSUM_JSONFILE := $(GOTESTSUM_JSONFILE) diff --git a/server/channels/api4/plugin_test.go b/server/channels/api4/plugin_test.go index 0c6b869f778..ec21c4dd9d5 100644 --- a/server/channels/api4/plugin_test.go +++ b/server/channels/api4/plugin_test.go @@ -27,6 +27,7 @@ import ( "github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/public/plugin" "github.com/mattermost/mattermost/server/public/plugin/utils" + "github.com/mattermost/mattermost/server/v8/channels/app/plugin_api_tests" "github.com/mattermost/mattermost/server/v8/channels/testlib" "github.com/mattermost/mattermost/server/v8/channels/utils/fileutils" ) @@ -1990,9 +1991,7 @@ func TestPluginWebSocketSession(t *testing.T) { pluginID := "com.mattermost.websocket_session_test" // Compile plugin - testFolder, found := fileutils.FindDir("channels/app/plugin_api_tests") - require.True(t, found, "Cannot find tests folder") - fullPath := path.Join(testFolder, "manual.test_websocket_session", "main.go") + fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_websocket_session", "main.go") pluginCode, err := os.ReadFile(fullPath) require.NoError(t, err) require.NotEmpty(t, pluginCode) diff --git a/server/channels/app/plugin_api_test.go b/server/channels/app/plugin_api_test.go index 5d2a86ad9c8..5748416e3e8 100644 --- a/server/channels/app/plugin_api_test.go +++ b/server/channels/app/plugin_api_test.go @@ -32,8 +32,9 @@ import ( "github.com/mattermost/mattermost/server/public/plugin/utils" "github.com/mattermost/mattermost/server/public/shared/i18n" "github.com/mattermost/mattermost/server/public/shared/request" - "github.com/mattermost/mattermost/server/v8/channels/utils/fileutils" + "github.com/mattermost/mattermost/server/v8/channels/app/plugin_api_tests" "github.com/mattermost/mattermost/server/v8/einterfaces/mocks" + "github.com/mattermost/mattermost/server/v8/tests" ) func getDefaultPluginSettingsSchema() string { @@ -802,9 +803,7 @@ func TestPluginAPILoadPluginConfiguration(t *testing.T) { cfg.PluginSettings.Plugins["testloadpluginconfig"] = pluginJson }) - testFolder, found := fileutils.FindDir("channels/app/plugin_api_tests") - require.True(t, found, "Cannot find tests folder") - fullPath := path.Join(testFolder, "manual.test_load_configuration_plugin", "main.go") + fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_load_configuration_plugin", "main.go") err = pluginAPIHookTest(t, th, fullPath, "testloadpluginconfig", `{"id": "testloadpluginconfig", "server": {"executable": "backend.exe"}, "settings_schema": { "settings": [ @@ -837,9 +836,7 @@ func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) { cfg.PluginSettings.Plugins["testloadpluginconfig"] = pluginJson }) - testFolder, found := fileutils.FindDir("channels/app/plugin_api_tests") - require.True(t, found, "Cannot find tests folder") - fullPath := path.Join(testFolder, "manual.test_load_configuration_defaults_plugin", "main.go") + fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_load_configuration_defaults_plugin", "main.go") err = pluginAPIHookTest(t, th, fullPath, "testloadpluginconfig", `{ "settings": [ @@ -927,8 +924,7 @@ func TestPluginAPIInstallPlugin(t *testing.T) { defer th.TearDown() api := th.SetupPluginAPI() - path, _ := fileutils.FindDir("tests") - tarData, err := os.ReadFile(filepath.Join(path, "testplugin.tar.gz")) + tarData, err := os.ReadFile(filepath.Join(tests.GetPackagePath(), "testplugin.tar.gz")) require.NoError(t, err) _, appErr := api.InstallPlugin(bytes.NewReader(tarData), true) @@ -1004,8 +1000,7 @@ func TestInstallPlugin(t *testing.T) { defer th.TearDown() // start an http server to serve plugin's tarball to the test. - path, _ := fileutils.FindDir("tests") - ts := httptest.NewServer(http.FileServer(http.Dir(path))) + ts := httptest.NewServer(http.FileServer(http.Dir(tests.GetPackagePath()))) defer ts.Close() th.App.UpdateConfig(func(cfg *model.Config) { @@ -1203,8 +1198,7 @@ func pluginAPIHookTest(t *testing.T, th *TestHelper, fileName string, id string, func TestBasicAPIPlugins(t *testing.T) { defaultSchema := getDefaultPluginSettingsSchema() - testFolder, found := fileutils.FindDir("channels/app/plugin_api_tests") - require.True(t, found, "Cannot read find app folder") + testFolder := plugin_api_tests.GetPackagePath() dirs, err := os.ReadDir(testFolder) require.NoError(t, err, "Cannot read test folder %v", testFolder) for _, dir := range dirs { @@ -1789,9 +1783,7 @@ func TestPluginHTTPConnHijack(t *testing.T) { th := Setup(t) defer th.TearDown() - testFolder, found := fileutils.FindDir("channels/app/plugin_api_tests") - require.True(t, found, "Cannot find tests folder") - fullPath := path.Join(testFolder, "manual.test_http_hijack_plugin", "main.go") + fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_http_hijack_plugin", "main.go") pluginCode, err := os.ReadFile(fullPath) require.NoError(t, err) @@ -1824,9 +1816,7 @@ func TestPluginHTTPUpgradeWebSocket(t *testing.T) { th := Setup(t) defer th.TearDown() - testFolder, found := fileutils.FindDir("channels/app/plugin_api_tests") - require.True(t, found, "Cannot find tests folder") - fullPath := path.Join(testFolder, "manual.test_http_upgrade_websocket_plugin", "main.go") + fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_http_upgrade_websocket_plugin", "main.go") pluginCode, err := os.ReadFile(fullPath) require.NoError(t, err) @@ -2373,9 +2363,7 @@ func TestPluginServeMetrics(t *testing.T) { cfg.MetricsSettings.ListenAddress = prevAddress }) - testFolder, found := fileutils.FindDir("channels/app/plugin_api_tests") - require.True(t, found, "Cannot find tests folder") - fullPath := path.Join(testFolder, "manual.test_serve_metrics_plugin", "main.go") + fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_serve_metrics_plugin", "main.go") pluginCode, err := os.ReadFile(fullPath) require.NoError(t, err) diff --git a/server/channels/app/plugin_api_tests/path.go b/server/channels/app/plugin_api_tests/path.go new file mode 100644 index 00000000000..94a8a6be508 --- /dev/null +++ b/server/channels/app/plugin_api_tests/path.go @@ -0,0 +1,18 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package plugin_api_tests + +import ( + "path/filepath" + "runtime" +) + +// GetPackagePath returns the filepath to this package for use 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) +} diff --git a/server/channels/app/server.go b/server/channels/app/server.go index ae937125f91..2630ab0aa5b 100644 --- a/server/channels/app/server.go +++ b/server/channels/app/server.go @@ -322,7 +322,7 @@ func NewServer(options ...Option) (*Server, error) { templatesDir, ok := templates.GetTemplateDirectory() if !ok { - return nil, errors.New("Failed find server templates in \"templates\" directory or MM_SERVER_PATH") + return nil, errors.New("Failed find server templates in \"templates\" directory") } htmlTemplateWatcher, errorsChan, err2 := templates.NewWithWatcher(templatesDir) if err2 != nil { diff --git a/server/channels/testlib/helper.go b/server/channels/testlib/helper.go index 3b849b2f4f3..b55756864cc 100644 --- a/server/channels/testlib/helper.go +++ b/server/channels/testlib/helper.go @@ -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)) diff --git a/server/channels/testlib/resources.go b/server/channels/testlib/resources.go index 022d8870f80..cb69abece67 100644 --- a/server/channels/testlib/resources.go +++ b/server/channels/testlib/resources.go @@ -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 == "" { diff --git a/server/channels/testlib/testdata/path.go b/server/channels/testlib/testdata/path.go new file mode 100644 index 00000000000..a3188ac9afd --- /dev/null +++ b/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) +} diff --git a/server/channels/utils/fileutils/fileutils.go b/server/channels/utils/fileutils/fileutils.go index 0fe5e4e729d..69a17ea943c 100644 --- a/server/channels/utils/fileutils/fileutils.go +++ b/server/channels/utils/fileutils/fileutils.go @@ -17,11 +17,6 @@ func CommonBaseSearchPaths() []string { "../../../..", } - // this enables the server to be used in tests from a different repository - if mmPath := os.Getenv("MM_SERVER_PATH"); mmPath != "" { - paths = append(paths, mmPath) - } - return paths } diff --git a/server/channels/utils/i18n.go b/server/channels/utils/i18n.go index 2162ae4ae4f..c3b6a91812e 100644 --- a/server/channels/utils/i18n.go +++ b/server/channels/utils/i18n.go @@ -5,8 +5,6 @@ package utils import ( "fmt" - "os" - "path/filepath" "github.com/mattermost/mattermost/server/public/shared/i18n" "github.com/mattermost/mattermost/server/v8/channels/utils/fileutils" @@ -16,9 +14,6 @@ import ( // loaded already and assigns english while loading server config. func TranslationsPreInit() error { translationsDir := "i18n" - if mattermostPath := os.Getenv("MM_SERVER_PATH"); mattermostPath != "" { - translationsDir = filepath.Join(mattermostPath, "i18n") - } i18nDirectory, found := fileutils.FindDirRelBinary(translationsDir) if !found { diff --git a/server/cmd/mmctl/commands/export_e2e_test.go b/server/cmd/mmctl/commands/export_e2e_test.go index 04d3913cd64..233584c61ec 100644 --- a/server/cmd/mmctl/commands/export_e2e_test.go +++ b/server/cmd/mmctl/commands/export_e2e_test.go @@ -11,6 +11,7 @@ import ( "github.com/mattermost/mattermost/server/v8/cmd/mmctl/client" "github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer" + "github.com/mattermost/mattermost/server/v8/tests" "github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/public/utils" @@ -19,9 +20,8 @@ import ( func (s *MmctlE2ETestSuite) TestExportListCmdF() { s.SetupTestHelper() - serverPath := os.Getenv("MM_SERVER_PATH") importName := "import_test.zip" - importFilePath := filepath.Join(serverPath, "tests", importName) + importFilePath := filepath.Join(tests.GetPackagePath(), importName) exportPath, err := filepath.Abs(filepath.Join(*s.th.App.Config().FileSettings.Directory, *s.th.App.Config().ExportSettings.Directory)) s.Require().Nil(err) @@ -72,9 +72,8 @@ func (s *MmctlE2ETestSuite) TestExportListCmdF() { func (s *MmctlE2ETestSuite) TestExportDeleteCmdF() { s.SetupTestHelper() - serverPath := os.Getenv("MM_SERVER_PATH") importName := "import_test.zip" - importFilePath := filepath.Join(serverPath, "tests", importName) + importFilePath := filepath.Join(tests.GetPackagePath(), importName) exportPath, err := filepath.Abs(filepath.Join(*s.th.App.Config().FileSettings.Directory, *s.th.App.Config().ExportSettings.Directory)) s.Require().Nil(err) @@ -179,9 +178,8 @@ func (s *MmctlE2ETestSuite) TestExportCreateCmdF() { func (s *MmctlE2ETestSuite) TestExportDownloadCmdF() { s.SetupTestHelper() - serverPath := os.Getenv("MM_SERVER_PATH") importName := "import_test.zip" - importFilePath := filepath.Join(serverPath, "tests", importName) + importFilePath := filepath.Join(tests.GetPackagePath(), importName) exportPath, err := filepath.Abs(filepath.Join(*s.th.App.Config().FileSettings.Directory, *s.th.App.Config().ExportSettings.Directory)) s.Require().Nil(err) diff --git a/server/cmd/mmctl/commands/extract_e2e_test.go b/server/cmd/mmctl/commands/extract_e2e_test.go index 983dcb30fd3..311183a6926 100644 --- a/server/cmd/mmctl/commands/extract_e2e_test.go +++ b/server/cmd/mmctl/commands/extract_e2e_test.go @@ -11,6 +11,7 @@ import ( "github.com/mattermost/mattermost/server/v8/cmd/mmctl/client" "github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer" + "github.com/mattermost/mattermost/server/v8/tests" "github.com/mattermost/mattermost/server/public/model" "github.com/spf13/cobra" @@ -18,9 +19,8 @@ import ( func (s *MmctlE2ETestSuite) TestExtractRunCmdF() { s.SetupTestHelper().InitBasic() - serverPath := os.Getenv("MM_SERVER_PATH") docName := "sample-doc.pdf" - docFilePath := filepath.Join(serverPath, "tests", docName) + docFilePath := filepath.Join(tests.GetPackagePath(), docName) s.Run("no permissions", func() { printer.Clean() diff --git a/server/cmd/mmctl/commands/import_e2e_test.go b/server/cmd/mmctl/commands/import_e2e_test.go index 9589bbc19cd..edf9a435f42 100644 --- a/server/cmd/mmctl/commands/import_e2e_test.go +++ b/server/cmd/mmctl/commands/import_e2e_test.go @@ -11,6 +11,7 @@ import ( "github.com/mattermost/mattermost/server/v8/cmd/mmctl/client" "github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer" + "github.com/mattermost/mattermost/server/v8/tests" "github.com/mattermost/mattermost/server/public/model" "github.com/spf13/cobra" @@ -18,9 +19,8 @@ import ( func (s *MmctlE2ETestSuite) TestImportUploadCmdF() { s.SetupTestHelper().InitBasic() - serverPath := os.Getenv("MM_SERVER_PATH") importName := "import_test.zip" - importFilePath := filepath.Join(serverPath, "tests", importName) + importFilePath := filepath.Join(tests.GetPackagePath(), importName) info, err := os.Stat(importFilePath) s.Require().NoError(err) @@ -91,9 +91,8 @@ func (s *MmctlE2ETestSuite) TestImportUploadCmdF() { func (s *MmctlE2ETestSuite) TestImportProcessCmdF() { s.SetupTestHelper().InitBasic() - serverPath := os.Getenv("MM_SERVER_PATH") importName := "import_test.zip" - importFilePath := filepath.Join(serverPath, "tests", importName) + importFilePath := filepath.Join(tests.GetPackagePath(), "import_test.zip") s.Run("no permissions", func() { printer.Clean() @@ -131,9 +130,8 @@ func (s *MmctlE2ETestSuite) TestImportProcessCmdF() { func (s *MmctlE2ETestSuite) TestImportListAvailableCmdF() { s.SetupTestHelper().InitBasic() - serverPath := os.Getenv("MM_SERVER_PATH") importName := "import_test.zip" - importFilePath := filepath.Join(serverPath, "tests", importName) + importFilePath := filepath.Join(tests.GetPackagePath(), importName) s.Run("no permissions", func() { printer.Clean() @@ -372,9 +370,8 @@ func (s *MmctlE2ETestSuite) TestImportJobListCmdF() { func (s *MmctlE2ETestSuite) TestImportValidateCmdF() { s.SetupTestHelper().InitBasic() - serverPath := os.Getenv("MM_SERVER_PATH") importName := "import_test.zip" - importFilePath := filepath.Join(serverPath, "tests", importName) + importFilePath := filepath.Join(tests.GetPackagePath(), importName) s.RunForSystemAdminAndLocal("defaults", func(c client.Client) { printer.Clean() diff --git a/server/cmd/mmctl/commands/plugin_e2e_test.go b/server/cmd/mmctl/commands/plugin_e2e_test.go index dee0f8d2cff..4186e529ec5 100644 --- a/server/cmd/mmctl/commands/plugin_e2e_test.go +++ b/server/cmd/mmctl/commands/plugin_e2e_test.go @@ -5,7 +5,6 @@ package commands import ( "fmt" - "os" "github.com/hashicorp/go-multierror" "github.com/mattermost/mattermost/server/public/model" @@ -17,12 +16,13 @@ import ( "github.com/mattermost/mattermost/server/v8/cmd/mmctl/client" "github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer" + "github.com/mattermost/mattermost/server/v8/tests" ) func (s *MmctlE2ETestSuite) TestPluginAddCmd() { s.SetupTestHelper().InitBasic() - pluginPath := filepath.Join(os.Getenv("MM_SERVER_PATH"), "tests", "testplugin.tar.gz") + pluginPath := filepath.Join(tests.GetPackagePath(), "testplugin.tar.gz") s.RunForSystemAdminAndLocal("add an already installed plugin without force", func(c client.Client) { printer.Clean() diff --git a/server/platform/shared/templates/templates.go b/server/platform/shared/templates/templates.go index c440136a9a5..949a8ab2712 100644 --- a/server/platform/shared/templates/templates.go +++ b/server/platform/shared/templates/templates.go @@ -7,7 +7,6 @@ import ( "bytes" "html/template" "io" - "os" "path/filepath" "sync" @@ -33,12 +32,7 @@ type Data struct { } func GetTemplateDirectory() (string, bool) { - templatesDir := "templates" - if mattermostPath := os.Getenv("MM_SERVER_PATH"); mattermostPath != "" { - templatesDir = filepath.Join(mattermostPath, templatesDir) - } - - return fileutils.FindDir(templatesDir) + return fileutils.FindDir("templates") } // NewFromTemplates creates a new templates container using a diff --git a/server/public/utils/fileutils.go b/server/public/utils/fileutils.go index 2418bc2f6ee..3832a8aac75 100644 --- a/server/public/utils/fileutils.go +++ b/server/public/utils/fileutils.go @@ -17,11 +17,6 @@ func CommonBaseSearchPaths() []string { "../../../..", } - // this enables the server to be used in tests from a different repository - if mmPath := os.Getenv("MM_SERVER_PATH"); mmPath != "" { - paths = append(paths, mmPath) - } - return paths } diff --git a/server/tests/path.go b/server/tests/path.go new file mode 100644 index 00000000000..850fb1ab0d5 --- /dev/null +++ b/server/tests/path.go @@ -0,0 +1,18 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +package tests + +import ( + "path/filepath" + "runtime" +) + +// GetPackagePath returns the filepath to this package for use 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) +}