[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 удалений

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

@@ -7,6 +7,7 @@ import (
"testing"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/stretchr/testify/require"
)
func TestElasticsearchTest(t *testing.T) {
@@ -14,19 +15,22 @@ func TestElasticsearchTest(t *testing.T) {
defer th.TearDown()
t.Run("as system user", func(t *testing.T) {
_, resp := th.Client.TestElasticsearch()
resp, err := th.Client.TestElasticsearch()
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
t.Run("as system admin", func(t *testing.T) {
_, resp := th.SystemAdminClient.TestElasticsearch()
resp, err := th.SystemAdminClient.TestElasticsearch()
require.Error(t, err)
CheckNotImplementedStatus(t, resp)
})
t.Run("as restricted system admin", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
_, resp := th.SystemAdminClient.TestElasticsearch()
resp, err := th.SystemAdminClient.TestElasticsearch()
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
}
@@ -36,19 +40,22 @@ func TestElasticsearchPurgeIndexes(t *testing.T) {
defer th.TearDown()
t.Run("as system user", func(t *testing.T) {
_, resp := th.Client.PurgeElasticsearchIndexes()
resp, err := th.Client.PurgeElasticsearchIndexes()
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
t.Run("as system admin", func(t *testing.T) {
_, resp := th.SystemAdminClient.PurgeElasticsearchIndexes()
resp, err := th.SystemAdminClient.PurgeElasticsearchIndexes()
require.Error(t, err)
CheckNotImplementedStatus(t, resp)
})
t.Run("as restricted system admin", func(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
_, resp := th.SystemAdminClient.PurgeElasticsearchIndexes()
resp, err := th.SystemAdminClient.PurgeElasticsearchIndexes()
require.Error(t, err)
CheckForbiddenStatus(t, resp)
})
}