diff --git a/agents/agentreq.go b/agents/agentreq.go index f86348c93..da295464d 100644 --- a/agents/agentreq.go +++ b/agents/agentreq.go @@ -112,11 +112,12 @@ func (ar *AgentRequest) AsNavigableMap(tplFlds []*config.CfgCdrField) ( } else if !pass { continue } - if out, err := ar.ParseField(tplFld); err != nil { + out, err := ar.ParseField(tplFld) + if err != nil { return nil, err - } else { - nM.Set(strings.Split(tplFld.FieldId, utils.HIERARCHY_SEP), out, true) } + nM.Set(strings.Split(tplFld.FieldId, + utils.HIERARCHY_SEP), out, true) } return } @@ -159,7 +160,7 @@ func (ar *AgentRequest) composedField(outTpl utils.RSRFields) (outVal string) { } continue } - valStr, err := ar.FieldAsString(strings.Split(rsrTpl.Id, utils.CONCATENATED_KEY_SEP)) + valStr, err := ar.FieldAsString(strings.Split(rsrTpl.Id, utils.HIERARCHY_SEP)) if err != nil { utils.Logger.Warning( fmt.Sprintf("<%s> %s", diff --git a/agents/agentreq_test.go b/agents/agentreq_test.go index 492a380a1..b44b689ec 100644 --- a/agents/agentreq_test.go +++ b/agents/agentreq_test.go @@ -19,7 +19,7 @@ along with this program. If not, see package agents import ( - "fmt" + "reflect" "testing" "time" @@ -85,19 +85,30 @@ func TestAgReqAsNavigableMap(t *testing.T) { &config.CfgCdrField{Tag: "AttrPaypalAccount", FieldId: "PaypalAccount", Type: utils.META_COMPOSED, Filters: []string{"*string:*cgrReply>Error:"}, - Value: utils.ParseRSRFieldsMustCompile("*cgrReply>Attributes>PaypalAccount", utils.INFIELD_SEP)}, + Value: utils.ParseRSRFieldsMustCompile( + "*cgrReply>Attributes>PaypalAccount", utils.INFIELD_SEP)}, &config.CfgCdrField{Tag: "MaxUsage", FieldId: "MaxUsage", Type: utils.META_COMPOSED, Filters: []string{"*string:*cgrReply>Error:"}, - Value: utils.ParseRSRFieldsMustCompile("*cgrReply>MaxUsage", utils.INFIELD_SEP)}, + Value: utils.ParseRSRFieldsMustCompile( + "*cgrReply>MaxUsage{*duration_seconds}", utils.INFIELD_SEP)}, &config.CfgCdrField{Tag: "Error", FieldId: "Error", Type: utils.META_COMPOSED, Filters: []string{"*rsr::*cgrReply>Error(!^$)"}, - Value: utils.ParseRSRFieldsMustCompile("*cgrReply>Error", utils.INFIELD_SEP)}, + Value: utils.ParseRSRFieldsMustCompile( + "*cgrReply>Error", utils.INFIELD_SEP)}, } + eMp := engine.NewNavigableMap(nil) + eMp.Set([]string{utils.Tenant}, "cgrates.org", true) + eMp.Set([]string{utils.Account}, "1001", true) + eMp.Set([]string{utils.Destination}, "1002", true) + eMp.Set([]string{"RequestedUsage"}, "180", true) + eMp.Set([]string{"PaypalAccount"}, "cgrates@paypal.com", true) + eMp.Set([]string{"MaxUsage"}, "120", true) if mpOut, err := agReq.AsNavigableMap(tplFlds); err != nil { t.Error(err) - } else { - fmt.Printf("mpOut: %+v\n", mpOut.AsMapStringInterface()) + } else if !reflect.DeepEqual(eMp, mpOut) { + t.Errorf("expecting: %+v, received: %+v", + eMp.AsMapStringInterface(), mpOut.AsMapStringInterface()) } }