Differentiate between installed and activated states for plugins (#7706)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9c0575ce6e
Коммит
16b845c0d7
@@ -89,6 +89,20 @@ func (env *Environment) ActivePluginIds() (ids []string) {
|
||||
return
|
||||
}
|
||||
|
||||
// Returns true if the plugin is active, false otherwise.
|
||||
func (env *Environment) IsPluginActive(pluginId string) bool {
|
||||
env.mutex.RLock()
|
||||
defer env.mutex.RUnlock()
|
||||
|
||||
for id := range env.activePlugins {
|
||||
if id == pluginId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Activates the plugin with the given id.
|
||||
func (env *Environment) ActivatePlugin(id string) error {
|
||||
env.mutex.Lock()
|
||||
|
||||
@@ -152,10 +152,12 @@ func TestEnvironment(t *testing.T) {
|
||||
activePlugins = env.ActivePlugins()
|
||||
assert.Len(t, activePlugins, 1)
|
||||
assert.Error(t, env.ActivatePlugin("foo"))
|
||||
assert.True(t, env.IsPluginActive("foo"))
|
||||
|
||||
hooks.On("OnDeactivate").Return(nil)
|
||||
assert.NoError(t, env.DeactivatePlugin("foo"))
|
||||
assert.Error(t, env.DeactivatePlugin("foo"))
|
||||
assert.False(t, env.IsPluginActive("foo"))
|
||||
|
||||
assert.NoError(t, env.ActivatePlugin("foo"))
|
||||
assert.Equal(t, env.ActivePluginIds(), []string{"foo"})
|
||||
|
||||
Ссылка в новой задаче
Block a user