MCPcopy
hub / github.com/gotify/server / Test_UpdateConfig_invalidConfig_expect400

Method Test_UpdateConfig_invalidConfig_expect400

api/plugin_test.go:497–532  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

495}
496
497func (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
534func (s *PluginSuite) Test_UpdateConfig_malformedYAML_expect400() {
535 conf, err := s.db.GetPluginConfByUserAndPath(1, mock.ModulePath)

Callers

nothing calls this directly

Calls 5

WithUserFunction · 0.92
InstanceMethod · 0.80
UpdateConfigMethod · 0.80
GetPluginConfByIDMethod · 0.65

Tested by

no test coverage detected