[MM-29973] Adds E2E tests for mmctl plugin disable (#35464)

This commit is contained in:
Domenico Rizzo
2026-03-18 11:05:46 +00:00
committed by GitHub
parent b10346496b
commit 9dacec3672
@@ -462,3 +462,138 @@ func (s *MmctlE2ETestSuite) TestPluginListCmdF() {
s.Require().Len(printer.GetErrorLines(), 0)
})
}
func (s *MmctlE2ETestSuite) TestPluginDisableCmd() {
s.SetupTestHelper().InitBasic(s.T())
pluginID := "testplugin"
pluginURL := filepath.Join(server.GetPackagePath(), "tests", "testplugin.tar.gz")
nonExistentPluginID := "nonExistentPluginID"
enablePlugin := *s.th.App.Config().PluginSettings.Enable
enableUploads := *s.th.App.Config().PluginSettings.EnableUploads
defer func() {
appErr := s.th.App.Channels().RemovePlugin(pluginID)
if appErr != nil {
s.Require().Contains(appErr.Error(), "Plugin is not installed.")
}
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 0)
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = enablePlugin
*cfg.PluginSettings.EnableUploads = enableUploads
})
}()
// Enable plugin uploads
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = true
*cfg.PluginSettings.EnableUploads = true
})
// Install plugin first
err := pluginAddCmdF(s.th.SystemAdminClient, &cobra.Command{}, []string{pluginURL})
s.Require().Nil(err)
s.RunForSystemAdminAndLocal("Successful disable plugin", func(c client.Client) {
printer.Clean()
appErr := s.th.App.EnablePlugin(pluginID)
s.Require().Nil(appErr)
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 1)
s.Require().Len(plugins.Inactive, 0)
cmd := &cobra.Command{}
err := pluginDisableCmdF(c, cmd, []string{pluginID})
s.Require().Nil(err)
plugins, appErr = s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
s.Require().Len(printer.GetLines(), 1)
s.Require().Equal(printer.GetLines()[0], "Disabled plugin: "+pluginID)
})
s.Run("error for disable plugin due insufficient permissions", func() {
printer.Clean()
appErr := s.th.App.EnablePlugin(pluginID)
s.Require().Nil(appErr)
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 1)
s.Require().Len(plugins.Inactive, 0)
cmd := &cobra.Command{}
err := pluginDisableCmdF(s.th.Client, cmd, []string{pluginID})
s.Require().NotNil(err)
s.Require().ErrorContains(err, "You do not have the appropriate permissions.")
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Equal(printer.GetErrorLines()[0], "Unable to disable plugin: "+pluginID+". Error: You do not have the appropriate permissions.")
plugins, appErr = s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 1)
s.Require().Len(plugins.Inactive, 0)
appErr = s.th.App.DisablePlugin(pluginID)
s.Require().Nil(appErr)
})
s.RunForSystemAdminAndLocal("error for disabling non existent plugin", func(c client.Client) {
printer.Clean()
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
cmd := &cobra.Command{}
err := pluginDisableCmdF(c, cmd, []string{nonExistentPluginID})
s.Require().NotNil(err)
s.Require().ErrorContains(err, "Plugin is not installed.")
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Equal(printer.GetErrorLines()[0], "Unable to disable plugin: "+nonExistentPluginID+". Error: Plugin is not installed.")
plugins, appErr = s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 0)
s.Require().Len(plugins.Inactive, 1)
})
s.RunForSystemAdminAndLocal("error when plugin configs are disabled", func(c client.Client) {
printer.Clean()
appErr := s.th.App.EnablePlugin(pluginID)
s.Require().Nil(appErr)
plugins, appErr := s.th.App.GetPlugins()
s.Require().Nil(appErr)
s.Require().Len(plugins.Active, 1)
s.Require().Len(plugins.Inactive, 0)
enablePlugin2 := *s.th.App.Config().PluginSettings.Enable
defer s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = enablePlugin2
})
s.th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.PluginSettings.Enable = false
})
cmd := &cobra.Command{}
err := pluginDisableCmdF(c, cmd, []string{pluginID})
s.Require().NotNil(err)
s.Require().ErrorContains(err, "Plugins have been disabled. Please check your logs for details.")
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Equal(printer.GetErrorLines()[0], "Unable to disable plugin: "+pluginID+". Error: Plugins have been disabled. Please check your logs for details.")
})
}