MM-26031: Migrate reaction store to plain errors (#14931)
* ReactionStore migration to return plain errors * Fix translations * FixImports * Rollback fix imports * Fix merge conflict * add ent translation Co-authored-by: Rodrigo Villablanca <villa061004@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
00aeca0e5c
Коммит
71925ea224
@@ -15,7 +15,7 @@ type ReactionStore struct {
|
||||
}
|
||||
|
||||
// BulkGetForPosts provides a mock function with given fields: postIds
|
||||
func (_m *ReactionStore) BulkGetForPosts(postIds []string) ([]*model.Reaction, *model.AppError) {
|
||||
func (_m *ReactionStore) BulkGetForPosts(postIds []string) ([]*model.Reaction, error) {
|
||||
ret := _m.Called(postIds)
|
||||
|
||||
var r0 []*model.Reaction
|
||||
@@ -27,20 +27,18 @@ func (_m *ReactionStore) BulkGetForPosts(postIds []string) ([]*model.Reaction, *
|
||||
}
|
||||
}
|
||||
|
||||
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(postIds)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: reaction
|
||||
func (_m *ReactionStore) Delete(reaction *model.Reaction) (*model.Reaction, *model.AppError) {
|
||||
func (_m *ReactionStore) Delete(reaction *model.Reaction) (*model.Reaction, error) {
|
||||
ret := _m.Called(reaction)
|
||||
|
||||
var r0 *model.Reaction
|
||||
@@ -52,36 +50,32 @@ func (_m *ReactionStore) Delete(reaction *model.Reaction) (*model.Reaction, *mod
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.Reaction) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*model.Reaction) error); ok {
|
||||
r1 = rf(reaction)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// DeleteAllWithEmojiName provides a mock function with given fields: emojiName
|
||||
func (_m *ReactionStore) DeleteAllWithEmojiName(emojiName string) *model.AppError {
|
||||
func (_m *ReactionStore) DeleteAllWithEmojiName(emojiName string) error {
|
||||
ret := _m.Called(emojiName)
|
||||
|
||||
var r0 *model.AppError
|
||||
if rf, ok := ret.Get(0).(func(string) *model.AppError); ok {
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(string) error); ok {
|
||||
r0 = rf(emojiName)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.AppError)
|
||||
}
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// GetForPost provides a mock function with given fields: postId, allowFromCache
|
||||
func (_m *ReactionStore) GetForPost(postId string, allowFromCache bool) ([]*model.Reaction, *model.AppError) {
|
||||
func (_m *ReactionStore) GetForPost(postId string, allowFromCache bool) ([]*model.Reaction, error) {
|
||||
ret := _m.Called(postId, allowFromCache)
|
||||
|
||||
var r0 []*model.Reaction
|
||||
@@ -93,20 +87,18 @@ func (_m *ReactionStore) GetForPost(postId string, allowFromCache bool) ([]*mode
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(string, bool) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(string, bool) error); ok {
|
||||
r1 = rf(postId, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PermanentDeleteBatch provides a mock function with given fields: endTime, limit
|
||||
func (_m *ReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) {
|
||||
func (_m *ReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int64, error) {
|
||||
ret := _m.Called(endTime, limit)
|
||||
|
||||
var r0 int64
|
||||
@@ -116,20 +108,18 @@ func (_m *ReactionStore) PermanentDeleteBatch(endTime int64, limit int64) (int64
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(int64, int64) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(int64, int64) error); ok {
|
||||
r1 = rf(endTime, limit)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Save provides a mock function with given fields: reaction
|
||||
func (_m *ReactionStore) Save(reaction *model.Reaction) (*model.Reaction, *model.AppError) {
|
||||
func (_m *ReactionStore) Save(reaction *model.Reaction) (*model.Reaction, error) {
|
||||
ret := _m.Called(reaction)
|
||||
|
||||
var r0 *model.Reaction
|
||||
@@ -141,13 +131,11 @@ func (_m *ReactionStore) Save(reaction *model.Reaction) (*model.Reaction, *model
|
||||
}
|
||||
}
|
||||
|
||||
var r1 *model.AppError
|
||||
if rf, ok := ret.Get(1).(func(*model.Reaction) *model.AppError); ok {
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(*model.Reaction) error); ok {
|
||||
r1 = rf(reaction)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*model.AppError)
|
||||
}
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
|
||||
@@ -37,8 +37,8 @@ func testReactionSave(t *testing.T, ss store.Store) {
|
||||
PostId: post.Id,
|
||||
EmojiName: model.NewId(),
|
||||
}
|
||||
reaction, err := ss.Reaction().Save(reaction1)
|
||||
require.Nil(t, err)
|
||||
reaction, nErr := ss.Reaction().Save(reaction1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
saved := reaction
|
||||
assert.Equal(t, saved.UserId, reaction1.UserId, "should've saved reaction user_id and returned it")
|
||||
@@ -56,8 +56,8 @@ func testReactionSave(t *testing.T, ss store.Store) {
|
||||
secondUpdateAt = postList.Posts[post.Id].UpdateAt
|
||||
}
|
||||
|
||||
_, err = ss.Reaction().Save(reaction1)
|
||||
assert.Nil(t, err, "should've allowed saving a duplicate reaction")
|
||||
_, nErr = ss.Reaction().Save(reaction1)
|
||||
assert.Nil(t, nErr, "should've allowed saving a duplicate reaction")
|
||||
|
||||
// different user
|
||||
reaction2 := &model.Reaction{
|
||||
@@ -65,8 +65,8 @@ func testReactionSave(t *testing.T, ss store.Store) {
|
||||
PostId: reaction1.PostId,
|
||||
EmojiName: reaction1.EmojiName,
|
||||
}
|
||||
_, err = ss.Reaction().Save(reaction2)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.Reaction().Save(reaction2)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
postList, err = ss.Post().Get(reaction2.PostId, false)
|
||||
require.Nil(t, err)
|
||||
@@ -79,8 +79,8 @@ func testReactionSave(t *testing.T, ss store.Store) {
|
||||
PostId: model.NewId(),
|
||||
EmojiName: reaction1.EmojiName,
|
||||
}
|
||||
_, err = ss.Reaction().Save(reaction3)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.Reaction().Save(reaction3)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// different emoji
|
||||
reaction4 := &model.Reaction{
|
||||
@@ -88,16 +88,17 @@ func testReactionSave(t *testing.T, ss store.Store) {
|
||||
PostId: reaction1.PostId,
|
||||
EmojiName: model.NewId(),
|
||||
}
|
||||
_, err = ss.Reaction().Save(reaction4)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.Reaction().Save(reaction4)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// invalid reaction
|
||||
reaction5 := &model.Reaction{
|
||||
UserId: reaction1.UserId,
|
||||
PostId: reaction1.PostId,
|
||||
}
|
||||
_, err = ss.Reaction().Save(reaction5)
|
||||
require.NotNil(t, err, "should've failed for invalid reaction")
|
||||
_, nErr = ss.Reaction().Save(reaction5)
|
||||
require.NotNil(t, nErr, "should've failed for invalid reaction")
|
||||
|
||||
}
|
||||
|
||||
func testReactionDelete(t *testing.T, ss store.Store) {
|
||||
@@ -113,16 +114,16 @@ func testReactionDelete(t *testing.T, ss store.Store) {
|
||||
EmojiName: model.NewId(),
|
||||
}
|
||||
|
||||
_, err = ss.Reaction().Save(reaction)
|
||||
require.Nil(t, err)
|
||||
_, nErr := ss.Reaction().Save(reaction)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
result, err := ss.Post().Get(reaction.PostId, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
firstUpdateAt := result.Posts[post.Id].UpdateAt
|
||||
|
||||
_, err = ss.Reaction().Delete(reaction)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.Reaction().Delete(reaction)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
reactions, rErr := ss.Reaction().GetForPost(post.Id, false)
|
||||
require.Nil(t, rErr)
|
||||
@@ -341,9 +342,9 @@ func testReactionStorePermanentDeleteBatch(t *testing.T, ss store.Store) {
|
||||
// Need to hang on to a reaction to delete later in order to clear the cache, as "allowFromCache" isn't honoured any more.
|
||||
var lastReaction *model.Reaction
|
||||
for _, reaction := range reactions {
|
||||
var err *model.AppError
|
||||
lastReaction, err = ss.Reaction().Save(reaction)
|
||||
require.Nil(t, err)
|
||||
var nErr error
|
||||
lastReaction, nErr = ss.Reaction().Save(reaction)
|
||||
require.Nil(t, nErr)
|
||||
}
|
||||
|
||||
returned, err := ss.Reaction().GetForPost(post.Id, false)
|
||||
@@ -439,8 +440,8 @@ func testReactionDeadlock(t *testing.T, ss store.Store) {
|
||||
PostId: post.Id,
|
||||
EmojiName: model.NewId(),
|
||||
}
|
||||
_, err = ss.Reaction().Save(reaction1)
|
||||
require.Nil(t, err)
|
||||
_, nErr := ss.Reaction().Save(reaction1)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// different user
|
||||
reaction2 := &model.Reaction{
|
||||
@@ -448,8 +449,8 @@ func testReactionDeadlock(t *testing.T, ss store.Store) {
|
||||
PostId: reaction1.PostId,
|
||||
EmojiName: reaction1.EmojiName,
|
||||
}
|
||||
_, err = ss.Reaction().Save(reaction2)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.Reaction().Save(reaction2)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// different post
|
||||
reaction3 := &model.Reaction{
|
||||
@@ -457,8 +458,8 @@ func testReactionDeadlock(t *testing.T, ss store.Store) {
|
||||
PostId: model.NewId(),
|
||||
EmojiName: reaction1.EmojiName,
|
||||
}
|
||||
_, err = ss.Reaction().Save(reaction3)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.Reaction().Save(reaction3)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
// different emoji
|
||||
reaction4 := &model.Reaction{
|
||||
@@ -466,8 +467,8 @@ func testReactionDeadlock(t *testing.T, ss store.Store) {
|
||||
PostId: reaction1.PostId,
|
||||
EmojiName: model.NewId(),
|
||||
}
|
||||
_, err = ss.Reaction().Save(reaction4)
|
||||
require.Nil(t, err)
|
||||
_, nErr = ss.Reaction().Save(reaction4)
|
||||
require.Nil(t, nErr)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
|
||||
Ссылка в новой задаче
Block a user