plugin/helpers: fix an unchecked issue when comparing two conf… (#13748)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
40b7790318
Коммит
99a82ef07e
@@ -18,7 +18,7 @@ func (p *HelpersImpl) CheckRequiredServerConfiguration(req *model.Config) (bool,
|
|||||||
|
|
||||||
cfg := p.API.GetConfig()
|
cfg := p.API.GetConfig()
|
||||||
|
|
||||||
mc, err := utils.Merge(req, cfg, nil)
|
mc, err := utils.Merge(cfg, req, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrap(err, "could not merge configurations")
|
return false, errors.Wrap(err, "could not merge configurations")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,12 +27,15 @@ func TestCheckRequiredServerConfiguration(t *testing.T) {
|
|||||||
ShouldReturn: true,
|
ShouldReturn: true,
|
||||||
ShouldError: false,
|
ShouldError: false,
|
||||||
},
|
},
|
||||||
"same configurations": {
|
"contains required configuration": {
|
||||||
SetupAPI: func(api *plugintest.API) *plugintest.API {
|
SetupAPI: func(api *plugintest.API) *plugintest.API {
|
||||||
api.On("GetConfig").Return(&model.Config{
|
api.On("GetConfig").Return(&model.Config{
|
||||||
ServiceSettings: model.ServiceSettings{
|
ServiceSettings: model.ServiceSettings{
|
||||||
EnableCommands: model.NewBool(true),
|
EnableCommands: model.NewBool(true),
|
||||||
},
|
},
|
||||||
|
TeamSettings: model.TeamSettings{
|
||||||
|
EnableUserCreation: model.NewBool(true),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return api
|
return api
|
||||||
@@ -45,7 +48,46 @@ func TestCheckRequiredServerConfiguration(t *testing.T) {
|
|||||||
ShouldReturn: true,
|
ShouldReturn: true,
|
||||||
ShouldError: false,
|
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": {
|
"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 {
|
SetupAPI: func(api *plugintest.API) *plugintest.API {
|
||||||
api.On("GetConfig").Return(&model.Config{})
|
api.On("GetConfig").Return(&model.Config{})
|
||||||
|
|
||||||
@@ -69,9 +111,7 @@ func TestCheckRequiredServerConfiguration(t *testing.T) {
|
|||||||
|
|
||||||
ok, err := p.CheckRequiredServerConfiguration(test.Input)
|
ok, err := p.CheckRequiredServerConfiguration(test.Input)
|
||||||
|
|
||||||
if !ok {
|
assert.Equal(t, test.ShouldReturn, ok)
|
||||||
assert.False(t, ok)
|
|
||||||
}
|
|
||||||
if test.ShouldError {
|
if test.ShouldError {
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user