mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
AgentRequest.AsNavigableMap operational with test
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user