[MM-21473] Review archiveTeamsCmdF function to return an error in case of a failure (#26622)
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8f3a13122f
Коммит
8ccdca0954
@@ -178,6 +178,7 @@ func deleteTeam(c client.Client, team *model.Team) (*model.Response, error) {
|
||||
}
|
||||
|
||||
func archiveTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
var result *multierror.Error
|
||||
confirmFlag, _ := cmd.Flags().GetBool("confirm")
|
||||
if !confirmFlag {
|
||||
if err := getConfirmation("Are you sure you want to archive the specified teams?", true); err != nil {
|
||||
@@ -189,16 +190,18 @@ func archiveTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error
|
||||
for i, team := range teams {
|
||||
if team == nil {
|
||||
printer.PrintError("Unable to find team '" + args[i] + "'")
|
||||
result = multierror.Append(result, errors.New("Unable to find team '"+args[i]+"'"))
|
||||
continue
|
||||
}
|
||||
if _, err := c.SoftDeleteTeam(context.TODO(), team.Id); err != nil {
|
||||
printer.PrintError("Unable to archive team '" + team.Name + "' error: " + err.Error())
|
||||
result = multierror.Append(result, errors.New("Unable to archive team '"+team.Name+"' error: "+err.Error()))
|
||||
} else {
|
||||
printer.PrintT("Archived team '{{.Name}}'", team)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return result.ErrorOrNil()
|
||||
}
|
||||
|
||||
func listTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
|
||||
|
||||
@@ -367,7 +367,7 @@ func (s *MmctlE2ETestSuite) TestArchiveTeamsCmd() {
|
||||
printer.Clean()
|
||||
|
||||
err := archiveTeamsCmdF(c, cmd, []string{"unknown-team"})
|
||||
s.Require().Nil(err)
|
||||
s.Require().Error(err)
|
||||
s.Require().Len(printer.GetLines(), 0)
|
||||
s.Require().Len(printer.GetErrorLines(), 1)
|
||||
s.Require().Equal("Unable to find team 'unknown-team'", printer.GetErrorLines()[0])
|
||||
@@ -395,7 +395,7 @@ func (s *MmctlE2ETestSuite) TestArchiveTeamsCmd() {
|
||||
printer.Clean()
|
||||
|
||||
err := archiveTeamsCmdF(s.th.Client, cmd, []string{s.th.BasicTeam.Name})
|
||||
s.Require().Nil(err)
|
||||
s.Require().Error(err)
|
||||
s.Require().Len(printer.GetLines(), 0)
|
||||
s.Require().Len(printer.GetErrorLines(), 1)
|
||||
s.Require().Contains(printer.GetErrorLines()[0], "You do not have the appropriate permissions.")
|
||||
|
||||
Ссылка в новой задаче
Block a user