mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated NavigableMap field parsing
This commit is contained in:
committed by
Dan Christian Bogos
parent
ddb242191c
commit
20e3ede5d3
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user