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

Method Test_UpdateConfig

api/plugin_test.go:462–495  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

460}
461
462func (s *PluginSuite) Test_UpdateConfig() {
463 conf, err := s.db.GetPluginConfByUserAndPath(1, mock.ModulePath)
464 assert.NoError(s.T(), err)
465 inst, err := s.manager.Instance(conf.ID)
466 assert.Nil(s.T(), err)
467 mockInst := inst.(*mock.PluginInstance)
468
469 newConfig := &mock.PluginConfig{
470 TestKey: "test__new__config",
471 }
472 newConfigYAML, err := yaml.Marshal(newConfig)
473 assert.Nil(s.T(), err)
474
475 {
476 test.WithUser(s.ctx, 1)
477
478 s.ctx.Request = httptest.NewRequest("POST", fmt.Sprintf("/plugin/%d/config", conf.ID), bytes.NewReader(newConfigYAML))
479 s.ctx.Header("Content-Type", "application/x-yaml")
480 s.ctx.Params = gin.Params{{Key: "id", Value: fmt.Sprint(conf.ID)}}
481 s.a.UpdateConfig(s.ctx)
482
483 assert.Equal(s.T(), 200, s.recorder.Code)
484 assert.Equal(s.T(), newConfig, mockInst.Config, "config should be received by plugin")
485
486 var pluginFromDBBytes []byte
487 if pluginConf, err := s.db.GetPluginConfByID(conf.ID); assert.NoError(s.T(), err) {
488 pluginFromDBBytes = pluginConf.Config
489 }
490 pluginFromDB := new(mock.PluginConfig)
491 err := yaml.Unmarshal(pluginFromDBBytes, pluginFromDB)
492 assert.Nil(s.T(), err)
493 assert.Equal(s.T(), newConfig, pluginFromDB, "config should be updated in database")
494 }
495}
496
497func (s *PluginSuite) Test_UpdateConfig_invalidConfig_expect400() {
498 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