From cbba2f1ccacd47eda6785a0a3f17c849e401eb79 Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Fri, 13 Aug 2021 19:41:32 +0200 Subject: [PATCH] [MM-37664] Remove deprecated Backend field from plugin manifest (#18064) --- app/integration_action_test.go | 6 ++-- app/plugin_api_test.go | 12 +++---- app/plugin_hooks_test.go | 4 +-- app/post_test.go | 4 +-- model/manifest.go | 10 +----- model/manifest_test.go | 60 ---------------------------------- plugin/health_check_test.go | 4 +-- plugin/supervisor_test.go | 6 ++-- 8 files changed, 19 insertions(+), 87 deletions(-) diff --git a/app/integration_action_test.go b/app/integration_action_test.go index f4c77cfcd8..b41830ba3c 100644 --- a/app/integration_action_test.go +++ b/app/integration_action_test.go @@ -559,7 +559,7 @@ func TestSubmitInteractiveDialog(t *testing.T) { func main() { plugin.ClientMain(&MyPlugin{}) } - `, `{"id": "myplugin", "backend": {"executable": "backend.exe"}}`, "myplugin", th.App, th.Context) + `, `{"id": "myplugin", "server": {"executable": "backend.exe"}}`, "myplugin", th.App, th.Context) hooks, err2 := th.App.GetPluginsEnvironment().HooksForPlugin("myplugin") require.NoError(t, err2) @@ -841,7 +841,7 @@ func TestPostActionRelativePluginURL(t *testing.T) { func main() { plugin.ClientMain(&MyPlugin{}) } - `, `{"id": "myplugin", "backend": {"executable": "backend.exe"}}`, "myplugin", th.App, th.Context) + `, `{"id": "myplugin", "server": {"executable": "backend.exe"}}`, "myplugin", th.App, th.Context) hooks, err2 := th.App.GetPluginsEnvironment().HooksForPlugin("myplugin") require.NoError(t, err2) @@ -1060,7 +1060,7 @@ func TestDoPluginRequest(t *testing.T) { func main() { plugin.ClientMain(&MyPlugin{}) } - `, `{"id": "myplugin", "backend": {"executable": "backend.exe"}}`, "myplugin", th.App, th.Context) + `, `{"id": "myplugin", "server": {"executable": "backend.exe"}}`, "myplugin", th.App, th.Context) hooks, err2 := th.App.GetPluginsEnvironment().HooksForPlugin("myplugin") require.NoError(t, err2) diff --git a/app/plugin_api_test.go b/app/plugin_api_test.go index 3d9a8f24d7..09d8d9b0f3 100644 --- a/app/plugin_api_test.go +++ b/app/plugin_api_test.go @@ -691,7 +691,7 @@ func TestPluginAPILoadPluginConfiguration(t *testing.T) { require.True(t, found, "Cannot find tests folder") fullPath := path.Join(testFolder, "manual.test_load_configuration_plugin", "main.go") - err = pluginAPIHookTest(t, th, fullPath, "testloadpluginconfig", `{"id": "testloadpluginconfig", "backend": {"executable": "backend.exe"}, "settings_schema": { + err = pluginAPIHookTest(t, th, fullPath, "testloadpluginconfig", `{"id": "testloadpluginconfig", "server": {"executable": "backend.exe"}, "settings_schema": { "settings": [ { "key": "MyStringSetting", @@ -950,7 +950,7 @@ func TestInstallPlugin(t *testing.T) { } `, - `{"id": "testinstallplugin", "backend": {"executable": "backend.exe"}, "settings_schema": { + `{"id": "testinstallplugin", "server": {"executable": "backend.exe"}, "settings_schema": { "settings": [ { "key": "DownloadURL", @@ -1068,7 +1068,7 @@ func pluginAPIHookTest(t *testing.T, th *TestHelper, fileName string, id string, } th.App.srv.sqlStore = th.GetSqlStore() setupPluginApiTest(t, code, - fmt.Sprintf(`{"id": "%v", "backend": {"executable": "backend.exe"}, "settings_schema": %v}`, id, schema), + fmt.Sprintf(`{"id": "%v", "server": {"executable": "backend.exe"}, "settings_schema": %v}`, id, schema), id, th.App, th.Context) hooks, err := th.App.GetPluginsEnvironment().HooksForPlugin(id) require.NoError(t, err) @@ -1511,8 +1511,8 @@ func TestInterpluginPluginHTTP(t *testing.T) { `, }, []string{ - `{"id": "testplugininterserver", "backend": {"executable": "backend.exe"}}`, - `{"id": "testplugininterclient", "backend": {"executable": "backend.exe"}}`, + `{"id": "testplugininterserver", "server": {"executable": "backend.exe"}}`, + `{"id": "testplugininterclient", "server": {"executable": "backend.exe"}}`, }, []string{ "testplugininterserver", @@ -1573,7 +1573,7 @@ func TestApiMetrics(t *testing.T) { } ` utils.CompileGo(t, code, backend) - ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(`{"id": "`+pluginID+`", "backend": {"executable": "backend.exe"}}`), 0600) + ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(`{"id": "`+pluginID+`", "server": {"executable": "backend.exe"}}`), 0600) // Don't care about these mocks metricsMock.On("ObservePluginHookDuration", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return() diff --git a/app/plugin_hooks_test.go b/app/plugin_hooks_test.go index 8beaa7ac3a..eb435e0f90 100644 --- a/app/plugin_hooks_test.go +++ b/app/plugin_hooks_test.go @@ -45,7 +45,7 @@ func SetAppEnvironmentWithPlugins(t *testing.T, pluginCode []string, app *App, a backend := filepath.Join(pluginDir, pluginID, "backend.exe") utils.CompileGo(t, code, backend) - ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(`{"id": "`+pluginID+`", "backend": {"executable": "backend.exe"}}`), 0600) + ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(`{"id": "`+pluginID+`", "server": {"executable": "backend.exe"}}`), 0600) _, _, activationErr := env.Activate(pluginID) pluginIDs = append(pluginIDs, pluginID) activationErrors = append(activationErrors, activationErr) @@ -1083,7 +1083,7 @@ func TestHookMetrics(t *testing.T) { } ` utils.CompileGo(t, code, backend) - ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(`{"id": "`+pluginID+`", "backend": {"executable": "backend.exe"}}`), 0600) + ioutil.WriteFile(filepath.Join(pluginDir, pluginID, "plugin.json"), []byte(`{"id": "`+pluginID+`", "server": {"executable": "backend.exe"}}`), 0600) // Setup mocks before activating metricsMock.On("ObservePluginHookDuration", pluginID, "Implemented", true, mock.Anything).Return() diff --git a/app/post_test.go b/app/post_test.go index f0a406c142..050ebe919a 100644 --- a/app/post_test.go +++ b/app/post_test.go @@ -78,7 +78,7 @@ func TestCreatePostDeduplicate(t *testing.T) { func main() { plugin.ClientMain(&MyPlugin{}) } - `, `{"id": "testrejectfirstpost", "backend": {"executable": "backend.exe"}}`, "testrejectfirstpost", th.App, th.Context) + `, `{"id": "testrejectfirstpost", "server": {"executable": "backend.exe"}}`, "testrejectfirstpost", th.App, th.Context) pendingPostId := model.NewId() post, err := th.App.CreatePostAsUser(th.Context, &model.Post{ @@ -128,7 +128,7 @@ func TestCreatePostDeduplicate(t *testing.T) { func main() { plugin.ClientMain(&MyPlugin{}) } - `, `{"id": "testdelayfirstpost", "backend": {"executable": "backend.exe"}}`, "testdelayfirstpost", th.App, th.Context) + `, `{"id": "testdelayfirstpost", "server": {"executable": "backend.exe"}}`, "testdelayfirstpost", th.App, th.Context) var post *model.Post pendingPostId := model.NewId() diff --git a/model/manifest.go b/model/manifest.go index e54549d1eb..fe5eee7854 100644 --- a/model/manifest.go +++ b/model/manifest.go @@ -176,9 +176,6 @@ type Manifest struct { // Server defines the server-side portion of your plugin. Server *ManifestServer `json:"server,omitempty" yaml:"server,omitempty"` - // Backend is a deprecated flag for defining the server-side portion of your plugin. Going forward, use Server instead. - Backend *ManifestServer `json:"backend,omitempty" yaml:"backend,omitempty"` - // If your plugin extends the web app, you'll need to define webapp. Webapp *ManifestWebapp `json:"webapp,omitempty" yaml:"webapp,omitempty"` @@ -278,11 +275,6 @@ func (m *Manifest) ClientManifest() *Manifest { func (m *Manifest) GetExecutableForRuntime(goOs, goArch string) string { server := m.Server - // Support the deprecated backend parameter. - if server == nil { - server = m.Backend - } - if server == nil { return "" } @@ -301,7 +293,7 @@ func (m *Manifest) GetExecutableForRuntime(goOs, goArch string) string { } func (m *Manifest) HasServer() bool { - return m.Server != nil || m.Backend != nil + return m.Server != nil } func (m *Manifest) HasWebapp() bool { diff --git a/model/manifest_test.go b/model/manifest_test.go index 68d6852cd0..43e4c0a668 100644 --- a/model/manifest_test.go +++ b/model/manifest_test.go @@ -707,44 +707,6 @@ func TestManifestGetExecutableForRuntime(t *testing.T) { "amd64", "path/to/executable", }, - { - "deprecated backend field, ignored since server present", - &Manifest{ - Server: &ManifestServer{ - Executables: map[string]string{ - "linux-amd64": "linux-amd64/path/to/executable", - "darwin-amd64": "darwin-amd64/path/to/executable", - "windows-amd64": "windows-amd64/path/to/executable", - "linux-arm64": "linux-arm64/path/to/executable", - }, - }, - Backend: &ManifestServer{ - Executables: map[string]string{ - "linux-amd64": "linux-amd64/path/to/executable", - "darwin-amd64": "darwin-amd64/path/to/executable", - "windows-amd64": "windows-amd64/path/to/executable", - }, - }, - }, - "linux", - "amd64", - "linux-amd64/path/to/executable", - }, - { - "deprecated backend field used, since no server present", - &Manifest{ - Backend: &ManifestServer{ - Executables: map[string]string{ - "linux-amd64": "linux-amd64/path/to/executable", - "darwin-amd64": "darwin-amd64/path/to/executable", - "windows-amd64": "windows-amd64/path/to/executable", - }, - }, - }, - "linux", - "amd64", - "linux-amd64/path/to/executable", - }, } for _, testCase := range testCases { @@ -798,28 +760,6 @@ func TestManifestHasServer(t *testing.T) { }, true, }, - { - "single executable defined via deprecated backend", - &Manifest{ - Backend: &ManifestServer{ - Executable: "path/to/executable", - }, - }, - true, - }, - { - "multiple executables defined via deprecated backend", - &Manifest{ - Backend: &ManifestServer{ - Executables: map[string]string{ - "linux-amd64": "linux-amd64/path/to/executable", - "darwin-amd64": "darwin-amd64/path/to/executable", - "windows-amd64": "windows-amd64/path/to/executable", - }, - }, - }, - true, - }, } for _, testCase := range testCases { diff --git a/plugin/health_check_test.go b/plugin/health_check_test.go index b5c5de8a54..12f8d95389 100644 --- a/plugin/health_check_test.go +++ b/plugin/health_check_test.go @@ -48,7 +48,7 @@ func testPluginHealthCheckSuccess(t *testing.T) { } `, backend) - err = ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "backend.exe"}}`), 0600) + err = ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "server": {"executable": "backend.exe"}}`), 0600) require.NoError(t, err) bundle := model.BundleInfoForPath(dir) @@ -95,7 +95,7 @@ func testPluginHealthCheckPanic(t *testing.T) { } `, backend) - err = ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "backend.exe"}}`), 0600) + err = ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "server": {"executable": "backend.exe"}}`), 0600) require.NoError(t, err) bundle := model.BundleInfoForPath(dir) diff --git a/plugin/supervisor_test.go b/plugin/supervisor_test.go index 4492eb3b1a..9719b97eb6 100644 --- a/plugin/supervisor_test.go +++ b/plugin/supervisor_test.go @@ -32,7 +32,7 @@ func testSupervisorInvalidExecutablePath(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "/foo/../../backend.exe"}}`), 0600) + ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "server": {"executable": "/foo/../../backend.exe"}}`), 0600) bundle := model.BundleInfoForPath(dir) log := mlog.NewLogger(&mlog.LoggerConfiguration{ @@ -51,7 +51,7 @@ func testSupervisorNonExistentExecutablePath(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "thisfileshouldnotexist"}}`), 0600) + ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "server": {"executable": "thisfileshouldnotexist"}}`), 0600) bundle := model.BundleInfoForPath(dir) log := mlog.NewLogger(&mlog.LoggerConfiguration{ @@ -81,7 +81,7 @@ func testSupervisorStartTimeout(t *testing.T) { } `, backend) - ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "backend.exe"}}`), 0600) + ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "server": {"executable": "backend.exe"}}`), 0600) bundle := model.BundleInfoForPath(dir) log := mlog.NewLogger(&mlog.LoggerConfiguration{