From 5ba3c06dec7f93e8bfc3bddb4190ac12a710de07 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 29 Jun 2021 10:28:13 +0300 Subject: [PATCH] Fix the process of merging loaders with same id (final) --- config/loaderscfg.go | 3 + config/loaderscfg_test.go | 1209 ++++++++++++++++++++++++++++++++++++- 2 files changed, 1197 insertions(+), 15 deletions(-) diff --git a/config/loaderscfg.go b/config/loaderscfg.go index dcc09538a..78843ce67 100644 --- a/config/loaderscfg.go +++ b/config/loaderscfg.go @@ -152,6 +152,9 @@ func (l *LoaderSCfg) loadFromJSONCfg(jsnCfg *LoaderJsonCfg, msgTemplates map[str } if jsnCfg.Data != nil { for _, jsnLoCfg := range *jsnCfg.Data { + if jsnLoCfg == nil { + continue + } var ldrDataType *LoaderDataType if jsnLoCfg.Type != nil { for _, ldrDT := range l.Data { diff --git a/config/loaderscfg_test.go b/config/loaderscfg_test.go index 053b0d382..ff7837aa4 100644 --- a/config/loaderscfg_test.go +++ b/config/loaderscfg_test.go @@ -58,6 +58,7 @@ func TestLoaderSCfgloadFromJsonCfgCase1(t *testing.T) { if err != nil { t.Error(err) } + var flags utils.FlagsWithParams expected := LoaderSCfgs{ { Enabled: true, @@ -69,6 +70,58 @@ func TestLoaderSCfgloadFromJsonCfgCase1(t *testing.T) { TpInDir: "/var/spool/cgrates/loader/in", TpOutDir: "/var/spool/cgrates/loader/out", Data: []*LoaderDataType{ + { + Type: "*filters", + Filename: "Filters.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "Type", + Path: "Type", + pathSlice: []string{"Type"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Element", + Path: "Element", + pathSlice: []string{"Element"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Values", + Path: "Values", + pathSlice: []string{"Values"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, { Type: "*attributes", Filename: "Attributes.csv", @@ -85,6 +138,1129 @@ func TestLoaderSCfgloadFromJsonCfgCase1(t *testing.T) { }, }, }, + { + Type: "*resources", + Filename: "Resources.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "FilterIDs", + Path: "FilterIDs", + pathSlice: []string{"FilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Weight", + Path: "Weight", + pathSlice: []string{"Weight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "TTL", + Path: "UsageTTL", + pathSlice: []string{"UsageTTL"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Limit", + Path: "Limit", + pathSlice: []string{"Limit"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.5", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "AllocationMessage", + Path: "AllocationMessage", + pathSlice: []string{"AllocationMessage"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.6", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Blocker", + Path: "Blocker", + pathSlice: []string{"Blocker"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.7", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Stored", + Path: "Stored", + pathSlice: []string{"Stored"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.8", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ThresholdIDs", + Path: "ThresholdIDs", + pathSlice: []string{"ThresholdIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.9", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, + { + Type: "*stats", + Filename: "Stats.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "FilterIDs", + Path: "FilterIDs", + pathSlice: []string{"FilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Weight", + Path: "Weight", + pathSlice: []string{"Weight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "QueueLength", + Path: "QueueLength", + pathSlice: []string{"QueueLength"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "TTL", + Path: "TTL", + pathSlice: []string{"TTL"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.5", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "MinItems", + Path: "MinItems", + pathSlice: []string{"MinItems"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.6", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "MetricIDs", + Path: "MetricIDs", + pathSlice: []string{"MetricIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.7", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "MetricFilterIDs", + Path: "MetricFilterIDs", + pathSlice: []string{"MetricFilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.8", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Blocker", + Path: "Blocker", + pathSlice: []string{"Blocker"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.9", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Stored", + Path: "Stored", + pathSlice: []string{"Stored"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.10", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ThresholdIDs", + Path: "ThresholdIDs", + pathSlice: []string{"ThresholdIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.11", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, + { + Type: "*thresholds", + Filename: "Thresholds.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "FilterIDs", + Path: "FilterIDs", + pathSlice: []string{"FilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Weight", + Path: "Weight", + pathSlice: []string{"Weight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "MaxHits", + Path: "MaxHits", + pathSlice: []string{"MaxHits"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "MinHits", + Path: "MinHits", + pathSlice: []string{"MinHits"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.5", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "MinSleep", + Path: "MinSleep", + pathSlice: []string{"MinSleep"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.6", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Blocker", + Path: "Blocker", + pathSlice: []string{"Blocker"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.7", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ActionProfileIDs", + Path: "ActionProfileIDs", + pathSlice: []string{"ActionProfileIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.8", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Async", + Path: "Async", + pathSlice: []string{"Async"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.9", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, + { + Type: "*routes", + Filename: "Routes.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "FilterIDs", + Path: "FilterIDs", + pathSlice: []string{"FilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Weight", + Path: "Weight", + pathSlice: []string{"Weight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Sorting", + Path: "Sorting", + pathSlice: []string{"Sorting"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "SortingParameters", + Path: "SortingParameters", + pathSlice: []string{"SortingParameters"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.5", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RouteID", + Path: "RouteID", + pathSlice: []string{"RouteID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.6", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RouteFilterIDs", + Path: "RouteFilterIDs", + pathSlice: []string{"RouteFilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.7", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RouteAccountIDs", + Path: "RouteAccountIDs", + pathSlice: []string{"RouteAccountIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.8", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RouteRatingPlanIDs", + Path: "RouteRatingPlanIDs", + pathSlice: []string{"RouteRatingPlanIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.9", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RouteResourceIDs", + Path: "RouteResourceIDs", + pathSlice: []string{"RouteResourceIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.10", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RouteStatIDs", + Path: "RouteStatIDs", + pathSlice: []string{"RouteStatIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.11", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RouteWeight", + Path: "RouteWeight", + pathSlice: []string{"RouteWeight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.12", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RouteBlocker", + Path: "RouteBlocker", + pathSlice: []string{"RouteBlocker"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.13", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RouteParameters", + Path: "RouteParameters", + pathSlice: []string{"RouteParameters"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.14", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, + { + Type: "*chargers", + Filename: "Chargers.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "FilterIDs", + Path: "FilterIDs", + pathSlice: []string{"FilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Weight", + Path: "Weight", + pathSlice: []string{"Weight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RunID", + Path: "RunID", + pathSlice: []string{"RunID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "AttributeIDs", + Path: "AttributeIDs", + pathSlice: []string{"AttributeIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.5", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, + { + Type: "*dispatchers", + Filename: "DispatcherProfiles.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "FilterIDs", + Path: "FilterIDs", + pathSlice: []string{"FilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Weight", + Path: "Weight", + pathSlice: []string{"Weight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Strategy", + Path: "Strategy", + pathSlice: []string{"Strategy"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "StrategyParameters", + Path: "StrategyParameters", + pathSlice: []string{"StrategyParameters"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.5", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ConnID", + Path: "ConnID", + pathSlice: []string{"ConnID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.6", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ConnFilterIDs", + Path: "ConnFilterIDs", + pathSlice: []string{"ConnFilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.7", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ConnWeight", + Path: "ConnWeight", + pathSlice: []string{"ConnWeight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.8", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ConnBlocker", + Path: "ConnBlocker", + pathSlice: []string{"ConnBlocker"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.9", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ConnParameters", + Path: "ConnParameters", + pathSlice: []string{"ConnParameters"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.10", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, + { + Type: "*dispatcher_hosts", + Filename: "DispatcherHosts.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "Address", + Path: "Address", + pathSlice: []string{"Address"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Transport", + Path: "Transport", + pathSlice: []string{"Transport"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "TLS", + Path: "TLS", + pathSlice: []string{"TLS"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, + { + Type: "*rate_profiles", + Filename: "RateProfiles.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "FilterIDs", + Path: "FilterIDs", + pathSlice: []string{"FilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Weight", + Path: "Weight", + pathSlice: []string{"Weight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "MinCost", + Path: "MinCost", + pathSlice: []string{"MinCost"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "MaxCost", + Path: "MaxCost", + pathSlice: []string{"MaxCost"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.5", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "MaxCostStrategy", + Path: "MaxCostStrategy", + pathSlice: []string{"MaxCostStrategy"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.6", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateID", + Path: "RateID", + pathSlice: []string{"RateID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.7", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateFilterIDs", + Path: "RateFilterIDs", + pathSlice: []string{"RateFilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.8", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateActivationTimes", + Path: "RateActivationTimes", + pathSlice: []string{"RateActivationTimes"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.9", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateWeight", + Path: "RateWeight", + pathSlice: []string{"RateWeight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.10", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateBlocker", + Path: "RateBlocker", + pathSlice: []string{"RateBlocker"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.11", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateIntervalStart", + Path: "RateIntervalStart", + pathSlice: []string{"RateIntervalStart"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.12", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateFixedFee", + Path: "RateFixedFee", + pathSlice: []string{"RateFixedFee"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.13", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateRecurrentFee", + Path: "RateRecurrentFee", + pathSlice: []string{"RateRecurrentFee"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.14", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateUnit", + Path: "RateUnit", + pathSlice: []string{"RateUnit"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.15", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "RateIncrement", + Path: "RateIncrement", + pathSlice: []string{"RateIncrement"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.16", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, + { + Type: "*action_profiles", + Filename: "ActionProfiles.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "FilterIDs", + Path: "FilterIDs", + pathSlice: []string{"FilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Weight", + Path: "Weight", + pathSlice: []string{"Weight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Schedule", + Path: "Schedule", + pathSlice: []string{"Schedule"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "TargetType", + Path: "TargetType", + pathSlice: []string{"TargetType"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.5", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "TargetIDs", + Path: "TargetIDs", + pathSlice: []string{"TargetIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.6", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ActionID", + Path: "ActionID", + pathSlice: []string{"ActionID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.7", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ActionFilterIDs", + Path: "ActionFilterIDs", + pathSlice: []string{"ActionFilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.8", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ActionBlocker", + Path: "ActionBlocker", + pathSlice: []string{"ActionBlocker"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.9", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ActionTTL", + Path: "ActionTTL", + pathSlice: []string{"ActionTTL"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.10", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ActionType", + Path: "ActionType", + pathSlice: []string{"ActionType"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.11", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ActionOpts", + Path: "ActionOpts", + pathSlice: []string{"ActionOpts"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.12", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ActionPath", + Path: "ActionPath", + pathSlice: []string{"ActionPath"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.13", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ActionValue", + Path: "ActionValue", + pathSlice: []string{"ActionValue"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.14", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, + { + Type: "*accounts", + Filename: "Accounts.csv", + Flags: flags, + Fields: []*FCTemplate{ + { + Tag: "Tenant", + Path: "Tenant", + pathSlice: []string{"Tenant"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "ID", + Path: "ID", + pathSlice: []string{"ID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.1", utils.InfieldSep), + Mandatory: true, + Layout: time.RFC3339, + }, + { + Tag: "FilterIDs", + Path: "FilterIDs", + pathSlice: []string{"FilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.2", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "Weight", + Path: "Weight", + pathSlice: []string{"Weight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.3", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceID", + Path: "BalanceID", + pathSlice: []string{"BalanceID"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.4", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceFilterIDs", + Path: "BalanceFilterIDs", + pathSlice: []string{"BalanceFilterIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.5", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceWeight", + Path: "BalanceWeight", + pathSlice: []string{"BalanceWeight"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.6", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceBlocker", + Path: "BalanceBlocker", + pathSlice: []string{"BalanceBlocker"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.7", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceType", + Path: "BalanceType", + pathSlice: []string{"BalanceType"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.8", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceOpts", + Path: "BalanceOpts", + pathSlice: []string{"BalanceOpts"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.9", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceCostIncrements", + Path: "BalanceCostIncrements", + pathSlice: []string{"BalanceCostIncrements"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.10", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceAttributeIDs", + Path: "BalanceAttributeIDs", + pathSlice: []string{"BalanceAttributeIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.11", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceRateProfileIDs", + Path: "BalanceRateProfileIDs", + pathSlice: []string{"BalanceRateProfileIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.12", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceUnitFactors", + Path: "BalanceUnitFactors", + pathSlice: []string{"BalanceUnitFactors"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.13", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "BalanceUnits", + Path: "BalanceUnits", + pathSlice: []string{"BalanceUnits"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.14", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + { + Tag: "ThresholdIDs", + Path: "ThresholdIDs", + pathSlice: []string{"ThresholdIDs"}, + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.15", utils.InfieldSep), + Mandatory: false, + Layout: time.RFC3339, + }, + }, + }, }, }, } @@ -96,7 +1272,7 @@ func TestLoaderSCfgloadFromJsonCfgCase1(t *testing.T) { } else if err = newCfg.loadLoaderSCfg(jsonCfg); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, newCfg.loaderCfg) { - t.Errorf("Expected %+v,\n received %+v", utils.ToJSON(expected), utils.ToJSON(newCfg.loaderCfg)) + t.Errorf("expected: %+v,\nreceived: %+v", utils.ToJSON(expected), utils.ToJSON(newCfg.loaderCfg)) } } @@ -174,9 +1350,11 @@ func TestLoaderSCfgloadFromJsonCfgCase5(t *testing.T) { { Tag: "TenantID", Path: "Tenant", + pathSlice: []string{"Tenant"}, Type: utils.MetaVariable, Value: NewRSRParsersMustCompile("~*req.0", utils.InfieldSep), Mandatory: true, + Layout: time.RFC3339, }, }, }, @@ -197,8 +1375,8 @@ func TestLoaderSCfgloadFromJsonCfgCase5(t *testing.T) { jsonCfg := NewDefaultCGRConfig() if err = jsonCfg.loaderCfg[0].loadFromJSONCfg(cfg, msgTemplates, jsonCfg.generalCfg.RSRSep); err != nil { t.Error(err) - } else if !reflect.DeepEqual(jsonCfg.loaderCfg[0].Data[0].Fields[0], expectedFields[0].Data[0].Fields[0]) { - t.Errorf("Expected %+v,\n received %+v", utils.ToJSON(expectedFields[0].Data[0].Fields[0]), utils.ToJSON(jsonCfg.loaderCfg[0].Data[0].Fields[0])) + } else if !reflect.DeepEqual(jsonCfg.loaderCfg[0].Data[1].Fields[0], expectedFields[0].Data[0].Fields[0]) { + t.Errorf("Expected %+v,\n received %+v", utils.ToJSON(expectedFields[0].Data[0].Fields[0]), utils.ToJSON(jsonCfg.loaderCfg[0].Data[1].Fields[0])) } } @@ -276,6 +1454,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { }, ], }` + var flags []string eMap := []map[string]interface{}{ { utils.IDCfg: "*default", @@ -292,7 +1471,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*filters", utils.FilenameCfg: "Filters.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -331,7 +1510,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*attributes", utils.FilenameCfg: "Attributes.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "TenantID", @@ -351,7 +1530,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*resources", utils.FilenameCfg: "Resources.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -420,7 +1599,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*stats", utils.FilenameCfg: "Stats.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -501,7 +1680,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*thresholds", utils.FilenameCfg: "Thresholds.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -570,7 +1749,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*routes", utils.FilenameCfg: "Routes.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -669,7 +1848,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*chargers", utils.FilenameCfg: "Chargers.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -714,7 +1893,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*dispatchers", utils.FilenameCfg: "DispatcherProfiles.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -789,7 +1968,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*dispatcher_hosts", utils.FilenameCfg: "DispatcherHosts.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -828,7 +2007,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*rate_profiles", utils.FilenameCfg: "RateProfiles.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -939,7 +2118,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*action_profiles", utils.FilenameCfg: "ActionProfiles.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant", @@ -1038,7 +2217,7 @@ func TestLoaderCfgAsMapInterfaceCase1(t *testing.T) { { utils.TypeCfg: "*accounts", utils.FilenameCfg: "Accounts.csv", - utils.FlagsCfg: nil, + utils.FlagsCfg: flags, utils.FieldsCfg: []map[string]interface{}{ { utils.TagCfg: "Tenant",