mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
updated modifyTeamsCmdF to return error instead of nil when encounting error (#26606)
This commit is contained in:
parent
65c6717e6b
commit
db2cfe953b
@ -336,6 +336,8 @@ func modifyTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
|||||||
return errors.New("must specify one of --private or --public")
|
return errors.New("must specify one of --private or --public")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errs *multierror.Error
|
||||||
|
|
||||||
// I = invite only (private)
|
// I = invite only (private)
|
||||||
// O = open (public)
|
// O = open (public)
|
||||||
privacy := model.TeamInvite
|
privacy := model.TeamInvite
|
||||||
@ -346,17 +348,24 @@ func modifyTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
|||||||
teams := getTeamsFromTeamArgs(c, args)
|
teams := getTeamsFromTeamArgs(c, args)
|
||||||
for i, team := range teams {
|
for i, team := range teams {
|
||||||
if team == nil {
|
if team == nil {
|
||||||
printer.PrintError("Unable to find team '" + args[i] + "'")
|
errs = multierror.Append(errs, errors.New("Unable to find team '"+args[i]+"'"))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if updatedTeam, _, err := c.UpdateTeamPrivacy(context.TODO(), team.Id, privacy); err != nil {
|
|
||||||
printer.PrintError("Unable to modify team '" + team.Name + "' error: " + err.Error())
|
updatedTeam, _, err := c.UpdateTeamPrivacy(context.TODO(), team.Id, privacy)
|
||||||
} else {
|
if err != nil {
|
||||||
printer.PrintT("Modified team '{{.Name}}'", updatedTeam)
|
errs = multierror.Append(errs, errors.New("Unable to modify team '"+team.Name+"' error: "+err.Error()))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printer.PrintT("Modified team '{{.Name}}'", updatedTeam)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
for _, err := range errs.WrappedErrors() {
|
||||||
|
printer.PrintError(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return errs.ErrorOrNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
func restoreTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
func restoreTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||||
|
@ -182,10 +182,12 @@ func (s *MmctlE2ETestSuite) TestModifyTeamsCmdF() {
|
|||||||
cmd := &cobra.Command{}
|
cmd := &cobra.Command{}
|
||||||
cmd.Flags().Bool("private", true, "")
|
cmd.Flags().Bool("private", true, "")
|
||||||
err := modifyTeamsCmdF(s.th.Client, cmd, []string{teamID})
|
err := modifyTeamsCmdF(s.th.Client, cmd, []string{teamID})
|
||||||
s.Require().NoError(err)
|
|
||||||
|
expectedError := fmt.Sprintf("Unable to modify team '%s' error: You do not have the appropriate permissions.", s.th.BasicTeam.Name)
|
||||||
|
s.Require().ErrorContains(err, expectedError)
|
||||||
s.Require().Contains(
|
s.Require().Contains(
|
||||||
printer.GetErrorLines()[0],
|
printer.GetErrorLines()[0],
|
||||||
fmt.Sprintf("Unable to modify team '%s' error: You do not have the appropriate permissions.", s.th.BasicTeam.Name),
|
expectedError,
|
||||||
)
|
)
|
||||||
t, appErr := s.th.App.GetTeam(teamID)
|
t, appErr := s.th.App.GetTeam(teamID)
|
||||||
s.Require().Nil(appErr)
|
s.Require().Nil(appErr)
|
||||||
@ -199,10 +201,12 @@ func (s *MmctlE2ETestSuite) TestModifyTeamsCmdF() {
|
|||||||
cmd.Flags().Bool("private", true, "")
|
cmd.Flags().Bool("private", true, "")
|
||||||
s.th.LoginBasic2()
|
s.th.LoginBasic2()
|
||||||
err := modifyTeamsCmdF(s.th.Client, cmd, []string{teamID})
|
err := modifyTeamsCmdF(s.th.Client, cmd, []string{teamID})
|
||||||
s.Require().NoError(err)
|
|
||||||
|
expectedError := fmt.Sprintf("Unable to modify team '%s' error: You do not have the appropriate permissions.", s.th.BasicTeam.Name)
|
||||||
|
s.Require().ErrorContains(err, expectedError)
|
||||||
s.Require().Contains(
|
s.Require().Contains(
|
||||||
printer.GetErrorLines()[0],
|
printer.GetErrorLines()[0],
|
||||||
fmt.Sprintf("Unable to modify team '%s' error: You do not have the appropriate permissions.", s.th.BasicTeam.Name),
|
expectedError,
|
||||||
)
|
)
|
||||||
t, appErr := s.th.App.GetTeam(teamID)
|
t, appErr := s.th.App.GetTeam(teamID)
|
||||||
s.Require().Nil(appErr)
|
s.Require().Nil(appErr)
|
||||||
|
@ -734,8 +734,10 @@ func (s *MmctlUnitTestSuite) TestModifyTeamsCmd() {
|
|||||||
cmd.Flags().Bool("private", true, "")
|
cmd.Flags().Bool("private", true, "")
|
||||||
|
|
||||||
err := modifyTeamsCmdF(s.client, cmd, []string{"team1"})
|
err := modifyTeamsCmdF(s.client, cmd, []string{"team1"})
|
||||||
s.Require().Nil(err)
|
|
||||||
s.Require().Equal("Unable to find team 'team1'", printer.GetErrorLines()[0])
|
expectedError := "Unable to find team 'team1'"
|
||||||
|
s.Require().ErrorContains(err, expectedError)
|
||||||
|
s.Require().Equal(expectedError, printer.GetErrorLines()[0])
|
||||||
})
|
})
|
||||||
|
|
||||||
s.Run("Modify teams, set to private", func() {
|
s.Run("Modify teams, set to private", func() {
|
||||||
@ -823,8 +825,10 @@ func (s *MmctlUnitTestSuite) TestModifyTeamsCmd() {
|
|||||||
cmd.Flags().Bool("public", true, "")
|
cmd.Flags().Bool("public", true, "")
|
||||||
|
|
||||||
err := modifyTeamsCmdF(s.client, cmd, []string{"team1"})
|
err := modifyTeamsCmdF(s.client, cmd, []string{"team1"})
|
||||||
s.Require().Nil(err)
|
|
||||||
s.Require().Equal("Unable to modify team 'team1' error: an error occurred modifying a team",
|
expectedError := "Unable to modify team 'team1' error: an error occurred modifying a team"
|
||||||
|
s.Require().ErrorContains(err, expectedError)
|
||||||
|
s.Require().Equal(expectedError,
|
||||||
printer.GetErrorLines()[0])
|
printer.GetErrorLines()[0])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user