[MM-37557] Move error out of client4 response (#18101)

* Return an error seperately from Response

* Remove BuildErrorResponse

* Drop Response.Error from model/client4.go

* Migrate require.Nil checks

* Migrate require.NotNil checks

* More manual fixes

* Move error check out of CheckOKStatus and CheckCreatedStatus

* Move error check out of CheckForbiddenStatus

* Move error check out of CheckUnauthorizedStatus

* Move error check out of CheckNotFoundStatus

* Move error check out of CheckBadRequestStatus

* Move error check out of CheckNotImplementedStatus and CheckRequestEntityTooLargeStatus

* Move error check out of CheckInternalErrorStatus

* Move error check out of CheckServiceUnavailableStatus

* Remove error check from checkHTTPStatus

* Remove remaining references to Response.Error

* Check previously unchecked errors

* Manually fix compile and linter errors

* Return error in CreateWebSocket methods

* Return error instead of *AppError in DoApi methods

* Manually fix bad replacments

* Conistently return Response and error

* Use err instead of seperate bool return value to indicate success

* Reduce ussage of model.AppError in web/oauth_test.go

* Remove client4.Must

* Check error in buf.ReadFrom

* Fix failing tests
Этот коммит содержится в:
Ben Schumacher
2021-08-13 13:12:16 +02:00
коммит произвёл GitHub
родитель 96593580ae
Коммит a8ca5c423f
60 изменённых файлов: 9790 добавлений и 8706 удалений

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

@@ -113,7 +113,8 @@ func TestListChannels(t *testing.T) {
defer th.TearDown()
channel := th.CreatePublicChannel()
th.Client.Must(th.Client.DeleteChannel(channel.Id))
_, err := th.Client.DeleteChannel(channel.Id)
require.NoError(t, err)
privateChannel := th.CreatePrivateChannel()
output := th.CheckCommand(t, "channel", "list", th.BasicTeam.Name)
@@ -124,7 +125,8 @@ func TestListChannels(t *testing.T) {
require.True(t, strings.Contains(output, privateChannel.Name+" (private)"), "should have private channel")
th.Client.Must(th.Client.DeleteChannel(privateChannel.Id))
_, err = th.Client.DeleteChannel(privateChannel.Id)
require.NoError(t, err)
output = th.CheckCommand(t, "channel", "list", th.BasicTeam.Name)
@@ -136,7 +138,8 @@ func TestRestoreChannel(t *testing.T) {
defer th.TearDown()
channel := th.CreatePublicChannel()
th.Client.Must(th.Client.DeleteChannel(channel.Id))
_, err := th.Client.DeleteChannel(channel.Id)
require.NoError(t, err)
th.CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)

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

@@ -115,9 +115,8 @@ func TestCreateCommand(t *testing.T) {
t.Run(testCase.Description, func(t *testing.T) {
actual, _ := th.RunCommandWithOutput(t, testCase.Args...)
cmds, response := th.SystemAdminClient.ListCommands(team.Id, true)
require.Nil(t, response.Error, "Failed to list commands")
cmds, _, err := th.SystemAdminClient.ListCommands(team.Id, true)
require.NoError(t, err, "Failed to list commands")
if testCase.ExpectedErr == "" {
assert.NotZero(t, len(cmds), "Failed to create command")

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

@@ -22,7 +22,8 @@ func TestCreateTeam(t *testing.T) {
th.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
found, _, err := th.SystemAdminClient.TeamExists(name, "")
require.NoError(t, err)
require.True(t, found, "Failed to create Team")
}
@@ -33,7 +34,8 @@ func TestJoinTeam(t *testing.T) {
th.CheckCommand(t, "team", "add", th.BasicTeam.Name, th.BasicUser.Email)
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
profiles, _, err := th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")
require.NoError(t, err)
found := false
@@ -53,7 +55,8 @@ func TestLeaveTeam(t *testing.T) {
th.CheckCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email)
profiles := th.Client.Must(th.Client.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
profiles, _, err := th.Client.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")
require.NoError(t, err)
found := false
@@ -181,8 +184,8 @@ func TestRestoreTeams(t *testing.T) {
th.CheckCommand(t, "team", "restore", name)
found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
found, _, err := th.SystemAdminClient.TeamExists(name, "")
require.NoError(t, err)
require.True(t, found)
}

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

@@ -24,7 +24,8 @@ func TestCreateUserWithTeam(t *testing.T) {
th.CheckCommand(t, "team", "add", th.BasicTeam.Id, email)
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
profiles, _, err := th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")
require.NoError(t, err)
found := false

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

@@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v6/api4"
"github.com/mattermost/mattermost-server/v6/model"
)
@@ -44,13 +43,13 @@ func TestListWebhooks(t *testing.T) {
dispName := "myhookinc"
hook := &model.IncomingWebhook{DisplayName: dispName, ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId}
_, resp := adminClient.CreateIncomingWebhook(hook)
api4.CheckNoError(t, resp)
_, _, err := adminClient.CreateIncomingWebhook(hook)
require.NoError(t, err)
dispName2 := "myhookout"
outHook := &model.OutgoingWebhook{DisplayName: dispName2, ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, CallbackURLs: []string{"http://nowhere.com"}, Username: "some-user-name", IconURL: "http://some-icon-url/"}
_, resp = adminClient.CreateOutgoingWebhook(outHook)
api4.CheckNoError(t, resp)
_, _, err = adminClient.CreateOutgoingWebhook(outHook)
require.NoError(t, err)
output := th.CheckCommand(t, "webhook", "list", th.BasicTeam.Name)
@@ -91,8 +90,8 @@ func TestShowWebhook(t *testing.T) {
ChannelId: th.BasicChannel.Id,
TeamId: th.BasicChannel.TeamId,
}
incomingWebhook, resp := adminClient.CreateIncomingWebhook(hook)
api4.CheckNoError(t, resp)
incomingWebhook, _, err := adminClient.CreateIncomingWebhook(hook)
require.NoError(t, err)
// should return an error when no webhookid is provided
require.Error(t, th.RunCommand(t, "webhook", "show"))
@@ -114,8 +113,8 @@ func TestShowWebhook(t *testing.T) {
Username: "some-user-name",
IconURL: "http://some-icon-url/",
}
outgoingWebhook, resp := adminClient.CreateOutgoingWebhook(outgoingHook)
api4.CheckNoError(t, resp)
outgoingWebhook, _, err := adminClient.CreateOutgoingWebhook(outgoingHook)
require.NoError(t, err)
// valid outgoing webhook should return webhook data
output = th.CheckCommand(t, "webhook", "show", outgoingWebhook.Id)
@@ -424,13 +423,13 @@ func TestDeleteWebhooks(t *testing.T) {
dispName := "myhookinc"
inHookStruct := &model.IncomingWebhook{DisplayName: dispName, ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId}
incomingHook, resp := adminClient.CreateIncomingWebhook(inHookStruct)
api4.CheckNoError(t, resp)
incomingHook, _, err := adminClient.CreateIncomingWebhook(inHookStruct)
require.NoError(t, err)
dispName2 := "myhookout"
outHookStruct := &model.OutgoingWebhook{DisplayName: dispName2, ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId, CallbackURLs: []string{"http://nowhere.com"}, Username: "some-user-name", IconURL: "http://some-icon-url/"}
outgoingHook, resp := adminClient.CreateOutgoingWebhook(outHookStruct)
api4.CheckNoError(t, resp)
outgoingHook, _, err := adminClient.CreateOutgoingWebhook(outHookStruct)
require.NoError(t, err)
hooksBeforeDeletion := th.CheckCommand(t, "webhook", "list", th.BasicTeam.Name)