mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Don't modify global variables in TestNoticeValidation (#27591)
This commit is contained in:
parent
00dc08824c
commit
6fc5ff572f
@ -28,7 +28,7 @@ const MinSecondsBetweenRepeatViewings = 60 * 60
|
|||||||
var noticesCache = utils.RequestCache{}
|
var noticesCache = utils.RequestCache{}
|
||||||
|
|
||||||
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userID string,
|
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userID string,
|
||||||
client model.NoticeClientType, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool,
|
client model.NoticeClientType, serverVersion, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool,
|
||||||
isTeamAdmin bool, isCloud bool, sku, dbName, dbVer, searchEngineName, searchEngineVer string,
|
isTeamAdmin bool, isCloud bool, sku, dbName, dbVer, searchEngineName, searchEngineVer string,
|
||||||
notice *model.ProductNotice) (bool, error) {
|
notice *model.ProductNotice) (bool, error) {
|
||||||
cnd := notice.Conditions
|
cnd := notice.Conditions
|
||||||
@ -76,9 +76,9 @@ func noticeMatchesConditions(config *model.Config, preferences store.PreferenceS
|
|||||||
|
|
||||||
// check if current server version is notice range
|
// check if current server version is notice range
|
||||||
if !isCloud && cnd.ServerVersion != nil {
|
if !isCloud && cnd.ServerVersion != nil {
|
||||||
serverVersion, err := semver.NewVersion(model.CurrentVersion)
|
serverVersionSemver, err := semver.NewVersion(serverVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Warn("Version number is not in semver format", mlog.String("version_number", model.CurrentVersion))
|
mlog.Warn("Version number is not in semver format", mlog.String("version_number", serverVersion))
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
for _, v := range cnd.ServerVersion {
|
for _, v := range cnd.ServerVersion {
|
||||||
@ -86,7 +86,7 @@ func noticeMatchesConditions(config *model.Config, preferences store.PreferenceS
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrapf(err, "Cannot parse version range %s", v)
|
return false, errors.Wrapf(err, "Cannot parse version range %s", v)
|
||||||
}
|
}
|
||||||
if !c.Check(serverVersion) {
|
if !c.Check(serverVersionSemver) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -268,6 +268,7 @@ func (a *App) GetProductNotices(c request.CTX, userID, teamID string, client mod
|
|||||||
a.Srv().Store().Preference(),
|
a.Srv().Store().Preference(),
|
||||||
userID,
|
userID,
|
||||||
client,
|
client,
|
||||||
|
model.CurrentVersion,
|
||||||
clientVersion,
|
clientVersion,
|
||||||
a.ch.cachedPostCount,
|
a.ch.cachedPostCount,
|
||||||
a.ch.cachedUserCount,
|
a.ch.cachedUserCount,
|
||||||
|
@ -566,18 +566,17 @@ func TestNoticeValidation(t *testing.T) {
|
|||||||
clientVersion = "1.2.3"
|
clientVersion = "1.2.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
model.CurrentVersion = tt.args.serverVersion
|
serverVersion := tt.args.serverVersion
|
||||||
if model.CurrentVersion == "" {
|
if serverVersion == "" {
|
||||||
model.CurrentVersion = "5.26.1"
|
serverVersion = "5.26.1"
|
||||||
defer func() {
|
|
||||||
model.CurrentVersion = ""
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok, err := noticeMatchesConditions(
|
if ok, err := noticeMatchesConditions(
|
||||||
th.App.Config(),
|
th.App.Config(),
|
||||||
th.App.Srv().Store().Preference(),
|
th.App.Srv().Store().Preference(),
|
||||||
"test",
|
"test",
|
||||||
tt.args.client,
|
tt.args.client,
|
||||||
|
serverVersion,
|
||||||
clientVersion,
|
clientVersion,
|
||||||
tt.args.postCount,
|
tt.args.postCount,
|
||||||
tt.args.userCount,
|
tt.args.userCount,
|
||||||
|
Loading…
Reference in New Issue
Block a user