mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
plugin/helpers: fix an unchecked issue when comparing two conf… (#13748)
This commit is contained in:
committed by
GitHub
parent
40b7790318
commit
99a82ef07e
@@ -18,7 +18,7 @@ func (p *HelpersImpl) CheckRequiredServerConfiguration(req *model.Config) (bool,
|
||||
|
||||
cfg := p.API.GetConfig()
|
||||
|
||||
mc, err := utils.Merge(req, cfg, nil)
|
||||
mc, err := utils.Merge(cfg, req, nil)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "could not merge configurations")
|
||||
}
|
||||
|
||||
@@ -27,12 +27,15 @@ func TestCheckRequiredServerConfiguration(t *testing.T) {
|
||||
ShouldReturn: true,
|
||||
ShouldError: false,
|
||||
},
|
||||
"same configurations": {
|
||||
"contains required configuration": {
|
||||
SetupAPI: func(api *plugintest.API) *plugintest.API {
|
||||
api.On("GetConfig").Return(&model.Config{
|
||||
ServiceSettings: model.ServiceSettings{
|
||||
EnableCommands: model.NewBool(true),
|
||||
},
|
||||
TeamSettings: model.TeamSettings{
|
||||
EnableUserCreation: model.NewBool(true),
|
||||
},
|
||||
})
|
||||
|
||||
return api
|
||||
@@ -45,7 +48,46 @@ func TestCheckRequiredServerConfiguration(t *testing.T) {
|
||||
ShouldReturn: true,
|
||||
ShouldError: false,
|
||||
},
|
||||
"does not contain required configuration": {
|
||||
SetupAPI: func(api *plugintest.API) *plugintest.API {
|
||||
api.On("GetConfig").Return(&model.Config{
|
||||
ServiceSettings: model.ServiceSettings{
|
||||
EnableCommands: model.NewBool(true),
|
||||
},
|
||||
})
|
||||
|
||||
return api
|
||||
},
|
||||
Input: &model.Config{
|
||||
ServiceSettings: model.ServiceSettings{
|
||||
EnableCommands: model.NewBool(true),
|
||||
},
|
||||
TeamSettings: model.TeamSettings{
|
||||
EnableUserCreation: model.NewBool(true),
|
||||
},
|
||||
},
|
||||
ShouldReturn: false,
|
||||
ShouldError: false,
|
||||
},
|
||||
"different configurations": {
|
||||
SetupAPI: func(api *plugintest.API) *plugintest.API {
|
||||
api.On("GetConfig").Return(&model.Config{
|
||||
ServiceSettings: model.ServiceSettings{
|
||||
EnableCommands: model.NewBool(false),
|
||||
},
|
||||
})
|
||||
|
||||
return api
|
||||
},
|
||||
Input: &model.Config{
|
||||
ServiceSettings: model.ServiceSettings{
|
||||
EnableCommands: model.NewBool(true),
|
||||
},
|
||||
},
|
||||
ShouldReturn: false,
|
||||
ShouldError: false,
|
||||
},
|
||||
"non-existent configuration": {
|
||||
SetupAPI: func(api *plugintest.API) *plugintest.API {
|
||||
api.On("GetConfig").Return(&model.Config{})
|
||||
|
||||
@@ -69,9 +111,7 @@ func TestCheckRequiredServerConfiguration(t *testing.T) {
|
||||
|
||||
ok, err := p.CheckRequiredServerConfiguration(test.Input)
|
||||
|
||||
if !ok {
|
||||
assert.False(t, ok)
|
||||
}
|
||||
assert.Equal(t, test.ShouldReturn, ok)
|
||||
if test.ShouldError {
|
||||
assert.NotNil(t, err)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user