Added tests for dynamic Set path

This commit is contained in:
Trial97
2020-05-25 09:47:26 +03:00
committed by Dan Christian Bogos
parent 87567198c2
commit eee83b5213
3 changed files with 20 additions and 5 deletions

View File

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

View File

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

View File

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