[MM-21473] Review archiveTeamsCmdF function to return an error in case of a failure (#26622)

Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
Matthew Straughn
2024-08-13 10:49:40 -04:00
коммит произвёл GitHub
родитель 8f3a13122f
Коммит 8ccdca0954
2 изменённых файлов: 6 добавлений и 3 удалений

Просмотреть файл

@@ -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 { func archiveTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {
var result *multierror.Error
confirmFlag, _ := cmd.Flags().GetBool("confirm") confirmFlag, _ := cmd.Flags().GetBool("confirm")
if !confirmFlag { if !confirmFlag {
if err := getConfirmation("Are you sure you want to archive the specified teams?", true); err != nil { 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 { for i, team := range teams {
if team == nil { if team == nil {
printer.PrintError("Unable to find team '" + args[i] + "'") printer.PrintError("Unable to find team '" + args[i] + "'")
result = multierror.Append(result, errors.New("Unable to find team '"+args[i]+"'"))
continue continue
} }
if _, err := c.SoftDeleteTeam(context.TODO(), team.Id); err != nil { if _, err := c.SoftDeleteTeam(context.TODO(), team.Id); err != nil {
printer.PrintError("Unable to archive team '" + team.Name + "' error: " + err.Error()) 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 { } else {
printer.PrintT("Archived team '{{.Name}}'", team) printer.PrintT("Archived team '{{.Name}}'", team)
} }
} }
return nil return result.ErrorOrNil()
} }
func listTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error { func listTeamsCmdF(c client.Client, cmd *cobra.Command, args []string) error {

Просмотреть файл

@@ -367,7 +367,7 @@ func (s *MmctlE2ETestSuite) TestArchiveTeamsCmd() {
printer.Clean() printer.Clean()
err := archiveTeamsCmdF(c, cmd, []string{"unknown-team"}) 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.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1) s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Equal("Unable to find team 'unknown-team'", printer.GetErrorLines()[0]) s.Require().Equal("Unable to find team 'unknown-team'", printer.GetErrorLines()[0])
@@ -395,7 +395,7 @@ func (s *MmctlE2ETestSuite) TestArchiveTeamsCmd() {
printer.Clean() printer.Clean()
err := archiveTeamsCmdF(s.th.Client, cmd, []string{s.th.BasicTeam.Name}) 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.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1) s.Require().Len(printer.GetErrorLines(), 1)
s.Require().Contains(printer.GetErrorLines()[0], "You do not have the appropriate permissions.") s.Require().Contains(printer.GetErrorLines()[0], "You do not have the appropriate permissions.")