From 20e3ede5d3813249a5ae595ef67a20ed061e2946 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 21 Aug 2019 17:06:24 +0300 Subject: [PATCH] Updated NavigableMap field parsing --- config/navigablemap.go | 18 ++++++++++++++++++ engine/cdr_test.go | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/config/navigablemap.go b/config/navigablemap.go index 1b0562bfc..c06590d3f 100644 --- a/config/navigablemap.go +++ b/config/navigablemap.go @@ -181,6 +181,24 @@ func (nM *NavigableMap) getNextMap(mp map[string]interface{}, spath string) (map } } else { switch mv := mi.(type) { + case []interface{}: + // in case we create the map using json and we marshall the value into a map[string]interface{} + // we can have slice of interfaces that is masking a slice of map[string]interface{} + // this is for CostDetails BalanceSummaries + if *idx < len(mv) { + mm := mv[*idx] + switch mmv := mm.(type) { + case map[string]interface{}: + return mmv, nil + case *map[string]interface{}: + return *mmv, nil + case NavigableMap: + return mmv.data, nil + case *NavigableMap: + return mmv.data, nil + default: + } + } case []map[string]interface{}: if *idx < len(mv) { return mv[*idx], nil diff --git a/engine/cdr_test.go b/engine/cdr_test.go index e3722dd2a..0c28be1ee 100644 --- a/engine/cdr_test.go +++ b/engine/cdr_test.go @@ -244,6 +244,20 @@ func TestFieldAsStringForCostDetails(t *testing.T) { AccountSummary: &AccountSummary{ Tenant: "cgrates.org", ID: "AccountFromAccountSummary", + BalanceSummaries: []*BalanceSummary{ + &BalanceSummary{ + UUID: "f9be602747f4", + ID: "monetary", + Type: utils.MONETARY, + Value: 0.5, + }, + &BalanceSummary{ + UUID: "2e02510ab90a", + ID: "voice", + Type: utils.VOICE, + Value: 10, + }, + }, }, } @@ -284,6 +298,14 @@ func TestFieldAsStringForCostDetails(t *testing.T) { } else if fldVal != eFldVal { t.Errorf("field: <%v>, expected: <%v>, received: <%v>", prsr, eFldVal, fldVal) } + + prsr = config.NewRSRParserMustCompile("~CostDetails.AccountSummary.BalanceSummaries[1].ID", true) + eFldVal = "voice" + if fldVal, err := cdr.FieldAsString(prsr); err != nil { + t.Error(err) + } else if fldVal != eFldVal { + t.Errorf("field: <%v>, expected: <%v>, received: <%v>", prsr, eFldVal, fldVal) + } } func TestFormatCost(t *testing.T) {