diff --git a/commands/plugin.go b/commands/plugin.go index e351191ee..e8b55eb95 100644 --- a/commands/plugin.go +++ b/commands/plugin.go @@ -9,6 +9,7 @@ import ( "github.com/mattermost/mmctl/v6/client" "github.com/mattermost/mmctl/v6/printer" + "github.com/hashicorp/go-multierror" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -118,17 +119,19 @@ func pluginAddCmdF(c client.Client, cmd *cobra.Command, args []string) error { func pluginInstallURLCmdF(c client.Client, cmd *cobra.Command, args []string) error { force, _ := cmd.Flags().GetBool("force") + var multiErr *multierror.Error for _, plugin := range args { manifest, _, err := c.InstallPluginFromURL(plugin, force) if err != nil { printer.PrintError("Unable to install plugin from URL \"" + plugin + "\". Error: " + err.Error()) + multiErr = multierror.Append(multiErr, err) } else { printer.PrintT("Plugin {{.Name}} successfully installed", manifest) } } - return nil + return multiErr.ErrorOrNil() } func pluginDeleteCmdF(c client.Client, cmd *cobra.Command, args []string) error { diff --git a/commands/plugin_e2e_test.go b/commands/plugin_e2e_test.go index 749067a07..924fb8f53 100644 --- a/commands/plugin_e2e_test.go +++ b/commands/plugin_e2e_test.go @@ -197,7 +197,7 @@ func (s *MmctlE2ETestSuite) TestPluginInstallURLCmd() { defer removePluginIfInstalled(s.th.Client, s, jiraPluginID) err := pluginInstallURLCmdF(s.th.Client, &cobra.Command{}, []string{jiraURL}) - s.Require().Nil(err) + s.Require().NotNil(err) s.Require().Len(printer.GetLines(), 0) s.Require().Len(printer.GetErrorLines(), 1) s.Require().Contains(printer.GetErrorLines()[0], fmt.Sprintf("Unable to install plugin from URL \"%s\".", jiraURL)) @@ -215,7 +215,7 @@ func (s *MmctlE2ETestSuite) TestPluginInstallURLCmd() { const pluginURL = "https://plugins-store.test.mattermost.com/release/mattermost-nonexistent-plugin-v2.0.0.tar.gz" err := pluginInstallURLCmdF(c, &cobra.Command{}, []string{pluginURL}) - s.Require().Nil(err) + s.Require().NotNil(err) s.Require().Len(printer.GetLines(), 0) s.Require().Len(printer.GetErrorLines(), 1) s.Require().Contains(printer.GetErrorLines()[0], fmt.Sprintf("Unable to install plugin from URL \"%s\".", pluginURL)) @@ -238,7 +238,7 @@ func (s *MmctlE2ETestSuite) TestPluginInstallURLCmd() { s.Require().Equal(jiraPluginID, printer.GetLines()[0].(*model.Manifest).Id) err = pluginInstallURLCmdF(c, &cobra.Command{}, []string{jiraURL}) - s.Require().Nil(err) + s.Require().NotNil(err) s.Require().Len(printer.GetLines(), 1) s.Require().Len(printer.GetErrorLines(), 1) s.Require().Contains(printer.GetErrorLines()[0], fmt.Sprintf("Unable to install plugin from URL \"%s\".", jiraURL)) diff --git a/commands/plugin_test.go b/commands/plugin_test.go index feaf0b7de..d4a64ab8e 100644 --- a/commands/plugin_test.go +++ b/commands/plugin_test.go @@ -198,7 +198,7 @@ func (s *MmctlUnitTestSuite) TestPluginInstallUrlCmd() { Times(1) err := pluginInstallURLCmdF(s.client, &cobra.Command{}, args) - s.Require().NoError(err) + s.Require().NotNil(err) s.Require().Len(printer.GetErrorLines(), 1) s.Require().Equal("Unable to install plugin from URL \"https://example.com/plugin2.tar.gz\". Error: mock error", printer.GetErrorLines()[0]) s.Require().Len(printer.GetLines(), 1)