mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
Config tests for ConectoAgent
This commit is contained in:
@@ -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: <true|false>.
|
||||
AliasesServerEnabled bool // Starts PubSub as server: <true|false>.
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user