From 62ee6bde6ae0425ae355941ef52e83f5be7a329a Mon Sep 17 00:00:00 2001 From: DanB Date: Fri, 1 Jun 2018 09:34:40 +0200 Subject: [PATCH] Config tests for ConectoAgent --- config/config.go | 28 +++++++++++++++++++++++++++- config/config_json.go | 13 +++++++++++++ config/config_json_test.go | 19 +++++++++++++++++++ config/config_test.go | 14 ++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 426f1ee19..c06552be3 100755 --- a/config/config.go +++ b/config/config.go @@ -143,6 +143,7 @@ func NewDefaultCGRConfig() (*CGRConfig, error) { cfg.asteriskAgentCfg = new(AsteriskAgentCfg) cfg.diameterAgentCfg = new(DiameterAgentCfg) cfg.radiusAgentCfg = new(RadiusAgentCfg) + cfg.conectoAgentCfg = new(ConectoAgentCfg) cfg.filterSCfg = new(FilterSCfg) cfg.dispatcherSCfg = new(DispatcherSCfg) cfg.ConfigReloads = make(map[string]chan struct{}) @@ -346,6 +347,7 @@ type CGRConfig struct { asteriskAgentCfg *AsteriskAgentCfg // SMAsterisk Configuration diameterAgentCfg *DiameterAgentCfg // DiameterAgent configuration radiusAgentCfg *RadiusAgentCfg // RadiusAgent configuration + conectoAgentCfg *ConectoAgentCfg // ConectoAgent configuration filterSCfg *FilterSCfg // FilterS configuration PubSubServerEnabled bool // Starts PubSub as server: . AliasesServerEnabled bool // Starts PubSub as server: . @@ -635,7 +637,16 @@ func (self *CGRConfig) checkConfigSanity() error { } } } - // ResourceS checks + // conectoAgent checks + if self.conectoAgentCfg.Enabled { + for _, sSConn := range self.conectoAgentCfg.SessionSConns { + if sSConn.Address == utils.MetaInternal && + !self.sessionSCfg.Enabled { + return errors.New("SessionS not enabled but referenced by ConectoAgent component") + } + } + } + // ResourceLimiter checks if self.resourceSCfg != nil && self.resourceSCfg.Enabled { for _, connCfg := range self.resourceSCfg.ThresholdSConns { if connCfg.Address == utils.MetaInternal && !self.thresholdSCfg.Enabled { @@ -782,6 +793,11 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { return err } + jsnCncAgntCfg, err := jsnCfg.ConectoAgentJsonCfg() + if err != nil { + return err + } + jsnPubSubServCfg, err := jsnCfg.PubSubServJsonCfg() if err != nil { return err @@ -1329,6 +1345,12 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { } } + if jsnCncAgntCfg != nil { + if err := self.conectoAgentCfg.loadFromJsonCfg(jsnCncAgntCfg); err != nil { + return err + } + } + if jsnPubSubServCfg != nil { if jsnPubSubServCfg.Enabled != nil { self.PubSubServerEnabled = *jsnPubSubServCfg.Enabled @@ -1505,6 +1527,10 @@ func (self *CGRConfig) AsteriskAgentCfg() *AsteriskAgentCfg { return self.asteriskAgentCfg } +func (self *CGRConfig) ConectoAgentCfg() *ConectoAgentCfg { + return self.conectoAgentCfg +} + func (cfg *CGRConfig) FilterSCfg() *FilterSCfg { return cfg.filterSCfg } diff --git a/config/config_json.go b/config/config_json.go index a62061f3a..b814ae09b 100644 --- a/config/config_json.go +++ b/config/config_json.go @@ -50,6 +50,7 @@ const ( OSIPS_JSN = "opensips" DA_JSN = "diameter_agent" RA_JSN = "radius_agent" + CncAgentJson = "conecto_agent" HISTSERV_JSN = "historys" PUBSUBSERV_JSN = "pubsubs" ALIASESSERV_JSN = "aliases" @@ -307,6 +308,18 @@ func (self CgrJsonCfg) RadiusAgentJsonCfg() (*RadiusAgentJsonCfg, error) { return cfg, nil } +func (self CgrJsonCfg) ConectoAgentJsonCfg() (*ConectoAgentJsonCfg, error) { + rawCfg, hasKey := self[CncAgentJson] + if !hasKey { + return nil, nil + } + cfg := new(ConectoAgentJsonCfg) + if err := json.Unmarshal(*rawCfg, cfg); err != nil { + return nil, err + } + return cfg, nil +} + func (self CgrJsonCfg) PubSubServJsonCfg() (*PubSubServJsonCfg, error) { rawCfg, hasKey := self[PUBSUBSERV_JSN] if !hasKey { diff --git a/config/config_json_test.go b/config/config_json_test.go index 768028542..b645d32d5 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -648,6 +648,25 @@ func TestRadiusAgentJsonCfg(t *testing.T) { } } +func TestConectoAgentJsonCfg(t *testing.T) { + eCfg := &ConectoAgentJsonCfg{ + Enabled: utils.BoolPointer(false), + Http_url: utils.StringPointer("/conecto"), + Sessions_conns: &[]*HaPoolJsonCfg{ + &HaPoolJsonCfg{ + Address: utils.StringPointer(utils.MetaInternal), + }}, + Timezone: utils.StringPointer(""), + Request_processors: &[]*CncProcessorJsnCfg{}, + } + if cfg, err := dfCgrJsonCfg.ConectoAgentJsonCfg(); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(eCfg, cfg) { + rcv := *cfg.Request_processors + t.Errorf("Received: %+v", rcv) + } +} + func TestDfPubSubServJsonCfg(t *testing.T) { eCfg := &PubSubServJsonCfg{ Enabled: utils.BoolPointer(false), diff --git a/config/config_test.go b/config/config_test.go index d1bb1fc97..ad851d795 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -996,6 +996,20 @@ func TestRadiusAgentCfg(t *testing.T) { } } +func TestConectoAgentCfg(t *testing.T) { + expct := &ConectoAgentCfg{ + Enabled: false, + HttpUrl: "/conecto", + Timezone: "", + SessionSConns: []*HaPoolConfig{ + &HaPoolConfig{Address: utils.MetaInternal}}, + RequestProcessors: nil, + } + if !reflect.DeepEqual(expct, cgrCfg.conectoAgentCfg) { + t.Errorf("expecting: %s, received: %s", utils.ToJSON(expct), utils.ToJSON(cgrCfg.conectoAgentCfg)) + } +} + func TestDbDefaults(t *testing.T) { dbdf := NewDbDefaults() flagInput := utils.MetaDynamic