Updated AsMapInterface method for ERsCfg/Added test

This commit is contained in:
adragusin
2020-04-28 18:01:14 +03:00
committed by Dan Christian Bogos
parent c93365599c
commit c498fa6bf1
2 changed files with 43 additions and 19 deletions

View File

@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package config
import (
"strings"
"time"
"github.com/cgrates/cgrates/utils"
@@ -252,13 +253,22 @@ func (er *EventReaderCfg) AsMapInterface(separator string) map[string]interface{
for i, item := range er.XmlRootPath {
xmlRootPath[i] = item
}
tenant := make([]string, len(er.Tenant))
for i, item := range er.Tenant {
tenant[i] = item.Rules
var tenant string
if er.Tenant != nil {
values := make([]string, len(er.Tenant))
for i, item := range er.Tenant {
values[i] = item.Rules
}
tenant = strings.Join(values, separator)
}
flags := make(map[string][]string, len(er.Flags))
flags := make(map[string][]interface{}, len(er.Flags))
for key, val := range er.Flags {
flags[key] = val
buf := make([]interface{}, len(val))
for i, item := range val {
buf[i] = item
}
flags[key] = buf
}
fields := make([]map[string]interface{}, len(er.Fields))
for i, item := range er.Fields {
@@ -268,13 +278,26 @@ func (er *EventReaderCfg) AsMapInterface(separator string) map[string]interface{
for i, item := range er.CacheDumpFields {
cacheDumpFields[i] = item.AsMapInterface(separator)
}
var runDelay string
if er.RunDelay > 0 {
runDelay = er.RunDelay.String()
} else if er.RunDelay == 0 {
runDelay = "0"
} else {
runDelay = "-1"
}
var partialRecordCache string = "0"
if er.PartialRecordCache != 0 {
partialRecordCache = er.PartialRecordCache.String()
}
return map[string]interface{}{
utils.IDCfg: er.ID,
utils.TypeCfg: er.Type,
utils.RowLengthCfg: er.RowLength,
utils.FieldSepCfg: er.FieldSep,
utils.RunDelayCfg: er.RunDelay,
utils.RunDelayCfg: runDelay,
utils.ConcurrentReqsCfg: er.ConcurrentReqs,
utils.SourcePathCfg: er.SourcePath,
utils.ProcessedPathCfg: er.ProcessedPath,
@@ -284,7 +307,7 @@ func (er *EventReaderCfg) AsMapInterface(separator string) map[string]interface{
utils.FiltersCfg: er.Filters,
utils.FlagsCfg: flags,
utils.FailedCallsPrefixCfg: er.FailedCallsPrefix,
utils.PartialRecordCacheCfg: er.PartialRecordCache,
utils.PartialRecordCacheCfg: partialRecordCache,
utils.PartialCacheExpiryActionCfg: er.PartialCacheExpiryAction,
utils.FieldsCfg: fields,
utils.CacheDumpFieldsCfg: cacheDumpFields,

View File

@@ -332,7 +332,7 @@ func TestEventReaderSameID(t *testing.T) {
}
func testERsCfgAsMapInterface(t *testing.T) {
func TestERsCfgAsMapInterface(t *testing.T) {
cfgJSONStr := `{
"ers": {
"enabled": true,
@@ -349,24 +349,25 @@ func testERsCfgAsMapInterface(t *testing.T) {
],
}
}`
var filters []string
eMap := map[string]interface{}{
"enabled": true,
"sessions_conns": []string{"conn1", "conn3"},
"readers": []map[string]interface{}{
{
"filters": []string{},
"flags": map[string]interface{}{},
"flags": map[string][]interface{}{},
"id": "*default",
"partial_record_cache": 0,
"partial_record_cache": "0",
"processed_path": "/var/spool/cgrates/cdrc/out",
"row_length": 0,
"run_delay": 0,
"run_delay": "0",
"soome": "",
"source_path": "/var/spool/cgrates/cdrc/in",
"tenant": []string{},
"tenant": "",
"timezone": "",
"xml_root_path": []string{""},
"cache_dump_fields": []string{},
"cache_dump_fields": []map[string]interface{}{},
"concurrent_requests": 1024,
"db_type": "*none",
"failed_calls_prefix": "",
@@ -386,7 +387,7 @@ func testERsCfgAsMapInterface(t *testing.T) {
},
},
{
"cache_dump_fields": []string{},
"cache_dump_fields": []map[string]interface{}{},
"concurrent_requests": 1024,
"db_type": "*file_csv",
"failed_calls_prefix": "",
@@ -404,16 +405,16 @@ func testERsCfgAsMapInterface(t *testing.T) {
{"mandatory": true, "path": "*cgreq.AnswerTime", "tag": "AnswerTime", "type": "*variable", "value": "~*req.12"},
{"mandatory": true, "path": "*cgreq.Usage", "tag": "Usage", "type": "*variable", "value": "~*req.13"},
},
"filters": nil,
"flags": map[string]interface{}{},
"filters": filters,
"flags": map[string][]interface{}{},
"id": "file_reader1",
"partial_record_cache": 0,
"partial_record_cache": "0",
"processed_path": "/tmp/ers/out",
"row_length": 0,
"run_delay": -1,
"run_delay": "-1",
"soome": "",
"source_path": "/tmp/ers/in",
"tenant": []string{},
"tenant": "",
"timezone": "",
"xml_root_path": []string{""},
},