()
| 495 | } |
| 496 | |
| 497 | func (s *PluginSuite) Test_UpdateConfig_invalidConfig_expect400() { |
| 498 | conf, err := s.db.GetPluginConfByUserAndPath(1, mock.ModulePath) |
| 499 | assert.NoError(s.T(), err) |
| 500 | inst, err := s.manager.Instance(conf.ID) |
| 501 | assert.Nil(s.T(), err) |
| 502 | mockInst := inst.(*mock.PluginInstance) |
| 503 | origConfig := mockInst.Config |
| 504 | |
| 505 | newConfig := &mock.PluginConfig{ |
| 506 | TestKey: "test__new__config__invalid", |
| 507 | IsNotValid: true, |
| 508 | } |
| 509 | newConfigYAML, err := yaml.Marshal(newConfig) |
| 510 | assert.Nil(s.T(), err) |
| 511 | |
| 512 | { |
| 513 | test.WithUser(s.ctx, 1) |
| 514 | |
| 515 | s.ctx.Request = httptest.NewRequest("POST", fmt.Sprintf("/plugin/%d/config", conf.ID), bytes.NewReader(newConfigYAML)) |
| 516 | s.ctx.Header("Content-Type", "application/x-yaml") |
| 517 | s.ctx.Params = gin.Params{{Key: "id", Value: fmt.Sprint(conf.ID)}} |
| 518 | s.a.UpdateConfig(s.ctx) |
| 519 | |
| 520 | assert.Equal(s.T(), 400, s.recorder.Code) |
| 521 | assert.Equal(s.T(), origConfig, mockInst.Config, "config should not be received by plugin") |
| 522 | |
| 523 | var pluginFromDBBytes []byte |
| 524 | if pluginConf, err := s.db.GetPluginConfByID(conf.ID); assert.NoError(s.T(), err) { |
| 525 | pluginFromDBBytes = pluginConf.Config |
| 526 | } |
| 527 | pluginFromDB := new(mock.PluginConfig) |
| 528 | err := yaml.Unmarshal(pluginFromDBBytes, pluginFromDB) |
| 529 | assert.Nil(s.T(), err) |
| 530 | assert.Equal(s.T(), origConfig, pluginFromDB, "config should not be updated in database") |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | func (s *PluginSuite) Test_UpdateConfig_malformedYAML_expect400() { |
| 535 | conf, err := s.db.GetPluginConfByUserAndPath(1, mock.ModulePath) |
nothing calls this directly
no test coverage detected