From 425c2f2e9b75d47a401b22dcce572d71ba1c3d9e Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Thu, 12 Oct 2023 12:14:08 -0400 Subject: [PATCH] Remove config default value for xml_root_path The field will remain commented in config_defaults for reference. --- config/config_defaults.go | 2 +- config/config_json_test.go | 1 - config/erscfg.go | 50 ++++++++++++++++++-------------------- config/erscfg_test.go | 8 +++--- 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/config/config_defaults.go b/config/config_defaults.go index 51c0ac1ee..8aec081fb 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -311,7 +311,7 @@ const CGRATES_CFG_JSON = ` "concurrent_requests": 1024, // maximum simultaneous requests/files to process, 0 for unlimited "source_path": "/var/spool/cgrates/ers/in", // read data from this path "processed_path": "/var/spool/cgrates/ers/out", // move processed data here - "xml_root_path": "", // path towards one event in case of XML CDRs + // "xml_root_path": "", // path towards one event in case of XML CDRs "tenant": "", // tenant used by import "timezone": "", // timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB> "filters": [], // limit parsing based on the filters diff --git a/config/config_json_test.go b/config/config_json_test.go index 18b139871..264f2ecdb 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -1719,7 +1719,6 @@ func TestDfEventReaderCfg(t *testing.T) { Concurrent_requests: utils.IntPointer(1024), Source_path: utils.StringPointer("/var/spool/cgrates/ers/in"), Processed_path: utils.StringPointer("/var/spool/cgrates/ers/out"), - Xml_root_path: utils.StringPointer(utils.EmptyString), Tenant: utils.StringPointer(utils.EmptyString), Timezone: utils.StringPointer(utils.EmptyString), Filters: &[]string{}, diff --git a/config/erscfg.go b/config/erscfg.go index 4bc773eab..6cfbb2b2b 100644 --- a/config/erscfg.go +++ b/config/erscfg.go @@ -249,9 +249,23 @@ func (er *EventReaderCfg) Clone() (cln *EventReaderCfg) { } func (er *EventReaderCfg) AsMapInterface(separator string) map[string]any { - xmlRootPath := make([]string, len(er.XmlRootPath)) - for i, item := range er.XmlRootPath { - xmlRootPath[i] = item + rdrMap := map[string]any{ + utils.IDCfg: er.ID, + utils.TypeCfg: er.Type, + utils.RowLengthCfg: er.RowLength, + utils.FieldSepCfg: er.FieldSep, + utils.ConcurrentReqsCfg: er.ConcurrentReqs, + utils.SourcePathCfg: er.SourcePath, + utils.ProcessedPathCfg: er.ProcessedPath, + utils.TimezoneCfg: er.Timezone, + utils.FiltersCfg: er.Filters, + utils.FailedCallsPrefixCfg: er.FailedCallsPrefix, + utils.PartialCacheExpiryActionCfg: er.PartialCacheExpiryAction, + } + if len(er.XmlRootPath) != 0 { + xmlRootPath := make([]string, len(er.XmlRootPath)) + copy(xmlRootPath, er.XmlRootPath) + rdrMap[utils.XmlRootPathCfg] = xmlRootPath } var tenant string if er.Tenant != nil { @@ -261,7 +275,7 @@ func (er *EventReaderCfg) AsMapInterface(separator string) map[string]any { } tenant = strings.Join(values, separator) } - + rdrMap[utils.TenantCfg] = tenant flags := make(map[string][]any, len(er.Flags)) for key, val := range er.Flags { buf := make([]any, len(val)) @@ -270,14 +284,17 @@ func (er *EventReaderCfg) AsMapInterface(separator string) map[string]any { } flags[key] = buf } + rdrMap[utils.FlagsCfg] = flags fields := make([]map[string]any, len(er.Fields)) for i, item := range er.Fields { fields[i] = item.AsMapInterface(separator) } + rdrMap[utils.FieldsCfg] = fields cacheDumpFields := make([]map[string]any, len(er.CacheDumpFields)) for i, item := range er.CacheDumpFields { cacheDumpFields[i] = item.AsMapInterface(separator) } + rdrMap[utils.CacheDumpFieldsCfg] = cacheDumpFields var runDelay string if er.RunDelay > 0 { runDelay = er.RunDelay.String() @@ -286,30 +303,11 @@ func (er *EventReaderCfg) AsMapInterface(separator string) map[string]any { } else { runDelay = "-1" } - + rdrMap[utils.RunDelayCfg] = runDelay var partialRecordCache string = "0" if er.PartialRecordCache != 0 { partialRecordCache = er.PartialRecordCache.String() } - - return map[string]any{ - utils.IDCfg: er.ID, - utils.TypeCfg: er.Type, - utils.RowLengthCfg: er.RowLength, - utils.FieldSepCfg: er.FieldSep, - utils.RunDelayCfg: runDelay, - utils.ConcurrentReqsCfg: er.ConcurrentReqs, - utils.SourcePathCfg: er.SourcePath, - utils.ProcessedPathCfg: er.ProcessedPath, - utils.XmlRootPathCfg: xmlRootPath, - utils.TenantCfg: tenant, - utils.TimezoneCfg: er.Timezone, - utils.FiltersCfg: er.Filters, - utils.FlagsCfg: flags, - utils.FailedCallsPrefixCfg: er.FailedCallsPrefix, - utils.PartialRecordCacheCfg: partialRecordCache, - utils.PartialCacheExpiryActionCfg: er.PartialCacheExpiryAction, - utils.FieldsCfg: fields, - utils.CacheDumpFieldsCfg: cacheDumpFields, - } + rdrMap[utils.PartialRecordCacheCfg] = partialRecordCache + return rdrMap } diff --git a/config/erscfg_test.go b/config/erscfg_test.go index 4b1c5d984..9169d6113 100644 --- a/config/erscfg_test.go +++ b/config/erscfg_test.go @@ -270,7 +270,6 @@ func TestERsCfgAsMapInterface(t *testing.T) { "source_path": "/var/spool/cgrates/ers/in", "tenant": "", "timezone": "", - "xml_root_path": []string{}, "cache_dump_fields": []map[string]any{}, "concurrent_requests": 1024, "type": "*none", @@ -320,7 +319,6 @@ func TestERsCfgAsMapInterface(t *testing.T) { "source_path": "/tmp/ers/in", "tenant": "", "timezone": "", - "xml_root_path": []string{}, }, }, } @@ -534,7 +532,7 @@ func TestEventReeadersCFGAsMapInterface(t *testing.T) { ConcurrentReqs: 1, SourcePath: "test", ProcessedPath: "test", - XmlRootPath: []string{}, + XmlRootPath: utils.HierarchyPath{"item1", "item2"}, Timezone: "test", Filters: []string{}, FailedCallsPrefix: "!", @@ -550,7 +548,6 @@ func TestEventReeadersCFGAsMapInterface(t *testing.T) { utils.ConcurrentReqsCfg: er.ConcurrentReqs, utils.SourcePathCfg: er.SourcePath, utils.ProcessedPathCfg: er.ProcessedPath, - utils.XmlRootPathCfg: []string{}, utils.TenantCfg: "test", utils.TimezoneCfg: er.Timezone, utils.FiltersCfg: er.Filters, @@ -560,6 +557,7 @@ func TestEventReeadersCFGAsMapInterface(t *testing.T) { utils.PartialCacheExpiryActionCfg: er.PartialCacheExpiryAction, utils.FieldsCfg: []map[string]any{}, utils.CacheDumpFieldsCfg: []map[string]any{fct.AsMapInterface("")}, + utils.XmlRootPathCfg: []string{"item1", "item2"}, } tests := []struct { @@ -579,7 +577,7 @@ func TestEventReeadersCFGAsMapInterface(t *testing.T) { rcv := er.AsMapInterface(tt.arg) if !reflect.DeepEqual(rcv, tt.exp) { - t.Errorf("recived %v, expected %v", rcv, tt.exp) + t.Errorf("expected %v,\nreceived %v", tt.exp, rcv) } }) }