mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Added tests for ChargerSCfg
This commit is contained in:
committed by
Dan Christian Bogos
parent
c7004550bd
commit
af623b49e9
60
config/chargerscfg_test.go
Normal file
60
config/chargerscfg_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package config
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestChargerSCfgloadFromJsonCfg(t *testing.T) {
|
||||
var chgscfg, expected ChargerSCfg
|
||||
if err := chgscfg.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(chgscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, chgscfg)
|
||||
}
|
||||
if err := chgscfg.loadFromJsonCfg(new(ChargerSJsonCfg)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(chgscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, chgscfg)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"chargers": { // Charger service
|
||||
"enabled": true, // starts charger service: <true|false>.
|
||||
"attributes_conns": [], // address where to reach the AttributeS <""|127.0.0.1:2013>
|
||||
//"string_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"prefix_indexed_fields": ["index1", "index2"], // query indexes based on these fields for faster processing
|
||||
},
|
||||
}`
|
||||
expected = ChargerSCfg{
|
||||
Enabled: true,
|
||||
AttributeSConns: []*HaPoolConfig{},
|
||||
PrefixIndexedFields: &[]string{"index1", "index2"},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromReader(strings.NewReader(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnCacheCfg, err := jsnCfg.ChargerServJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = chgscfg.loadFromJsonCfg(jsnCacheCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, chgscfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", expected, chgscfg)
|
||||
}
|
||||
}
|
||||
@@ -151,6 +151,7 @@ func NewDefaultCGRConfig() (*CGRConfig, error) {
|
||||
cfg.diameterAgentCfg = new(DiameterAgentCfg)
|
||||
cfg.radiusAgentCfg = new(RadiusAgentCfg)
|
||||
cfg.attributeSCfg = new(AttributeSCfg)
|
||||
cfg.chargerSCfg = new(ChargerSCfg)
|
||||
|
||||
//Depricated
|
||||
cfg.cdrStatsCfg = new(CdrStatsCfg)
|
||||
@@ -265,7 +266,6 @@ type CGRConfig struct {
|
||||
|
||||
httpAgentCfg []*HttpAgentCfg // HttpAgent configuration
|
||||
|
||||
chargerSCfg *ChargerSCfg
|
||||
resourceSCfg *ResourceSConfig // Configuration for resource limiter
|
||||
statsCfg *StatSCfg // Configuration for StatS
|
||||
thresholdSCfg *ThresholdSCfg // configuration for ThresholdS
|
||||
@@ -303,6 +303,7 @@ type CGRConfig struct {
|
||||
diameterAgentCfg *DiameterAgentCfg // DiameterAgent config
|
||||
radiusAgentCfg *RadiusAgentCfg // RadiusAgent config
|
||||
attributeSCfg *AttributeSCfg // AttributeS config
|
||||
chargerSCfg *ChargerSCfg // ChargerS config
|
||||
analyzerSCfg *AnalyzerSCfg
|
||||
|
||||
// Deprecated
|
||||
@@ -878,6 +879,9 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if self.chargerSCfg.loadFromJsonCfg(jsnChargerSCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsnRLSCfg, err := jsnCfg.ResourceSJsonCfg()
|
||||
if err != nil {
|
||||
@@ -1062,15 +1066,6 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
}
|
||||
///depricated^^^
|
||||
|
||||
if jsnChargerSCfg != nil {
|
||||
if self.chargerSCfg == nil {
|
||||
self.chargerSCfg = new(ChargerSCfg)
|
||||
}
|
||||
if self.chargerSCfg.loadFromJsonCfg(jsnChargerSCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if jsnRLSCfg != nil {
|
||||
if self.resourceSCfg == nil {
|
||||
self.resourceSCfg = new(ResourceSConfig)
|
||||
|
||||
Reference in New Issue
Block a user