Centralize the GetPackagePath (#27004)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e96db725ea
Коммит
cd51dec6e5
@@ -16,7 +16,6 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -32,9 +31,8 @@ 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/app/plugin_api_tests"
|
||||
"github.com/mattermost/mattermost/server/v8"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces/mocks"
|
||||
"github.com/mattermost/mattermost/server/v8/tests"
|
||||
)
|
||||
|
||||
func getDefaultPluginSettingsSchema() string {
|
||||
@@ -858,7 +856,7 @@ func TestPluginAPILoadPluginConfiguration(t *testing.T) {
|
||||
cfg.PluginSettings.Plugins["testloadpluginconfig"] = pluginJson
|
||||
})
|
||||
|
||||
fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_load_configuration_plugin", "main.go")
|
||||
fullPath := filepath.Join(server.GetPackagePath(), "channels", "app", "plugin_api_tests", "manual.test_load_configuration_plugin", "main.go")
|
||||
|
||||
err = pluginAPIHookTest(t, th, fullPath, "testloadpluginconfig", `{"id": "testloadpluginconfig", "server": {"executable": "backend.exe"}, "settings_schema": {
|
||||
"settings": [
|
||||
@@ -891,7 +889,7 @@ func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) {
|
||||
cfg.PluginSettings.Plugins["testloadpluginconfig"] = pluginJson
|
||||
})
|
||||
|
||||
fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_load_configuration_defaults_plugin", "main.go")
|
||||
fullPath := filepath.Join(server.GetPackagePath(), "channels", "app", "plugin_api_tests", "manual.test_load_configuration_defaults_plugin", "main.go")
|
||||
|
||||
err = pluginAPIHookTest(t, th, fullPath, "testloadpluginconfig", `{
|
||||
"settings": [
|
||||
@@ -979,7 +977,7 @@ func TestPluginAPIInstallPlugin(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
api := th.SetupPluginAPI()
|
||||
|
||||
tarData, err := os.ReadFile(filepath.Join(tests.GetPackagePath(), "testplugin.tar.gz"))
|
||||
tarData, err := os.ReadFile(filepath.Join(server.GetPackagePath(), "tests", "testplugin.tar.gz"))
|
||||
require.NoError(t, err)
|
||||
|
||||
_, appErr := api.InstallPlugin(bytes.NewReader(tarData), true)
|
||||
@@ -1055,7 +1053,7 @@ func TestInstallPlugin(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// start an http server to serve plugin's tarball to the test.
|
||||
ts := httptest.NewServer(http.FileServer(http.Dir(tests.GetPackagePath())))
|
||||
ts := httptest.NewServer(http.FileServer(http.Dir(filepath.Join(server.GetPackagePath(), "tests"))))
|
||||
defer ts.Close()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
@@ -1253,14 +1251,14 @@ func pluginAPIHookTest(t *testing.T, th *TestHelper, fileName string, id string,
|
||||
|
||||
func TestBasicAPIPlugins(t *testing.T) {
|
||||
defaultSchema := getDefaultPluginSettingsSchema()
|
||||
testFolder := plugin_api_tests.GetPackagePath()
|
||||
testFolder := filepath.Join(server.GetPackagePath(), "channels", "app", "plugin_api_tests")
|
||||
dirs, err := os.ReadDir(testFolder)
|
||||
require.NoError(t, err, "Cannot read test folder %v", testFolder)
|
||||
for _, dir := range dirs {
|
||||
d := dir.Name()
|
||||
if dir.IsDir() && !strings.HasPrefix(d, "manual.") {
|
||||
t.Run(d, func(t *testing.T) {
|
||||
mainPath := path.Join(testFolder, d, "main.go")
|
||||
mainPath := filepath.Join(testFolder, d, "main.go")
|
||||
_, err := os.Stat(mainPath)
|
||||
require.NoError(t, err, "Cannot find plugin main file at %v", mainPath)
|
||||
th := Setup(t).InitBasic().DeleteBots()
|
||||
@@ -1838,7 +1836,7 @@ func TestPluginHTTPConnHijack(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_http_hijack_plugin", "main.go")
|
||||
fullPath := filepath.Join(server.GetPackagePath(), "channels", "app", "plugin_api_tests", "manual.test_http_hijack_plugin", "main.go")
|
||||
|
||||
pluginCode, err := os.ReadFile(fullPath)
|
||||
require.NoError(t, err)
|
||||
@@ -1871,7 +1869,7 @@ func TestPluginHTTPUpgradeWebSocket(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_http_upgrade_websocket_plugin", "main.go")
|
||||
fullPath := filepath.Join(server.GetPackagePath(), "channels", "app", "plugin_api_tests", "manual.test_http_upgrade_websocket_plugin", "main.go")
|
||||
|
||||
pluginCode, err := os.ReadFile(fullPath)
|
||||
require.NoError(t, err)
|
||||
@@ -2418,7 +2416,7 @@ func TestPluginServeMetrics(t *testing.T) {
|
||||
cfg.MetricsSettings.ListenAddress = prevAddress
|
||||
})
|
||||
|
||||
fullPath := path.Join(plugin_api_tests.GetPackagePath(), "manual.test_serve_metrics_plugin", "main.go")
|
||||
fullPath := filepath.Join(server.GetPackagePath(), "channels", "app", "plugin_api_tests", "manual.test_serve_metrics_plugin", "main.go")
|
||||
|
||||
pluginCode, err := os.ReadFile(fullPath)
|
||||
require.NoError(t, err)
|
||||
|
||||
Ссылка в новой задаче
Block a user