mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
call OnActivate after plugin crash, update example (#7940)
This commit is contained in:
@@ -148,13 +148,9 @@ func (env *Environment) ActivatePlugin(id string) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to get api for plugin: %v", id)
|
||||
}
|
||||
if err := supervisor.Start(); err != nil {
|
||||
if err := supervisor.Start(api); err != nil {
|
||||
return errors.Wrapf(err, "unable to start plugin: %v", id)
|
||||
}
|
||||
if err := supervisor.Hooks().OnActivate(api); err != nil {
|
||||
supervisor.Stop()
|
||||
return errors.Wrapf(err, "unable to activate plugin: %v", id)
|
||||
}
|
||||
|
||||
activePlugin.Supervisor = supervisor
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ type MockSupervisor struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (m *MockSupervisor) Start() error {
|
||||
return m.Called().Error(0)
|
||||
func (m *MockSupervisor) Start(api plugin.API) error {
|
||||
return m.Called(api).Error(0)
|
||||
}
|
||||
|
||||
func (m *MockSupervisor) Stop() error {
|
||||
@@ -141,12 +141,10 @@ func TestEnvironment(t *testing.T) {
|
||||
provider.On("API").Return(&api, nil)
|
||||
provider.On("Supervisor").Return(&supervisor, nil)
|
||||
|
||||
supervisor.On("Start").Return(nil)
|
||||
supervisor.On("Start", &api).Return(nil)
|
||||
supervisor.On("Stop").Return(nil)
|
||||
supervisor.On("Hooks").Return(&hooks)
|
||||
|
||||
hooks.On("OnActivate", &api).Return(nil)
|
||||
|
||||
assert.NoError(t, env.ActivatePlugin("foo"))
|
||||
assert.Equal(t, env.ActivePluginIds(), []string{"foo"})
|
||||
activePlugins = env.ActivePlugins()
|
||||
@@ -238,17 +236,7 @@ func TestEnvironment_ActivatePluginErrors(t *testing.T) {
|
||||
provider.On("API").Return(&api, nil)
|
||||
provider.On("Supervisor").Return(&supervisor, nil)
|
||||
|
||||
supervisor.On("Start").Return(fmt.Errorf("test error"))
|
||||
},
|
||||
"HooksError": func() {
|
||||
provider.On("API").Return(&api, nil)
|
||||
provider.On("Supervisor").Return(&supervisor, nil)
|
||||
|
||||
supervisor.On("Start").Return(nil)
|
||||
supervisor.On("Stop").Return(nil)
|
||||
supervisor.On("Hooks").Return(&hooks)
|
||||
|
||||
hooks.On("OnActivate", &api).Return(fmt.Errorf("test error"))
|
||||
supervisor.On("Start", &api).Return(fmt.Errorf("test error"))
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
@@ -291,11 +279,10 @@ func TestEnvironment_ShutdownError(t *testing.T) {
|
||||
provider.On("API").Return(&api, nil)
|
||||
provider.On("Supervisor").Return(&supervisor, nil)
|
||||
|
||||
supervisor.On("Start").Return(nil)
|
||||
supervisor.On("Start", &api).Return(nil)
|
||||
supervisor.On("Stop").Return(fmt.Errorf("test error"))
|
||||
supervisor.On("Hooks").Return(&hooks)
|
||||
|
||||
hooks.On("OnActivate", &api).Return(nil)
|
||||
hooks.On("OnDeactivate").Return(fmt.Errorf("test error"))
|
||||
|
||||
assert.NoError(t, env.ActivatePlugin("foo"))
|
||||
@@ -329,13 +316,12 @@ func TestEnvironment_ConcurrentHookInvocations(t *testing.T) {
|
||||
provider.On("API").Return(&api, nil)
|
||||
provider.On("Supervisor").Return(&supervisor, nil)
|
||||
|
||||
supervisor.On("Start").Return(nil)
|
||||
supervisor.On("Start", &api).Return(nil)
|
||||
supervisor.On("Stop").Return(nil)
|
||||
supervisor.On("Hooks").Return(&hooks)
|
||||
|
||||
ch := make(chan bool)
|
||||
|
||||
hooks.On("OnActivate", &api).Return(nil)
|
||||
hooks.On("OnDeactivate").Return(nil)
|
||||
hooks.On("ServeHTTP", mock.AnythingOfType("*httptest.ResponseRecorder"), mock.AnythingOfType("*http.Request")).Run(func(args mock.Arguments) {
|
||||
r := args.Get(1).(*http.Request)
|
||||
|
||||
Reference in New Issue
Block a user