re-assign cluster interface after initializing enterprise interfaces (#20839)
* re-assign cluster interface after initializing enterprise interfaces * add a unit test to check if cluster is triggered * remove env overrides Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3498592a45
Коммит
8e0d46e0c6
@@ -114,6 +114,7 @@ func RegisterLicenseInterface(f func(*Server) einterfaces.LicenseInterface) {
|
|||||||
func (s *Server) initEnterprise() {
|
func (s *Server) initEnterprise() {
|
||||||
if clusterInterface != nil && s.Cluster == nil {
|
if clusterInterface != nil && s.Cluster == nil {
|
||||||
s.Cluster = clusterInterface(s)
|
s.Cluster = clusterInterface(s)
|
||||||
|
s.platform.SetCluster(s.Cluster)
|
||||||
}
|
}
|
||||||
if elasticsearchInterface != nil {
|
if elasticsearchInterface != nil {
|
||||||
s.SearchEngine.RegisterElasticsearchEngine(elasticsearchInterface(s))
|
s.SearchEngine.RegisterElasticsearchEngine(elasticsearchInterface(s))
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
package platform
|
package platform
|
||||||
|
|
||||||
|
import "github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||||
|
|
||||||
func (ps *PlatformService) IsLeader() bool {
|
func (ps *PlatformService) IsLeader() bool {
|
||||||
if ps.License() != nil && *ps.Config().ClusterSettings.Enable && ps.cluster != nil {
|
if ps.License() != nil && *ps.Config().ClusterSettings.Enable && ps.cluster != nil {
|
||||||
return ps.cluster.IsLeader()
|
return ps.cluster.IsLeader()
|
||||||
@@ -10,3 +12,7 @@ func (ps *PlatformService) IsLeader() bool {
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ps *PlatformService) SetCluster(impl einterfaces.ClusterInterface) {
|
||||||
|
ps.cluster = impl
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,3 +47,28 @@ func TestConfigListener(t *testing.T) {
|
|||||||
assert.True(t, listenerCalled, "listener should've been called")
|
assert.True(t, listenerCalled, "listener should've been called")
|
||||||
assert.True(t, listener2Called, "listener 2 should've been called")
|
assert.True(t, listener2Called, "listener 2 should've been called")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigSave(t *testing.T) {
|
||||||
|
th := Setup(t)
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
cm := &mocks.ClusterInterface{}
|
||||||
|
th.Service.SetCluster(cm)
|
||||||
|
|
||||||
|
t.Run("trigger a config changed event for the cluster", func(t *testing.T) {
|
||||||
|
oldCfg := th.Service.Config()
|
||||||
|
newCfg := oldCfg.Clone()
|
||||||
|
newCfg.ServiceSettings.SiteURL = model.NewString("http://newhost.me")
|
||||||
|
|
||||||
|
sanitizedOldCfg := th.Service.configStore.RemoveEnvironmentOverrides(oldCfg)
|
||||||
|
sanitizedNewCfg := th.Service.configStore.RemoveEnvironmentOverrides(newCfg)
|
||||||
|
|
||||||
|
cm.On("ConfigChanged", sanitizedOldCfg, sanitizedNewCfg, true).Return(nil)
|
||||||
|
|
||||||
|
_, _, appErr := th.Service.SaveConfig(newCfg, true)
|
||||||
|
require.Nil(t, appErr)
|
||||||
|
|
||||||
|
updatedCfg := th.Service.Config()
|
||||||
|
assert.Equal(t, "http://newhost.me", *updatedCfg.ServiceSettings.SiteURL)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user