Migrate Overwrite and GetMaxPostSize() in PostStore to sync by default (#10829)

* Migrate Overwrite and GetMaxPostSize() in PostStore to sync by default

* GH-10762: fix return type for mock func

* GH-10762: fix tests for MaxPostSize() mocks

* fix imports
This commit is contained in:
PR
2019-05-17 01:46:18 -07:00
committed by Jesús Espino
parent fab2e349b3
commit 6d2fa0f3d2
7 changed files with 60 additions and 87 deletions

View File

@@ -898,8 +898,8 @@ func (a *App) ImportReply(data *ReplyImportData, post *model.Post, teamId string
return result.Err
}
} else {
if result := <-a.Srv.Store.Post().Overwrite(reply); result.Err != nil {
return result.Err
if _, err := a.Srv.Store.Post().Overwrite(reply); err != nil {
return err
}
}
@@ -1000,8 +1000,8 @@ func (a *App) ImportPost(data *PostImportData, dryRun bool) *model.AppError {
return result.Err
}
} else {
if result := <-a.Srv.Store.Post().Overwrite(post); result.Err != nil {
return result.Err
if _, err := a.Srv.Store.Post().Overwrite(post); err != nil {
return err
}
}
@@ -1224,8 +1224,8 @@ func (a *App) ImportDirectPost(data *DirectPostImportData, dryRun bool) *model.A
return result.Err
}
} else {
if result := <-a.Srv.Store.Post().Overwrite(post); result.Err != nil {
return result.Err
if _, err := a.Srv.Store.Post().Overwrite(post); err != nil {
return err
}
}

View File

@@ -315,9 +315,8 @@ func (a *App) attachFilesToPost(post *model.Post) *model.AppError {
// We couldn't attach all files to the post, so ensure that post.FileIds reflects what was actually attached
post.FileIds = attachedIds
result := <-a.Srv.Store.Post().Overwrite(post)
if result.Err != nil {
return result.Err
if _, err := a.Srv.Store.Post().Overwrite(post); err != nil {
return err
}
}
@@ -1027,10 +1026,10 @@ func (a *App) ImageProxyRemover() (f func(string) string) {
}
func (a *App) MaxPostSize() int {
result := <-a.Srv.Store.Post().GetMaxPostSize()
if result.Err != nil {
mlog.Error(fmt.Sprint(result.Err))
maxPostSize := a.Srv.Store.Post().GetMaxPostSize()
if maxPostSize == 0 {
return model.POST_MESSAGE_MAX_RUNES_V1
}
return result.Data.(int)
return maxPostSize
}

View File

@@ -14,7 +14,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
"github.com/mattermost/mattermost-server/store/storetest"
)
@@ -565,25 +564,21 @@ func TestMaxPostSize(t *testing.T) {
Description string
StoreMaxPostSize int
ExpectedMaxPostSize int
ExpectedError *model.AppError
}{
{
"error fetching max post size",
"Max post size less than model.model.POST_MESSAGE_MAX_RUNES_V1 ",
0,
model.POST_MESSAGE_MAX_RUNES_V1,
model.NewAppError("TestMaxPostSize", "this is an error", nil, "", http.StatusBadRequest),
},
{
"4000 rune limit",
4000,
4000,
nil,
},
{
"16383 rune limit",
16383,
16383,
nil,
},
}
@@ -595,12 +590,7 @@ func TestMaxPostSize(t *testing.T) {
mockStore := &storetest.Store{}
defer mockStore.AssertExpectations(t)
mockStore.PostStore.On("GetMaxPostSize").Return(
storetest.NewStoreChannel(store.StoreResult{
Data: testCase.StoreMaxPostSize,
Err: testCase.ExpectedError,
}),
)
mockStore.PostStore.On("GetMaxPostSize").Return(testCase.StoreMaxPostSize)
app := App{
Srv: &Server{