Simplify request generation in store tests (#25422)

Этот коммит содержится в:
Ben Schumacher
2023-11-16 09:51:18 +01:00
коммит произвёл GitHub
родитель 51715d5ed6
Коммит afb48219c0
52 изменённых файлов: 1666 добавлений и 1752 удалений

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

@@ -378,7 +378,7 @@ func createUserAccessToken(ss store.Store, userId string) *model.UserAccessToken
}
func TestCheckIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
ss.DropAllTables()
t.Run("generate reports with no records", func(t *testing.T) {
results := ss.CheckIntegrity()
@@ -396,7 +396,7 @@ func TestCheckIntegrity(t *testing.T) {
}
func TestCheckParentChildIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
t.Run("should receive an error", func(t *testing.T) {
config := relationalCheckConfig{
@@ -413,7 +413,7 @@ func TestCheckParentChildIntegrity(t *testing.T) {
}
func TestCheckChannelsCommandWebhooksIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -440,7 +440,7 @@ func TestCheckChannelsCommandWebhooksIntegrity(t *testing.T) {
}
func TestCheckChannelsChannelMemberHistoryIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -471,7 +471,7 @@ func TestCheckChannelsChannelMemberHistoryIntegrity(t *testing.T) {
}
func TestCheckChannelsChannelMembersIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -499,7 +499,7 @@ func TestCheckChannelsChannelMembersIntegrity(t *testing.T) {
}
func TestCheckChannelsIncomingWebhooksIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -527,7 +527,7 @@ func TestCheckChannelsIncomingWebhooksIntegrity(t *testing.T) {
}
func TestCheckChannelsOutgoingWebhooksIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -557,7 +557,7 @@ func TestCheckChannelsOutgoingWebhooksIntegrity(t *testing.T) {
}
func TestCheckChannelsPostsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -584,7 +584,7 @@ func TestCheckChannelsPostsIntegrity(t *testing.T) {
}
func TestCheckCommandsCommandWebhooksIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -612,7 +612,7 @@ func TestCheckCommandsCommandWebhooksIntegrity(t *testing.T) {
}
func TestCheckPostsFileInfoIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -640,7 +640,7 @@ func TestCheckPostsFileInfoIntegrity(t *testing.T) {
}
func TestCheckPostsPostsRootIdIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -673,7 +673,7 @@ func TestCheckPostsPostsRootIdIntegrity(t *testing.T) {
}
func TestCheckPostsReactionsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -700,7 +700,7 @@ func TestCheckPostsReactionsIntegrity(t *testing.T) {
}
func TestCheckSchemesChannelsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -731,7 +731,7 @@ func TestCheckSchemesChannelsIntegrity(t *testing.T) {
}
func TestCheckSchemesTeamsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -762,8 +762,7 @@ func TestCheckSchemesTeamsIntegrity(t *testing.T) {
}
func TestCheckSessionsAuditsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
c := request.TestContext(t)
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -776,7 +775,7 @@ func TestCheckSessionsAuditsIntegrity(t *testing.T) {
t.Run("should generate a report with one record", func(t *testing.T) {
userId := model.NewId()
session := createSession(c, ss, model.NewId())
session := createSession(rctx, ss, model.NewId())
sessionId := session.Id
audit := createAudit(ss, userId, sessionId)
dbmap.Exec(`DELETE FROM Sessions WHERE Id=?`, session.Id)
@@ -794,7 +793,7 @@ func TestCheckSessionsAuditsIntegrity(t *testing.T) {
}
func TestCheckTeamsChannelsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -870,7 +869,7 @@ func TestCheckTeamsChannelsIntegrity(t *testing.T) {
}
func TestCheckTeamsCommandsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -898,7 +897,7 @@ func TestCheckTeamsCommandsIntegrity(t *testing.T) {
}
func TestCheckTeamsIncomingWebhooksIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -926,7 +925,7 @@ func TestCheckTeamsIncomingWebhooksIntegrity(t *testing.T) {
}
func TestCheckTeamsOutgoingWebhooksIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -954,7 +953,7 @@ func TestCheckTeamsOutgoingWebhooksIntegrity(t *testing.T) {
}
func TestCheckTeamsTeamMembersIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -982,7 +981,7 @@ func TestCheckTeamsTeamMembersIntegrity(t *testing.T) {
}
func TestCheckUsersAuditsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1012,7 +1011,7 @@ func TestCheckUsersAuditsIntegrity(t *testing.T) {
}
func TestCheckUsersCommandWebhooksIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1040,7 +1039,7 @@ func TestCheckUsersCommandWebhooksIntegrity(t *testing.T) {
}
func TestCheckUsersChannelsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1067,7 +1066,7 @@ func TestCheckUsersChannelsIntegrity(t *testing.T) {
}
func TestCheckUsersChannelMemberHistoryIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1097,7 +1096,7 @@ func TestCheckUsersChannelMemberHistoryIntegrity(t *testing.T) {
}
func TestCheckUsersChannelMembersIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1127,7 +1126,7 @@ func TestCheckUsersChannelMembersIntegrity(t *testing.T) {
}
func TestCheckUsersCommandsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1155,7 +1154,7 @@ func TestCheckUsersCommandsIntegrity(t *testing.T) {
}
func TestCheckUsersCompliancesIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1185,7 +1184,7 @@ func TestCheckUsersCompliancesIntegrity(t *testing.T) {
}
func TestCheckUsersEmojiIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1215,7 +1214,7 @@ func TestCheckUsersEmojiIntegrity(t *testing.T) {
}
func TestCheckUsersFileInfoIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1245,7 +1244,7 @@ func TestCheckUsersFileInfoIntegrity(t *testing.T) {
}
func TestCheckUsersIncomingWebhooksIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1273,7 +1272,7 @@ func TestCheckUsersIncomingWebhooksIntegrity(t *testing.T) {
}
func TestCheckUsersOAuthAccessDataIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1303,7 +1302,7 @@ func TestCheckUsersOAuthAccessDataIntegrity(t *testing.T) {
}
func TestCheckUsersOAuthAppsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1333,7 +1332,7 @@ func TestCheckUsersOAuthAppsIntegrity(t *testing.T) {
}
func TestCheckUsersOAuthAuthDataIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1363,7 +1362,7 @@ func TestCheckUsersOAuthAuthDataIntegrity(t *testing.T) {
}
func TestCheckUsersOutgoingWebhooksIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1391,7 +1390,7 @@ func TestCheckUsersOutgoingWebhooksIntegrity(t *testing.T) {
}
func TestCheckUsersPostsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1418,7 +1417,7 @@ func TestCheckUsersPostsIntegrity(t *testing.T) {
}
func TestCheckUsersPreferencesIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1464,7 +1463,7 @@ func TestCheckUsersPreferencesIntegrity(t *testing.T) {
}
func TestCheckUsersReactionsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1493,8 +1492,7 @@ func TestCheckUsersReactionsIntegrity(t *testing.T) {
}
func TestCheckUsersSessionsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
c := request.TestContext(t)
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1507,7 +1505,7 @@ func TestCheckUsersSessionsIntegrity(t *testing.T) {
t.Run("should generate a report with one record", func(t *testing.T) {
userId := model.NewId()
session := createSession(c, ss, userId)
session := createSession(rctx, ss, userId)
result := checkUsersSessionsIntegrity(store)
require.NoError(t, result.Err)
data := result.Data.(model.RelationalIntegrityCheckData)
@@ -1522,7 +1520,7 @@ func TestCheckUsersSessionsIntegrity(t *testing.T) {
}
func TestCheckUsersStatusIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1551,7 +1549,7 @@ func TestCheckUsersStatusIntegrity(t *testing.T) {
}
func TestCheckUsersTeamMembersIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1581,7 +1579,7 @@ func TestCheckUsersTeamMembersIntegrity(t *testing.T) {
}
func TestCheckUsersUserAccessTokensIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()
@@ -1611,7 +1609,7 @@ func TestCheckUsersUserAccessTokensIntegrity(t *testing.T) {
}
func TestCheckThreadsTeamsIntegrity(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
store := ss.(*SqlStore)
dbmap := store.GetMasterX()

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

@@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
"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/mattermost/mattermost/server/v8/channels/store/storetest"
)
@@ -18,7 +19,7 @@ func TestPreferenceStore(t *testing.T) {
}
func TestDeleteUnusedFeatures(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
userId1 := model.NewId()
userId2 := model.NewId()
category := model.PreferenceCategoryAdvancedSettings

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

@@ -24,6 +24,7 @@ import (
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin/plugintest/mock"
"github.com/mattermost/mattermost/server/public/shared/request"
"github.com/mattermost/mattermost/server/v8/channels/db"
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/channels/store/searchtest"
@@ -47,7 +48,7 @@ func newStoreType(name, driver string) *storeType {
}
}
func StoreTest(t *testing.T, f func(*testing.T, store.Store)) {
func StoreTest(t *testing.T, f func(*testing.T, request.CTX, store.Store)) {
defer func() {
if err := recover(); err != nil {
tearDownStores()
@@ -56,11 +57,13 @@ func StoreTest(t *testing.T, f func(*testing.T, store.Store)) {
}()
for _, st := range storeTypes {
st := st
rctx := request.TestContext(t)
t.Run(st.Name, func(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
f(t, st.Store)
f(t, rctx, st.Store)
})
}
}
@@ -83,7 +86,7 @@ func StoreTestWithSearchTestEngine(t *testing.T, f func(*testing.T, store.Store,
}
}
func StoreTestWithSqlStore(t *testing.T, f func(*testing.T, store.Store, storetest.SqlStore)) {
func StoreTestWithSqlStore(t *testing.T, f func(*testing.T, request.CTX, store.Store, storetest.SqlStore)) {
defer func() {
if err := recover(); err != nil {
tearDownStores()
@@ -92,11 +95,13 @@ func StoreTestWithSqlStore(t *testing.T, f func(*testing.T, store.Store, storete
}()
for _, st := range storeTypes {
st := st
rctx := request.TestContext(t)
t.Run(st.Name, func(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
f(t, st.Store, &StoreTestWrapper{st.SqlStore})
f(t, rctx, st.Store, &StoreTestWrapper{st.SqlStore})
})
}
}
@@ -803,7 +808,7 @@ func makeSqlSettings(driver string) (*model.SqlSettings, error) {
}
func TestExecNoTimeout(t *testing.T) {
StoreTest(t, func(t *testing.T, ss store.Store) {
StoreTest(t, func(t *testing.T, rctx request.CTX, ss store.Store) {
sqlStore := ss.(*SqlStore)
var query string
timeout := sqlStore.masterX.queryTimeout