Don't modify global variables in TestNoticeValidation (#27591)

This commit is contained in:
Ben Schumacher 2024-07-09 12:36:08 +02:00 committed by GitHub
parent 00dc08824c
commit 6fc5ff572f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 10 deletions

View File

@ -28,7 +28,7 @@ const MinSecondsBetweenRepeatViewings = 60 * 60
var noticesCache = utils.RequestCache{}
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,
notice *model.ProductNotice) (bool, error) {
cnd := notice.Conditions
@ -76,9 +76,9 @@ func noticeMatchesConditions(config *model.Config, preferences store.PreferenceS
// check if current server version is notice range
if !isCloud && cnd.ServerVersion != nil {
serverVersion, err := semver.NewVersion(model.CurrentVersion)
serverVersionSemver, err := semver.NewVersion(serverVersion)
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
}
for _, v := range cnd.ServerVersion {
@ -86,7 +86,7 @@ func noticeMatchesConditions(config *model.Config, preferences store.PreferenceS
if err != nil {
return false, errors.Wrapf(err, "Cannot parse version range %s", v)
}
if !c.Check(serverVersion) {
if !c.Check(serverVersionSemver) {
return false, nil
}
}
@ -268,6 +268,7 @@ func (a *App) GetProductNotices(c request.CTX, userID, teamID string, client mod
a.Srv().Store().Preference(),
userID,
client,
model.CurrentVersion,
clientVersion,
a.ch.cachedPostCount,
a.ch.cachedUserCount,

View File

@ -566,18 +566,17 @@ func TestNoticeValidation(t *testing.T) {
clientVersion = "1.2.3"
}
model.CurrentVersion = tt.args.serverVersion
if model.CurrentVersion == "" {
model.CurrentVersion = "5.26.1"
defer func() {
model.CurrentVersion = ""
}()
serverVersion := tt.args.serverVersion
if serverVersion == "" {
serverVersion = "5.26.1"
}
if ok, err := noticeMatchesConditions(
th.App.Config(),
th.App.Srv().Store().Preference(),
"test",
tt.args.client,
serverVersion,
clientVersion,
tt.args.postCount,
tt.args.userCount,