[MM-25477] - Migrate command webhook store AppError to error (#14703)

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Migrate command webhook store AppError to error

* Changes requested in the review.

* Changing http status

* fix i18n

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
Этот коммит содержится в:
dantepippi
2020-07-19 00:12:03 -03:00
коммит произвёл GitHub
родитель c7f7bef9ec
Коммит aae3b9650f
8 изменённых файлов: 113 добавлений и 82 удалений

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

@@ -4,7 +4,7 @@
package storetest
import (
"net/http"
"errors"
"testing"
"github.com/mattermost/mattermost-server/v5/model"
@@ -28,12 +28,13 @@ func testCommandWebhookStore(t *testing.T, ss store.Store) {
require.Nil(t, err)
var r1 *model.CommandWebhook
r1, err = cws.Get(h1.Id)
require.Nil(t, err)
r1, nErr := cws.Get(h1.Id)
require.Nil(t, nErr)
assert.Equal(t, *r1, *h1, "invalid returned webhook")
_, err = cws.Get("123")
assert.Equal(t, err.StatusCode, http.StatusNotFound, "Should have set the status as not found for missing id")
_, nErr = cws.Get("123")
var nfErr *store.ErrNotFound
require.True(t, errors.As(nErr, &nfErr), "Should have set the status as not found for missing id")
h2 := &model.CommandWebhook{}
h2.CreateAt = model.GetMillis() - 2*model.COMMAND_WEBHOOK_LIFETIME
@@ -43,22 +44,23 @@ func testCommandWebhookStore(t *testing.T, ss store.Store) {
h2, err = cws.Save(h2)
require.Nil(t, err)
_, err = cws.Get(h2.Id)
require.NotNil(t, err, "Should have set the status as not found for expired webhook")
assert.Equal(t, err.StatusCode, http.StatusNotFound, "Should have set the status as not found for expired webhook")
_, nErr = cws.Get(h2.Id)
require.NotNil(t, nErr, "Should have set the status as not found for expired webhook")
require.True(t, errors.As(nErr, &nfErr), "Should have set the status as not found for expired webhook")
cws.Cleanup()
_, err = cws.Get(h1.Id)
require.Nil(t, err, "Should have no error getting unexpired webhook")
_, nErr = cws.Get(h1.Id)
require.Nil(t, nErr, "Should have no error getting unexpired webhook")
_, err = cws.Get(h2.Id)
assert.Equal(t, err.StatusCode, http.StatusNotFound, "Should have set the status as not found for expired webhook")
_, nErr = cws.Get(h2.Id)
require.True(t, errors.As(nErr, &nfErr), "Should have set the status as not found for expired webhook")
err = cws.TryUse(h1.Id, 1)
require.Nil(t, err, "Should be able to use webhook once")
nErr = cws.TryUse(h1.Id, 1)
require.Nil(t, nErr, "Should be able to use webhook once")
err = cws.TryUse(h1.Id, 1)
require.NotNil(t, err, "Should be able to use webhook once")
assert.Equal(t, err.StatusCode, http.StatusBadRequest, "Should be able to use webhook once")
nErr = cws.TryUse(h1.Id, 1)
require.NotNil(t, nErr, "Should be able to use webhook once")
var invErr *store.ErrInvalidInput
require.True(t, errors.As(nErr, &invErr), "Should be able to use webhook once")
}

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

@@ -20,7 +20,7 @@ func (_m *CommandWebhookStore) Cleanup() {
}
// Get provides a mock function with given fields: id
func (_m *CommandWebhookStore) Get(id string) (*model.CommandWebhook, *model.AppError) {
func (_m *CommandWebhookStore) Get(id string) (*model.CommandWebhook, error) {
ret := _m.Called(id)
var r0 *model.CommandWebhook
@@ -32,12 +32,12 @@ func (_m *CommandWebhookStore) Get(id string) (*model.CommandWebhook, *model.App
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(id)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
r1 = ret.Get(1).(error)
}
}
@@ -45,7 +45,7 @@ func (_m *CommandWebhookStore) Get(id string) (*model.CommandWebhook, *model.App
}
// Save provides a mock function with given fields: webhook
func (_m *CommandWebhookStore) Save(webhook *model.CommandWebhook) (*model.CommandWebhook, *model.AppError) {
func (_m *CommandWebhookStore) Save(webhook *model.CommandWebhook) (*model.CommandWebhook, error) {
ret := _m.Called(webhook)
var r0 *model.CommandWebhook
@@ -57,12 +57,12 @@ func (_m *CommandWebhookStore) Save(webhook *model.CommandWebhook) (*model.Comma
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(*model.CommandWebhook) *model.AppError); ok {
var r1 error
if rf, ok := ret.Get(1).(func(*model.CommandWebhook) error); ok {
r1 = rf(webhook)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
r1 = ret.Get(1).(error)
}
}
@@ -70,15 +70,15 @@ func (_m *CommandWebhookStore) Save(webhook *model.CommandWebhook) (*model.Comma
}
// TryUse provides a mock function with given fields: id, limit
func (_m *CommandWebhookStore) TryUse(id string, limit int) *model.AppError {
func (_m *CommandWebhookStore) TryUse(id string, limit int) error {
ret := _m.Called(id, limit)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(string, int) *model.AppError); ok {
var r0 error
if rf, ok := ret.Get(0).(func(string, int) error); ok {
r0 = rf(id, limit)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)
r0 = ret.Get(0).(error)
}
}