[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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
96593580ae
Коммит
a8ca5c423f
@@ -43,7 +43,7 @@ func (th *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func TestPostActionCookies(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost,127.0.0.1"
|
||||
@@ -127,14 +127,12 @@ func TestPostActionCookies(t *testing.T) {
|
||||
assert.Equal(t, 32, len(th.App.PostActionCookieSecret()))
|
||||
post = model.AddPostActionCookies(post, th.App.PostActionCookieSecret())
|
||||
|
||||
ok, resp := Client.DoPostActionWithCookie(post.Id, test.Action.Id, "", test.Action.Cookie)
|
||||
resp, err := client.DoPostActionWithCookie(post.Id, test.Action.Id, "", test.Action.Cookie)
|
||||
require.NotNil(t, resp)
|
||||
if test.ExpectedSucess {
|
||||
assert.True(t, ok)
|
||||
assert.Nil(t, resp.Error)
|
||||
assert.NoError(t, err)
|
||||
} else {
|
||||
assert.False(t, ok)
|
||||
assert.NotNil(t, resp.Error)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
assert.Equal(t, test.ExpectedStatusCode, resp.StatusCode)
|
||||
assert.NotNil(t, resp.RequestId)
|
||||
@@ -146,14 +144,14 @@ func TestPostActionCookies(t *testing.T) {
|
||||
func TestOpenDialog(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost,127.0.0.1"
|
||||
})
|
||||
|
||||
_, triggerId, err := model.GenerateTriggerId(th.BasicUser.Id, th.App.AsymmetricSigningKey())
|
||||
require.Nil(t, err)
|
||||
_, triggerId, appErr := model.GenerateTriggerId(th.BasicUser.Id, th.App.AsymmetricSigningKey())
|
||||
require.Nil(t, appErr)
|
||||
|
||||
request := model.OpenDialogRequest{
|
||||
TriggerId: triggerId,
|
||||
@@ -175,51 +173,47 @@ func TestOpenDialog(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pass, resp := Client.OpenInteractiveDialog(request)
|
||||
CheckNoError(t, resp)
|
||||
assert.True(t, pass)
|
||||
_, err := client.OpenInteractiveDialog(request)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should fail on bad trigger ID
|
||||
request.TriggerId = "junk"
|
||||
pass, resp = Client.OpenInteractiveDialog(request)
|
||||
resp, err := client.OpenInteractiveDialog(request)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
assert.False(t, pass)
|
||||
|
||||
// URL is required
|
||||
request.TriggerId = triggerId
|
||||
request.URL = ""
|
||||
pass, resp = Client.OpenInteractiveDialog(request)
|
||||
resp, err = client.OpenInteractiveDialog(request)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
assert.False(t, pass)
|
||||
|
||||
// Should pass with markdown formatted introduction text
|
||||
request.URL = "http://localhost:8065"
|
||||
request.Dialog.IntroductionText = "**Some** _introduction text"
|
||||
pass, resp = Client.OpenInteractiveDialog(request)
|
||||
CheckNoError(t, resp)
|
||||
assert.True(t, pass)
|
||||
_, err = client.OpenInteractiveDialog(request)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should pass with empty introduction text
|
||||
request.Dialog.IntroductionText = ""
|
||||
pass, resp = Client.OpenInteractiveDialog(request)
|
||||
CheckNoError(t, resp)
|
||||
assert.True(t, pass)
|
||||
_, err = client.OpenInteractiveDialog(request)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should pass with no elements
|
||||
request.Dialog.Elements = nil
|
||||
pass, resp = Client.OpenInteractiveDialog(request)
|
||||
CheckNoError(t, resp)
|
||||
assert.True(t, pass)
|
||||
_, err = client.OpenInteractiveDialog(request)
|
||||
require.NoError(t, err)
|
||||
|
||||
request.Dialog.Elements = []model.DialogElement{}
|
||||
pass, resp = Client.OpenInteractiveDialog(request)
|
||||
CheckNoError(t, resp)
|
||||
assert.True(t, pass)
|
||||
_, err = client.OpenInteractiveDialog(request)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestSubmitDialog(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
client := th.Client
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost,127.0.0.1"
|
||||
@@ -253,25 +247,28 @@ func TestSubmitDialog(t *testing.T) {
|
||||
|
||||
submit.URL = ts.URL
|
||||
|
||||
submitResp, resp := Client.SubmitInteractiveDialog(submit)
|
||||
CheckNoError(t, resp)
|
||||
submitResp, _, err := client.SubmitInteractiveDialog(submit)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, submitResp)
|
||||
|
||||
submit.URL = ""
|
||||
submitResp, resp = Client.SubmitInteractiveDialog(submit)
|
||||
submitResp, resp, err := client.SubmitInteractiveDialog(submit)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
assert.Nil(t, submitResp)
|
||||
|
||||
submit.URL = ts.URL
|
||||
submit.ChannelId = model.NewId()
|
||||
submitResp, resp = Client.SubmitInteractiveDialog(submit)
|
||||
submitResp, resp, err = client.SubmitInteractiveDialog(submit)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
assert.Nil(t, submitResp)
|
||||
|
||||
submit.URL = ts.URL
|
||||
submit.ChannelId = th.BasicChannel.Id
|
||||
submit.TeamId = model.NewId()
|
||||
submitResp, resp = Client.SubmitInteractiveDialog(submit)
|
||||
submitResp, resp, err = client.SubmitInteractiveDialog(submit)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
assert.Nil(t, submitResp)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user