From eee83b5213893ed3d978d3054a66640a88efcf1e Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 25 May 2020 09:47:26 +0300 Subject: [PATCH] Added tests for dynamic Set path --- agents/agentreq.go | 6 +++++- agents/agentreq_test.go | 11 +++++++---- utils/pathitem.go | 8 ++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/agents/agentreq.go b/agents/agentreq.go index bf4f1c7de..fa690732f 100644 --- a/agents/agentreq.go +++ b/agents/agentreq.go @@ -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) diff --git a/agents/agentreq_test.go b/agents/agentreq_test.go index 7122bd42a..c03f8c206 100644 --- a/agents/agentreq_test.go +++ b/agents/agentreq_test.go @@ -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) diff --git a/utils/pathitem.go b/utils/pathitem.go index eeb13aae1..4d22ee867 100644 --- a/utils/pathitem.go +++ b/utils/pathitem.go @@ -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