Fix GetPluginStatus in a non-cluster environment (#15363)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b0216053a1
Коммит
31e99920ef
@@ -70,10 +70,21 @@ func setDefaultPluginConfig(th *TestHelper, pluginId string) {
|
|||||||
func setupMultiPluginApiTest(t *testing.T, pluginCodes []string, pluginManifests []string, pluginIds []string, app *App) string {
|
func setupMultiPluginApiTest(t *testing.T, pluginCodes []string, pluginManifests []string, pluginIds []string, app *App) string {
|
||||||
pluginDir, err := ioutil.TempDir("", "")
|
pluginDir, err := ioutil.TempDir("", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
t.Cleanup(func() {
|
||||||
|
err = os.RemoveAll(pluginDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("Failed to cleanup pluginDir %s", err.Error())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
webappPluginDir, err := ioutil.TempDir("", "")
|
webappPluginDir, err := ioutil.TempDir("", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(pluginDir)
|
t.Cleanup(func() {
|
||||||
defer os.RemoveAll(webappPluginDir)
|
err = os.RemoveAll(webappPluginDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("Failed to cleanup webappPluginDir %s", err.Error())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
env, err := plugin.NewEnvironment(app.NewPluginAPI, pluginDir, webappPluginDir, app.Log(), nil)
|
env, err := plugin.NewEnvironment(app.NewPluginAPI, pluginDir, webappPluginDir, app.Log(), nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@@ -90,6 +101,12 @@ func setupMultiPluginApiTest(t *testing.T, pluginCodes []string, pluginManifests
|
|||||||
require.Nil(t, reterr)
|
require.Nil(t, reterr)
|
||||||
require.NotNil(t, manifest)
|
require.NotNil(t, manifest)
|
||||||
require.True(t, activated)
|
require.True(t, activated)
|
||||||
|
|
||||||
|
app.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
cfg.PluginSettings.PluginStates[pluginId] = &model.PluginState{
|
||||||
|
Enable: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
app.SetPluginsEnvironment(env)
|
app.SetPluginsEnvironment(env)
|
||||||
|
|||||||
39
app/plugin_api_tests/test_get_plugin_status_plugin/main.go
Обычный файл
39
app/plugin_api_tests/test_get_plugin_status_plugin/main.go
Обычный файл
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mattermost/mattermost-server/v5/app/plugin_api_tests"
|
||||||
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
|
"github.com/mattermost/mattermost-server/v5/plugin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MyPlugin struct {
|
||||||
|
plugin.MattermostPlugin
|
||||||
|
configuration plugin_api_tests.BasicConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MyPlugin) OnConfigurationChange() error {
|
||||||
|
if err := p.API.LoadPluginConfiguration(&p.configuration); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
|
||||||
|
status, err := p.API.GetPluginStatus("test_get_plugin_status_plugin")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
if status.State != model.PluginStateRunning {
|
||||||
|
return nil, "State is not running"
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
plugin.ClientMain(&MyPlugin{})
|
||||||
|
}
|
||||||
@@ -21,13 +21,17 @@ func (s *Server) GetPluginStatus(id string) (*model.PluginStatus, *model.AppErro
|
|||||||
return nil, model.NewAppError("GetPluginStatus", "app.plugin.get_statuses.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("GetPluginStatus", "app.plugin.get_statuses.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add our cluster ID
|
|
||||||
for _, status := range pluginStatuses {
|
for _, status := range pluginStatuses {
|
||||||
if status.PluginId == id && s.Cluster != nil {
|
if status.PluginId == id {
|
||||||
status.ClusterId = s.Cluster.GetClusterId()
|
// Add our cluster ID
|
||||||
|
if s.Cluster != nil {
|
||||||
|
status.ClusterId = s.Cluster.GetClusterId()
|
||||||
|
}
|
||||||
|
|
||||||
return status, nil
|
return status, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, model.NewAppError("GetPluginStatus", "app.plugin.not_installed.app_error", nil, "", http.StatusNotFound)
|
return nil, model.NewAppError("GetPluginStatus", "app.plugin.not_installed.app_error", nil, "", http.StatusNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user