Store plugin OnActivate errors and include them in PluginStatus response (#20430)

* store plugin OnActivate errors, and include in PluginStatus

* write test

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Michael Kochell
2022-07-21 10:55:57 -04:00
коммит произвёл GitHub
родитель 638ee68935
Коммит bc7f961d75
3 изменённых файлов: 65 добавлений и 0 удалений

Просмотреть файл

@@ -770,6 +770,44 @@ func TestPluginPanicLogs(t *testing.T) {
})
}
func TestPluginStatusActivateError(t *testing.T) {
t.Run("should return error from OnActivate in plugin statuses", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
pluginSource := `
package main
import (
"errors"
"github.com/mattermost/mattermost-server/v6/plugin"
)
type MyPlugin struct {
plugin.MattermostPlugin
}
func (p *MyPlugin) OnActivate() error {
return errors.New("sample error")
}
func main() {
plugin.ClientMain(&MyPlugin{})
}
`
tearDown, _, _ := SetAppEnvironmentWithPlugins(t, []string{pluginSource}, th.App, th.NewPluginAPI)
defer tearDown()
env := th.App.GetPluginsEnvironment()
pluginStatus, err := env.Statuses()
require.NoError(t, err)
require.Len(t, pluginStatus, 1)
require.Equal(t, "sample error", pluginStatus[0].Error)
})
}
func TestProcessPrepackagedPlugins(t *testing.T) {
th := Setup(t)
defer th.TearDown()