Print & Return errors using multierror if an error happens (#26625)

* Print & Return errors using multierror if an error happens

* Group up errors assertion in test

* Remove trailing newspace

* Remove WrappedErrors loop

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Ezekiel
2024-05-01 04:16:05 +08:00
коммит произвёл GitHub
родитель 48b047aa0c
Коммит b7e830f4a1
3 изменённых файлов: 43 добавлений и 34 удалений

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

@@ -1783,13 +1783,13 @@ func (s *MmctlUnitTestSuite) TestUnarchiveChannelCmdF() {
Times(1)
err := unarchiveChannelsCmdF(s.client, cmd, args)
s.Require().Nil(err)
expectedError := fmt.Sprintf("Unable to find channel '%s'", args[0])
s.Require().ErrorContains(err, expectedError)
s.Require().Equal(expectedError, printer.GetErrorLines()[0])
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
actual := printer.GetErrorLines()[0]
expected := fmt.Sprintf("Unable to find channel '%s'", args[0])
s.Require().Equal(expected, actual)
})
s.Run("Fail to unarchive a non-existing channel on an existent team", func() {
@@ -1821,13 +1821,13 @@ func (s *MmctlUnitTestSuite) TestUnarchiveChannelCmdF() {
Times(1)
err := unarchiveChannelsCmdF(s.client, cmd, args)
s.Require().Nil(err)
expectedError := fmt.Sprintf("Unable to find channel '%s'", args[0])
s.Require().ErrorContains(err, expectedError)
s.Require().Equal(expectedError, printer.GetErrorLines()[0])
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
actual := printer.GetErrorLines()[0]
expected := fmt.Sprintf("Unable to find channel '%s'", args[0])
s.Require().Equal(expected, actual)
})
s.Run("Fail to unarchive a non-existing channel", func() {
@@ -1844,13 +1844,13 @@ func (s *MmctlUnitTestSuite) TestUnarchiveChannelCmdF() {
Times(1)
err := unarchiveChannelsCmdF(s.client, cmd, args)
s.Require().Nil(err)
expectedError := fmt.Sprintf("Unable to find channel '%s'", args[0])
s.Require().ErrorContains(err, expectedError)
s.Require().Equal(expectedError, printer.GetErrorLines()[0])
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
actual := printer.GetErrorLines()[0]
expected := fmt.Sprintf("Unable to find channel '%s'", args[0])
s.Require().Equal(expected, actual)
})
s.Run("Fail to unarchive an existing channel when client throws error", func() {
@@ -1875,13 +1875,13 @@ func (s *MmctlUnitTestSuite) TestUnarchiveChannelCmdF() {
Times(1)
err := unarchiveChannelsCmdF(s.client, cmd, args)
s.Require().Nil(err)
expectedError := fmt.Sprintf("Unable to unarchive channel '%s'. Error: %s", channelName, mockErr.Error())
s.Require().ErrorContains(err, expectedError)
s.Require().Equal(expectedError, printer.GetErrorLines()[0])
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
actual := printer.GetErrorLines()[0]
expected := fmt.Sprintf("Unable to unarchive channel '%s'. Error: %s", channelName, mockErr.Error())
s.Require().Equal(expected, actual)
})
s.Run("Fail to unarchive when team and channel not provided", func() {
@@ -1891,13 +1891,13 @@ func (s *MmctlUnitTestSuite) TestUnarchiveChannelCmdF() {
args := []string{":"}
err := unarchiveChannelsCmdF(s.client, cmd, args)
s.Require().Nil(err)
expectedError := fmt.Sprintf("Unable to find channel '%s'", args[0])
s.Require().ErrorContains(err, expectedError)
s.Require().Equal(expectedError, printer.GetErrorLines()[0])
s.Require().Len(printer.GetLines(), 0)
s.Require().Len(printer.GetErrorLines(), 1)
actual := printer.GetErrorLines()[0]
expected := fmt.Sprintf("Unable to find channel '%s'", args[0])
s.Require().Equal(expected, actual)
})
}