Migrate emojiStore to use request.CTX instead of context.Context (#24514)
* migrate emojistore to request.ctx * use mlog.CreateConsoleTestLogger * Add comment to WithMaster and RequestContextWithMaster
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e9cc03c1c8
Коммит
f65dad83bb
@@ -4,11 +4,11 @@
|
||||
package storetest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -53,6 +53,8 @@ func testEmojiSaveDelete(t *testing.T, ss store.Store) {
|
||||
}
|
||||
|
||||
func testEmojiGet(t *testing.T, ss store.Store) {
|
||||
c := request.TestContext(t)
|
||||
|
||||
emojis := []model.Emoji{
|
||||
{
|
||||
CreatorId: model.NewId(),
|
||||
@@ -81,17 +83,19 @@ func testEmojiGet(t *testing.T, ss store.Store) {
|
||||
}()
|
||||
|
||||
for _, emoji := range emojis {
|
||||
_, err := ss.Emoji().Get(context.Background(), emoji.Id, false)
|
||||
_, err := ss.Emoji().Get(c, emoji.Id, false)
|
||||
require.NoErrorf(t, err, "failed to get emoji with id %v", emoji.Id)
|
||||
}
|
||||
|
||||
for _, emoji := range emojis {
|
||||
_, err := ss.Emoji().Get(context.Background(), emoji.Id, true)
|
||||
_, err := ss.Emoji().Get(c, emoji.Id, true)
|
||||
require.NoErrorf(t, err, "failed to get emoji with id %v", emoji.Id)
|
||||
}
|
||||
}
|
||||
|
||||
func testEmojiGetByName(t *testing.T, ss store.Store) {
|
||||
c := request.TestContext(t)
|
||||
|
||||
emojis := []model.Emoji{
|
||||
{
|
||||
CreatorId: model.NewId(),
|
||||
@@ -120,12 +124,14 @@ func testEmojiGetByName(t *testing.T, ss store.Store) {
|
||||
}()
|
||||
|
||||
for _, emoji := range emojis {
|
||||
_, err := ss.Emoji().GetByName(context.Background(), emoji.Name, true)
|
||||
_, err := ss.Emoji().GetByName(c, emoji.Name, true)
|
||||
require.NoErrorf(t, err, "failed to get emoji with name %v", emoji.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func testEmojiGetMultipleByName(t *testing.T, ss store.Store) {
|
||||
c := request.TestContext(t)
|
||||
|
||||
emojis := []model.Emoji{
|
||||
{
|
||||
CreatorId: model.NewId(),
|
||||
@@ -154,26 +160,26 @@ func testEmojiGetMultipleByName(t *testing.T, ss store.Store) {
|
||||
}()
|
||||
|
||||
t.Run("one emoji", func(t *testing.T) {
|
||||
received, err := ss.Emoji().GetMultipleByName(context.Background(), []string{emojis[0].Name})
|
||||
received, err := ss.Emoji().GetMultipleByName(c, []string{emojis[0].Name})
|
||||
require.NoError(t, err, "could not get emoji")
|
||||
require.Len(t, received, 1, "got incorrect emoji")
|
||||
require.Equal(t, *received[0], emojis[0], "got incorrect emoji")
|
||||
})
|
||||
|
||||
t.Run("multiple emojis", func(t *testing.T) {
|
||||
received, err := ss.Emoji().GetMultipleByName(context.Background(), []string{emojis[0].Name, emojis[1].Name, emojis[2].Name})
|
||||
received, err := ss.Emoji().GetMultipleByName(c, []string{emojis[0].Name, emojis[1].Name, emojis[2].Name})
|
||||
require.NoError(t, err, "could not get emojis")
|
||||
require.Len(t, received, 3, "got incorrect emojis")
|
||||
})
|
||||
|
||||
t.Run("one nonexistent emoji", func(t *testing.T) {
|
||||
received, err := ss.Emoji().GetMultipleByName(context.Background(), []string{"ab"})
|
||||
received, err := ss.Emoji().GetMultipleByName(c, []string{"ab"})
|
||||
require.NoError(t, err, "could not get emoji", err)
|
||||
require.Empty(t, received, "got incorrect emoji")
|
||||
})
|
||||
|
||||
t.Run("multiple emojis with nonexistent names", func(t *testing.T) {
|
||||
received, err := ss.Emoji().GetMultipleByName(context.Background(), []string{emojis[0].Name, emojis[1].Name, emojis[2].Name, "abcd", "1234"})
|
||||
received, err := ss.Emoji().GetMultipleByName(c, []string{emojis[0].Name, emojis[1].Name, emojis[2].Name, "abcd", "1234"})
|
||||
require.NoError(t, err, "could not get emojis")
|
||||
require.Len(t, received, 3, "got incorrect emojis")
|
||||
})
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
model "github.com/mattermost/mattermost/server/public/model"
|
||||
request "github.com/mattermost/mattermost/server/public/shared/request"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
@@ -31,15 +30,15 @@ func (_m *EmojiStore) Delete(emoji *model.Emoji, timestamp int64) error {
|
||||
}
|
||||
|
||||
// Get provides a mock function with given fields: ctx, id, allowFromCache
|
||||
func (_m *EmojiStore) Get(ctx context.Context, id string, allowFromCache bool) (*model.Emoji, error) {
|
||||
func (_m *EmojiStore) Get(ctx request.CTX, id string, allowFromCache bool) (*model.Emoji, error) {
|
||||
ret := _m.Called(ctx, id, allowFromCache)
|
||||
|
||||
var r0 *model.Emoji
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, bool) (*model.Emoji, error)); ok {
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, bool) (*model.Emoji, error)); ok {
|
||||
return rf(ctx, id, allowFromCache)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, bool) *model.Emoji); ok {
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, bool) *model.Emoji); ok {
|
||||
r0 = rf(ctx, id, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -47,7 +46,7 @@ func (_m *EmojiStore) Get(ctx context.Context, id string, allowFromCache bool) (
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, bool) error); ok {
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, string, bool) error); ok {
|
||||
r1 = rf(ctx, id, allowFromCache)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
@@ -57,15 +56,15 @@ func (_m *EmojiStore) Get(ctx context.Context, id string, allowFromCache bool) (
|
||||
}
|
||||
|
||||
// GetByName provides a mock function with given fields: ctx, name, allowFromCache
|
||||
func (_m *EmojiStore) GetByName(ctx context.Context, name string, allowFromCache bool) (*model.Emoji, error) {
|
||||
func (_m *EmojiStore) GetByName(ctx request.CTX, name string, allowFromCache bool) (*model.Emoji, error) {
|
||||
ret := _m.Called(ctx, name, allowFromCache)
|
||||
|
||||
var r0 *model.Emoji
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, bool) (*model.Emoji, error)); ok {
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, bool) (*model.Emoji, error)); ok {
|
||||
return rf(ctx, name, allowFromCache)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, bool) *model.Emoji); ok {
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, string, bool) *model.Emoji); ok {
|
||||
r0 = rf(ctx, name, allowFromCache)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -73,7 +72,7 @@ func (_m *EmojiStore) GetByName(ctx context.Context, name string, allowFromCache
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, bool) error); ok {
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, string, bool) error); ok {
|
||||
r1 = rf(ctx, name, allowFromCache)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
@@ -109,15 +108,15 @@ func (_m *EmojiStore) GetList(offset int, limit int, sort string) ([]*model.Emoj
|
||||
}
|
||||
|
||||
// GetMultipleByName provides a mock function with given fields: ctx, names
|
||||
func (_m *EmojiStore) GetMultipleByName(ctx context.Context, names []string) ([]*model.Emoji, error) {
|
||||
func (_m *EmojiStore) GetMultipleByName(ctx request.CTX, names []string) ([]*model.Emoji, error) {
|
||||
ret := _m.Called(ctx, names)
|
||||
|
||||
var r0 []*model.Emoji
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, []string) ([]*model.Emoji, error)); ok {
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, []string) ([]*model.Emoji, error)); ok {
|
||||
return rf(ctx, names)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, []string) []*model.Emoji); ok {
|
||||
if rf, ok := ret.Get(0).(func(request.CTX, []string) []*model.Emoji); ok {
|
||||
r0 = rf(ctx, names)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
@@ -125,7 +124,7 @@ func (_m *EmojiStore) GetMultipleByName(ctx context.Context, names []string) ([]
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, []string) error); ok {
|
||||
if rf, ok := ret.Get(1).(func(request.CTX, []string) error); ok {
|
||||
r1 = rf(ctx, names)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
|
||||
Ссылка в новой задаче
Block a user