Skip to content

Commit

Permalink
[GH-21223] Add error handling for pluginInstallUvRLCmdF (mattermost#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
atlekbai authored Oct 12, 2022
1 parent 2d57a95 commit 4c28a0d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion commands/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions commands/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion commands/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4c28a0d

Please sign in to comment.