[MM-32665] app/product_notices: support notice for deprecating elasticsearch (#16966)

* app/product_notices: support notice for deprecating elasticsearch

* add a test case
This commit is contained in:
Ibrahim Serdar Acikgoz
2021-02-23 13:38:50 +03:00
committed by GitHub
parent 7277e23e04
commit 6d320ce9a0
3 changed files with 42 additions and 1 deletions
+19 -1
View File
@@ -54,7 +54,7 @@ func cleanupVersion(originalVersion string) string {
func noticeMatchesConditions(config *model.Config, preferences store.PreferenceStore, userID string,
client model.NoticeClientType, clientVersion string, postCount int64, userCount int64, isSystemAdmin bool,
isTeamAdmin bool, isCloud bool, sku, dbName, dbVer string,
isTeamAdmin bool, isCloud bool, sku, dbName, dbVer, searchEngineName, searchEngineVer string,
notice *model.ProductNotice) (bool, error) {
cnd := notice.Conditions
@@ -163,6 +163,15 @@ func noticeMatchesConditions(config *model.Config, preferences store.PreferenceS
return false, errors.Wrapf(err, "Cannot parse DBMS version %s", dbVer)
}
return extDepVersion.GreaterThan(serverDBMSVersion), nil
case model.SEARCHENGINE_ELASTICSEARCH:
if searchEngineName != model.SEARCHENGINE_ELASTICSEARCH {
return false, nil
}
semverESVersion, err := semver.NewVersion(searchEngineVer)
if err != nil {
return false, errors.Wrapf(err, "Cannot parse search engine version %s", searchEngineVer)
}
return extDepVersion.GreaterThan(semverESVersion), nil
default:
return false, nil
}
@@ -251,6 +260,13 @@ func (a *App) GetProductNotices(userID, teamID string, client model.NoticeClient
isCloud := a.Srv().License() != nil && *a.Srv().License().Features.Cloud
dbName := *a.Srv().Config().SqlSettings.DriverName
var searchEngineName, searchEngineVersion string
engine := a.SearchEngine().ElasticsearchEngine
if engine != nil {
searchEngineName = a.Srv().SearchEngine.ElasticsearchEngine.GetName()
searchEngineVersion = a.Srv().SearchEngine.ElasticsearchEngine.GetFullVersion()
}
filteredNotices := make([]model.NoticeMessage, 0)
for noticeIndex, notice := range cachedNotices {
@@ -289,6 +305,8 @@ func (a *App) GetProductNotices(userID, teamID string, client model.NoticeClient
sku,
dbName,
cachedDBMSVersion,
searchEngineName,
searchEngineVersion,
&cachedNotices[noticeIndex])
if err != nil {
return nil, model.NewAppError("GetProductNotices", "api.system.update_notices.validating_failed", nil, err.Error(), http.StatusBadRequest)
+21
View File
@@ -62,6 +62,8 @@ func TestNoticeValidation(t *testing.T) {
notice *model.ProductNotice
dbmsName string
dbmsVer string
searchEngineName string
searchEngineVer string
}
messages := map[string]model.NoticeMessageInternal{
"en": {
@@ -610,6 +612,23 @@ func TestNoticeValidation(t *testing.T) {
wantErr: false,
wantOk: false,
},
{
name: "notice on deprecating elasticsearch, server has unsupported search engine",
args: args{
searchEngineName: "elasticsearch",
searchEngineVer: "6.4.1",
notice: &model.ProductNotice{
Conditions: model.Conditions{
DeprecatingDependency: &model.ExternalDependency{
Name: "elasticsearch",
MinimumVersion: "7",
},
},
},
},
wantErr: false,
wantOk: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -635,6 +654,8 @@ func TestNoticeValidation(t *testing.T) {
tt.args.sku,
tt.args.dbmsName,
tt.args.dbmsVer,
tt.args.searchEngineName,
tt.args.searchEngineVer,
tt.args.notice,
); (err != nil) != tt.wantErr {
t.Errorf("noticeMatchesConditions() error = %v, wantErr %v", err, tt.wantErr)
+2
View File
@@ -36,6 +36,8 @@ const (
DATABASE_DRIVER_MYSQL = "mysql"
DATABASE_DRIVER_POSTGRES = "postgres"
SEARCHENGINE_ELASTICSEARCH = "elasticsearch"
MINIO_ACCESS_KEY = "minioaccesskey"
MINIO_SECRET_KEY = "miniosecretkey"
MINIO_BUCKET = "mattermost-test"