mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated AsMapInterface method for SessionSCfg/Added test
This commit is contained in:
committed by
Dan Christian Bogos
parent
db0f20be57
commit
6416fa3b35
@@ -298,33 +298,152 @@ func (scfg *SessionSCfg) loadFromJsonCfg(jsnCfg *SessionSJsonCfg) (err error) {
|
||||
}
|
||||
|
||||
func (scfg *SessionSCfg) AsMapInterface() map[string]interface{} {
|
||||
var debitInterval string = "0"
|
||||
if scfg.DebitInterval != 0 {
|
||||
debitInterval = scfg.DebitInterval.String()
|
||||
}
|
||||
var minCallDuration string = "0"
|
||||
if scfg.MinCallDuration != 0 {
|
||||
minCallDuration = scfg.MinCallDuration.String()
|
||||
}
|
||||
var maxCallDuration string = "0"
|
||||
if scfg.MaxCallDuration != 0 {
|
||||
maxCallDuration = scfg.MaxCallDuration.String()
|
||||
}
|
||||
var sessionTTL string = "0"
|
||||
if scfg.SessionTTL != 0 {
|
||||
sessionTTL = scfg.SessionTTL.String()
|
||||
}
|
||||
var sessionTTLMaxDelay string = "0"
|
||||
if scfg.SessionTTLMaxDelay != nil {
|
||||
sessionTTLMaxDelay = scfg.SessionTTLMaxDelay.String()
|
||||
}
|
||||
var sessionTTLLastUsed string = "0"
|
||||
if scfg.SessionTTLLastUsed != nil {
|
||||
sessionTTLLastUsed = scfg.SessionTTLLastUsed.String()
|
||||
}
|
||||
var sessionTTLUsage string = "0"
|
||||
if scfg.SessionTTLUsage != nil {
|
||||
sessionTTLUsage = scfg.SessionTTLUsage.String()
|
||||
}
|
||||
var channelSyncInterval string = "0"
|
||||
if scfg.ChannelSyncInterval != 0 {
|
||||
channelSyncInterval = scfg.ChannelSyncInterval.String()
|
||||
}
|
||||
var minDurLowBalance string = "0"
|
||||
if scfg.MinDurLowBalance != 0 {
|
||||
minDurLowBalance = scfg.MinDurLowBalance.String()
|
||||
}
|
||||
|
||||
chargerSConns := make([]string, len(scfg.ChargerSConns))
|
||||
for i, item := range scfg.ChargerSConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)
|
||||
if item == buf {
|
||||
chargerSConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaChargers, utils.EmptyString)
|
||||
} else {
|
||||
chargerSConns[i] = item
|
||||
}
|
||||
}
|
||||
RALsConns := make([]string, len(scfg.RALsConns))
|
||||
for i, item := range scfg.RALsConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResponder)
|
||||
|
||||
if item == buf {
|
||||
RALsConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaResponder, utils.EmptyString)
|
||||
} else {
|
||||
RALsConns[i] = item
|
||||
}
|
||||
}
|
||||
resSConns := make([]string, len(scfg.ResSConns))
|
||||
for i, item := range scfg.ResSConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)
|
||||
if item == buf {
|
||||
resSConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaResources, utils.EmptyString)
|
||||
} else {
|
||||
resSConns[i] = item
|
||||
}
|
||||
}
|
||||
threshSConns := make([]string, len(scfg.ThreshSConns))
|
||||
for i, item := range scfg.ThreshSConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)
|
||||
if item == buf {
|
||||
threshSConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaThresholds, utils.EmptyString)
|
||||
} else {
|
||||
threshSConns[i] = item
|
||||
}
|
||||
}
|
||||
statSConns := make([]string, len(scfg.StatSConns))
|
||||
for i, item := range scfg.StatSConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStatS)
|
||||
if item == buf {
|
||||
statSConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaStatS, utils.EmptyString)
|
||||
} else {
|
||||
statSConns[i] = item
|
||||
}
|
||||
}
|
||||
supplSConns := make([]string, len(scfg.SupplSConns))
|
||||
for i, item := range scfg.SupplSConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSuppliers)
|
||||
if item == buf {
|
||||
supplSConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaSuppliers, utils.EmptyString)
|
||||
} else {
|
||||
supplSConns[i] = item
|
||||
}
|
||||
}
|
||||
attrSConns := make([]string, len(scfg.AttrSConns))
|
||||
for i, item := range scfg.AttrSConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)
|
||||
if item == buf {
|
||||
attrSConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaAttributes, utils.EmptyString)
|
||||
} else {
|
||||
attrSConns[i] = item
|
||||
}
|
||||
}
|
||||
CDRsConns := make([]string, len(scfg.CDRsConns))
|
||||
for i, item := range scfg.CDRsConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)
|
||||
if item == buf {
|
||||
CDRsConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaCDRs, utils.EmptyString)
|
||||
} else {
|
||||
CDRsConns[i] = item
|
||||
}
|
||||
}
|
||||
schedulerConns := make([]string, len(scfg.SchedulerConns))
|
||||
for i, item := range scfg.SchedulerConns {
|
||||
buf := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler)
|
||||
if item == buf {
|
||||
schedulerConns[i] = strings.ReplaceAll(item, utils.CONCATENATED_KEY_SEP+utils.MetaScheduler, utils.EmptyString)
|
||||
} else {
|
||||
schedulerConns[i] = item
|
||||
}
|
||||
}
|
||||
return map[string]interface{}{
|
||||
utils.EnabledCfg: scfg.Enabled,
|
||||
utils.ListenBijsonCfg: scfg.ListenBijson,
|
||||
utils.ChargerSConnsCfg: scfg.ChargerSConns,
|
||||
utils.RALsConnsCfg: scfg.RALsConns,
|
||||
utils.ResSConnsCfg: scfg.ResSConns,
|
||||
utils.ThreshSConnsCfg: scfg.ThreshSConns,
|
||||
utils.StatSConnsCfg: scfg.StatSConns,
|
||||
utils.SupplSConnsCfg: scfg.SupplSConns,
|
||||
utils.AttrSConnsCfg: scfg.AttrSConns,
|
||||
utils.CDRsConnsCfg: scfg.CDRsConns,
|
||||
utils.ChargerSConnsCfg: chargerSConns,
|
||||
utils.RALsConnsCfg: RALsConns,
|
||||
utils.ResSConnsCfg: resSConns,
|
||||
utils.ThreshSConnsCfg: threshSConns,
|
||||
utils.StatSConnsCfg: statSConns,
|
||||
utils.SupplSConnsCfg: supplSConns,
|
||||
utils.AttrSConnsCfg: attrSConns,
|
||||
utils.CDRsConnsCfg: CDRsConns,
|
||||
utils.ReplicationConnsCfg: scfg.ReplicationConns,
|
||||
utils.DebitIntervalCfg: scfg.DebitInterval,
|
||||
utils.DebitIntervalCfg: debitInterval,
|
||||
utils.StoreSCostsCfg: scfg.StoreSCosts,
|
||||
utils.MinCallDurationCfg: scfg.MinCallDuration,
|
||||
utils.MaxCallDurationCfg: scfg.MaxCallDuration,
|
||||
utils.SessionTTLCfg: scfg.SessionTTL,
|
||||
utils.SessionTTLMaxDelayCfg: scfg.SessionTTLMaxDelay,
|
||||
utils.SessionTTLLastUsedCfg: scfg.SessionTTLLastUsed,
|
||||
utils.SessionTTLUsageCfg: scfg.SessionTTLUsage,
|
||||
utils.SessionIndexesCfg: scfg.SessionIndexes.GetSlice(),
|
||||
utils.MinCallDurationCfg: minCallDuration,
|
||||
utils.MaxCallDurationCfg: maxCallDuration,
|
||||
utils.SessionTTLCfg: sessionTTL,
|
||||
utils.SessionTTLMaxDelayCfg: sessionTTLMaxDelay,
|
||||
utils.SessionTTLLastUsedCfg: sessionTTLLastUsed,
|
||||
utils.SessionTTLUsageCfg: sessionTTLUsage,
|
||||
utils.SessionIndexesCfg: scfg.SessionIndexes.Slice(),
|
||||
utils.ClientProtocolCfg: scfg.ClientProtocol,
|
||||
utils.ChannelSyncIntervalCfg: scfg.ChannelSyncInterval,
|
||||
utils.ChannelSyncIntervalCfg: channelSyncInterval,
|
||||
utils.TerminateAttemptsCfg: scfg.TerminateAttempts,
|
||||
utils.AlterableFieldsCfg: scfg.AlterableFields.AsSlice(),
|
||||
utils.MinDurLowBalanceCfg: scfg.MinDurLowBalance,
|
||||
utils.MinDurLowBalanceCfg: minDurLowBalance,
|
||||
utils.SchedulerConnsCfg: schedulerConns,
|
||||
utils.STIRCfg: scfg.STIRCfg.AsMapInterface(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,164 @@ func TestSessionSCfgloadFromJsonCfg(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSessionSCfgAsMapInterface(t *testing.T) {
|
||||
var sescfg SessionSCfg
|
||||
cfgJSONStr := `{
|
||||
"sessions": {
|
||||
"enabled": false,
|
||||
"listen_bijson": "127.0.0.1:2014",
|
||||
"chargers_conns": [],
|
||||
"rals_conns": [],
|
||||
"cdrs_conns": [],
|
||||
"resources_conns": [],
|
||||
"thresholds_conns": [],
|
||||
"stats_conns": [],
|
||||
"suppliers_conns": [],
|
||||
"attributes_conns": [],
|
||||
"replication_conns": [],
|
||||
"debit_interval": "0s",
|
||||
"store_session_costs": false,
|
||||
"min_call_duration": "0s",
|
||||
"max_call_duration": "3h",
|
||||
"session_ttl": "0s",
|
||||
"session_indexes": [],
|
||||
"client_protocol": 1.0,
|
||||
"channel_sync_interval": "0",
|
||||
"terminate_attempts": 5,
|
||||
"alterable_fields": [],
|
||||
"stir": {
|
||||
"allowed_attest": ["*any"],
|
||||
"payload_maxduration": "-1",
|
||||
"default_attest": "A",
|
||||
"publickey_path": "",
|
||||
"privatekey_path": "",
|
||||
},
|
||||
"scheduler_conns": [],
|
||||
},
|
||||
}`
|
||||
eMap := map[string]interface{}{
|
||||
"enabled": false,
|
||||
"listen_bijson": "127.0.0.1:2014",
|
||||
"chargers_conns": []string{},
|
||||
"rals_conns": []string{},
|
||||
"cdrs_conns": []string{},
|
||||
"resources_conns": []string{},
|
||||
"thresholds_conns": []string{},
|
||||
"stats_conns": []string{},
|
||||
"suppliers_conns": []string{},
|
||||
"attributes_conns": []string{},
|
||||
"replication_conns": []string{},
|
||||
"debit_interval": "0",
|
||||
"store_session_costs": false,
|
||||
"min_call_duration": "0",
|
||||
"max_call_duration": "3h0m0s",
|
||||
"min_dur_low_balance": "0",
|
||||
"session_ttl": "0",
|
||||
"session_indexes": []string{},
|
||||
"client_protocol": 1.0,
|
||||
"channel_sync_interval": "0",
|
||||
"terminate_attempts": 5,
|
||||
"alterable_fields": []string{},
|
||||
"session_ttl_last_used": "0",
|
||||
"session_ttl_max_delay": "0",
|
||||
"session_ttl_usage": "0",
|
||||
"stir": map[string]interface{}{
|
||||
"allowed_attest": []string{"*any"},
|
||||
"payload_maxduration": "-1",
|
||||
"default_attest": "A",
|
||||
"publickey_path": "",
|
||||
"privatekey_path": "",
|
||||
},
|
||||
"scheduler_conns": []string{},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnSesCfg, err := jsnCfg.SessionSJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = sescfg.loadFromJsonCfg(jsnSesCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := sescfg.AsMapInterface(); !reflect.DeepEqual(eMap, rcv) {
|
||||
t.Errorf("\nExpected: %+v\nRecived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
cfgJSONStr = `{
|
||||
"sessions": {
|
||||
"enabled": false,
|
||||
"listen_bijson": "127.0.0.1:2014",
|
||||
"chargers_conns": ["*internal"],
|
||||
"rals_conns": ["*internal"],
|
||||
"cdrs_conns": ["*internal"],
|
||||
"resources_conns": ["*internal"],
|
||||
"thresholds_conns": ["*internal"],
|
||||
"stats_conns": ["*internal"],
|
||||
"suppliers_conns": ["*internal"],
|
||||
"attributes_conns": ["*internal"],
|
||||
"replication_conns": ["*localhost"],
|
||||
"debit_interval": "0s",
|
||||
"store_session_costs": false,
|
||||
"min_call_duration": "0s",
|
||||
"max_call_duration": "3h",
|
||||
"session_ttl": "0s",
|
||||
"session_indexes": [],
|
||||
"client_protocol": 1.0,
|
||||
"channel_sync_interval": "0",
|
||||
"terminate_attempts": 5,
|
||||
"alterable_fields": [],
|
||||
"stir": {
|
||||
"allowed_attest": ["*any"],
|
||||
"payload_maxduration": "-1",
|
||||
"default_attest": "A",
|
||||
"publickey_path": "",
|
||||
"privatekey_path": "",
|
||||
},
|
||||
"scheduler_conns": ["*internal"],
|
||||
},
|
||||
}`
|
||||
eMap = map[string]interface{}{
|
||||
"enabled": false,
|
||||
"listen_bijson": "127.0.0.1:2014",
|
||||
"chargers_conns": []string{"*internal"},
|
||||
"rals_conns": []string{"*internal"},
|
||||
"cdrs_conns": []string{"*internal"},
|
||||
"resources_conns": []string{"*internal"},
|
||||
"thresholds_conns": []string{"*internal"},
|
||||
"stats_conns": []string{"*internal"},
|
||||
"suppliers_conns": []string{"*internal"},
|
||||
"attributes_conns": []string{"*internal"},
|
||||
"replication_conns": []string{"*localhost"},
|
||||
"debit_interval": "0",
|
||||
"store_session_costs": false,
|
||||
"min_call_duration": "0",
|
||||
"max_call_duration": "3h0m0s",
|
||||
"min_dur_low_balance": "0",
|
||||
"session_ttl": "0",
|
||||
"session_indexes": []string{},
|
||||
"client_protocol": 1.0,
|
||||
"channel_sync_interval": "0",
|
||||
"terminate_attempts": 5,
|
||||
"alterable_fields": []string{},
|
||||
"session_ttl_last_used": "0",
|
||||
"session_ttl_max_delay": "0",
|
||||
"session_ttl_usage": "0",
|
||||
"stir": map[string]interface{}{
|
||||
"allowed_attest": []string{"*any"},
|
||||
"payload_maxduration": "-1",
|
||||
"default_attest": "A",
|
||||
"publickey_path": "",
|
||||
"privatekey_path": "",
|
||||
},
|
||||
"scheduler_conns": []string{"*internal"},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromBytes([]byte(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnSesCfg, err := jsnCfg.SessionSJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = sescfg.loadFromJsonCfg(jsnSesCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv := sescfg.AsMapInterface(); !reflect.DeepEqual(eMap, rcv) {
|
||||
t.Errorf("\nExpected: %+v\nRecived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFsAgentCfgloadFromJsonCfg2(t *testing.T) {
|
||||
var fsagcfg, expected FsAgentCfg
|
||||
if err := fsagcfg.loadFromJsonCfg(nil); err != nil {
|
||||
|
||||
@@ -1862,8 +1862,7 @@ const (
|
||||
|
||||
// Cache
|
||||
PartitionsCfg = "partitions"
|
||||
StaticTTL = "StaticTTL"
|
||||
Precache = "Precache"
|
||||
PrecacheCfg = "precache"
|
||||
|
||||
// CdreCfg
|
||||
ExportFormatCfg = "export_format"
|
||||
|
||||
Reference in New Issue
Block a user