Updated NavigableMap field parsing

This commit is contained in:
Trial97
2019-08-21 17:06:24 +03:00
committed by Dan Christian Bogos
parent ddb242191c
commit 20e3ede5d3
2 changed files with 40 additions and 0 deletions

View File

@@ -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

View File

@@ -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) {