()
| 532 | } |
| 533 | |
| 534 | func (s *PluginSuite) Test_UpdateConfig_malformedYAML_expect400() { |
| 535 | conf, err := s.db.GetPluginConfByUserAndPath(1, mock.ModulePath) |
| 536 | assert.NoError(s.T(), err) |
| 537 | inst, err := s.manager.Instance(conf.ID) |
| 538 | assert.Nil(s.T(), err) |
| 539 | mockInst := inst.(*mock.PluginInstance) |
| 540 | origConfig := mockInst.Config |
| 541 | |
| 542 | newConfigYAML := []byte(`--- "rg e""`) |
| 543 | |
| 544 | { |
| 545 | test.WithUser(s.ctx, 1) |
| 546 | |
| 547 | s.ctx.Request = httptest.NewRequest("POST", fmt.Sprintf("/plugin/%d/config", conf.ID), bytes.NewReader(newConfigYAML)) |
| 548 | s.ctx.Header("Content-Type", "application/x-yaml") |
| 549 | s.ctx.Params = gin.Params{{Key: "id", Value: fmt.Sprint(conf.ID)}} |
| 550 | s.a.UpdateConfig(s.ctx) |
| 551 | |
| 552 | assert.Equal(s.T(), 400, s.recorder.Code) |
| 553 | assert.Equal(s.T(), origConfig, mockInst.Config, "config should not be received by plugin") |
| 554 | |
| 555 | var pluginFromDBBytes []byte |
| 556 | if pluginConf, err := s.db.GetPluginConfByID(conf.ID); assert.NoError(s.T(), err) { |
| 557 | pluginFromDBBytes = pluginConf.Config |
| 558 | } |
| 559 | pluginFromDB := new(mock.PluginConfig) |
| 560 | err := yaml.Unmarshal(pluginFromDBBytes, pluginFromDB) |
| 561 | assert.Nil(s.T(), err) |
| 562 | assert.Equal(s.T(), origConfig, pluginFromDB, "config should not be updated in database") |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | func (s *PluginSuite) Test_UpdateConfig_ioError_expect500() { |
| 567 | conf, err := s.db.GetPluginConfByUserAndPath(1, mock.ModulePath) |
nothing calls this directly
no test coverage detected