Added *vars for ExportRequest && unit tests

This commit is contained in:
gezimbll
2023-06-21 08:10:02 -04:00
committed by Dan Christian Bogos
parent 77e9c5720d
commit b755fcca01
3 changed files with 42 additions and 10 deletions

View File

@@ -345,7 +345,7 @@
{"tag": "ToR", "path": "*exp.ToR", "type": "*variable", "value": "~*req.ToR"},
{"tag": "OriginID", "path": "*exp.OriginID", "type": "*variable", "value": "~*req.OriginID"},
{"tag": "RequestType", "path": "*exp.RequestType", "type": "*variable", "value": "~*req.RequestType"},
{"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*tenant.Tenant"},
{"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*vars.*tenant"},
{"tag": "Category", "path": "*exp.Category", "type": "*variable", "value": "~*req.Category"},
{"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"},
{"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"},
@@ -391,7 +391,7 @@
{"tag": "ToR", "path": "*exp.ToR", "type": "*variable", "value": "~*req.ToR"},
{"tag": "OriginID", "path": "*exp.OriginID", "type": "*variable", "value": "~*req.OriginID"},
{"tag": "RequestType", "path": "*exp.RequestType", "type": "*variable", "value": "~*req.RequestType"},
{"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*tenant.Tenant"},
{"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*vars.*tenant"},
{"tag": "Category", "path": "*exp.Category", "type": "*variable", "value": "~*req.Category"},
{"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"},
{"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"},
@@ -439,7 +439,7 @@
{"tag": "ToR", "path": "*exp.ToR", "type": "*variable", "value": "~*req.ToR"},
{"tag": "OriginID", "path": "*exp.OriginID", "type": "*variable", "value": "~*req.OriginID"},
{"tag": "RequestType", "path": "*exp.RequestType", "type": "*variable", "value": "~*req.RequestType"},
{"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*tenant.Tenant"},
{"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*vars.*tenant"},
{"tag": "Category", "path": "*exp.Category", "type": "*variable", "value": "~*req.Category"},
{"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"},
{"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"},
@@ -490,7 +490,7 @@
{"tag": "ToR", "path": "*exp.ToR", "type": "*variable", "value": "~*req.ToR"},
{"tag": "OriginID", "path": "*exp.OriginID", "type": "*variable", "value": "~*req.OriginID"},
{"tag": "RequestType", "path": "*exp.RequestType", "type": "*variable", "value": "~*req.RequestType"},
{"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*tenant.Tenant"},
{"tag": "Tenant", "path": "*exp.Tenant", "type": "*variable", "value": "~*vars.*tenant"},
{"tag": "Category", "path": "*exp.Category", "type": "*variable", "value": "~*req.Category"},
{"tag": "Account", "path": "*exp.Account", "type": "*variable", "value": "~*req.Account"},
{"tag": "Subject", "path": "*exp.Subject", "type": "*variable", "value": "~*req.Subject"},

View File

@@ -290,3 +290,35 @@ func TestEEPrepareOrderMap(t *testing.T) {
t.Errorf("Expected %v \n but received \n %v", utils.IfaceAsString(body), utils.IfaceAsString(rcv))
}
}
func TestExportRequestTenant(t *testing.T) {
bP := new(bytePreparing)
inData := map[string]utils.DataStorage{
utils.MetaVars: utils.MapStorage{
utils.MetaTenant: "cgrates.org"},
}
expNM := utils.NewOrderedNavigableMap()
tpFields := []*config.FCTemplate{
{
Tag: "Tenant",
Path: utils.MetaExp + utils.NestingSep + utils.Tenant,
Type: utils.MetaVariable,
Value: config.NewRSRParsersMustCompile(utils.DynamicDataPrefix+utils.MetaVars+utils.NestingSep+utils.MetaTenant, utils.InfieldSep),
},
}
tpFields[0].ComputePath()
if err := engine.NewExportRequest(inData, "cgrates.org", nil, map[string]*utils.OrderedNavigableMap{utils.MetaExp: expNM}).SetFields(tpFields); err != nil {
t.Error(err)
}
rcv, err := bP.PrepareOrderMap(expNM)
if err != nil {
t.Error(err)
}
valMp := map[string]any{
"Tenant": "cgrates.org",
}
body, _ := json.Marshal(valMp)
if !reflect.DeepEqual(rcv, body) {
t.Errorf("Expected %v \n but received \n %v", utils.IfaceAsString(body), utils.IfaceAsString(rcv))
}
}

View File

@@ -266,12 +266,12 @@ func exportEventWithExporter(exp EventExporter, ev *utils.CGREvent, oneTime bool
} else {
expNM := utils.NewOrderedNavigableMap()
err = engine.NewExportRequest(map[string]utils.DataStorage{
utils.MetaReq: utils.MapStorage(ev.Event),
utils.MetaDC: exp.GetMetrics(),
utils.MetaOpts: utils.MapStorage(ev.APIOpts),
utils.MetaCfg: cfg.GetDataProvider(),
utils.MetaEC: utils.MapStorage{utils.CostDetails: ev.Event[utils.CostDetails]},
utils.MetaTenant: utils.MapStorage{utils.Tenant: ev.Tenant},
utils.MetaReq: utils.MapStorage(ev.Event),
utils.MetaDC: exp.GetMetrics(),
utils.MetaOpts: utils.MapStorage(ev.APIOpts),
utils.MetaCfg: cfg.GetDataProvider(),
utils.MetaEC: utils.MapStorage{utils.CostDetails: ev.Event[utils.CostDetails]},
utils.MetaVars: utils.MapStorage{utils.MetaTenant: ev.Tenant},
}, utils.FirstNonEmpty(ev.Tenant, cfg.GeneralCfg().DefaultTenant),
filterS,
map[string]*utils.OrderedNavigableMap{utils.MetaExp: expNM}).SetFields(exp.Cfg().ContentFields())