mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added tests for dynamic Set path
This commit is contained in:
committed by
Dan Christian Bogos
parent
87567198c2
commit
eee83b5213
@@ -217,6 +217,7 @@ func (ar *AgentRequest) SetFields(tplFlds []*config.FCTemplate) (err error) {
|
||||
return
|
||||
}
|
||||
var fullPath *utils.FullPath
|
||||
var itmPath []string
|
||||
if fullPath, err = ar.dynamicProvider.GetFullFieldPath(tplFld.Path); err != nil {
|
||||
return
|
||||
} else if fullPath == nil { // no dynamic path
|
||||
@@ -224,9 +225,12 @@ func (ar *AgentRequest) SetFields(tplFlds []*config.FCTemplate) (err error) {
|
||||
PathItems: tplFld.GetPathItems().Clone(), // need to clone so me do not modify the template
|
||||
Path: tplFld.Path,
|
||||
}
|
||||
itmPath = tplFld.GetPathSlice()[1:]
|
||||
} else {
|
||||
itmPath = fullPath.PathItems.Slice()[1:]
|
||||
}
|
||||
|
||||
nMItm := &config.NMItem{Data: out, Path: tplFld.GetPathSlice()[1:], Config: tplFld}
|
||||
nMItm := &config.NMItem{Data: out, Path: itmPath, Config: tplFld}
|
||||
switch tplFld.Type {
|
||||
case utils.META_COMPOSED:
|
||||
err = utils.ComposeNavMapVal(ar, fullPath, nMItm)
|
||||
|
||||
@@ -2004,10 +2004,10 @@ func TestAgReqDynamicPath(t *testing.T) {
|
||||
Path: utils.MetaCgrep + utils.NestingSep + "Route",
|
||||
Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("~*cgreq.Routes[CGR_|~*cgreq.BestRoute]", true, utils.INFIELD_SEP),
|
||||
},
|
||||
// {Tag: "Route2",
|
||||
// Path: utils.MetaCgrep + utils.NestingSep + "Route2[CGR_|]",
|
||||
// Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("~*cgreq.Routes[CGR_|~*cgreq.BestRoute]", true, utils.INFIELD_SEP),
|
||||
// },
|
||||
{Tag: "Route2",
|
||||
Path: utils.MetaCgrep + utils.NestingSep + "Route2[CGR_|~*cgreq.BestRoute]",
|
||||
Type: utils.MetaVariable, Value: config.NewRSRParsersMustCompile("~*cgreq.Routes[CGR_ROUTE2]", true, utils.INFIELD_SEP),
|
||||
},
|
||||
}
|
||||
for _, v := range tplFlds {
|
||||
v.ComputePath()
|
||||
@@ -2028,6 +2028,9 @@ func TestAgReqDynamicPath(t *testing.T) {
|
||||
eMp.Set(utils.PathItems{{Field: "Route"}}, &utils.NMSlice{
|
||||
&config.NMItem{Data: "1001", Path: []string{"Route"},
|
||||
Config: tplFlds[4]}})
|
||||
eMp.Set(utils.PathItems{{Field: "Route2"}, {Field: "CGR_ROUTE1"}}, &utils.NMSlice{
|
||||
&config.NMItem{Data: "1002", Path: []string{"Route2", "CGR_ROUTE1"},
|
||||
Config: tplFlds[5]}})
|
||||
|
||||
if err := agReq.SetFields(tplFlds); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -76,7 +76,15 @@ func (path PathItems) String() (out string) {
|
||||
return
|
||||
}
|
||||
return out[1:]
|
||||
}
|
||||
|
||||
// Slice returns the path as string slice
|
||||
func (path PathItems) Slice() (out []string) {
|
||||
out = make([]string, len(path))
|
||||
for i, v := range path {
|
||||
out[i] = v.String()
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PathItem used by the NM interface to store the path information
|
||||
|
||||
Reference in New Issue
Block a user