Added *tenant case and tested it as well

This commit is contained in:
nickolasdaniel
2021-07-07 17:30:56 +03:00
committed by Dan Christian Bogos
parent b41d9ae2d6
commit 4d292cdad9
2 changed files with 11 additions and 0 deletions

View File

@@ -165,6 +165,8 @@ func (ar *AgentRequest) FieldAsInterface(fldPath []string) (val interface{}, err
} else {
val = ar.Cfg
}
case utils.MetaTenant:
return ar.Tenant, nil
}
if err != nil {
return

View File

@@ -957,6 +957,7 @@ func TestAgReqFieldAsInterface(t *testing.T) {
agReq.CGRRequest.Set(&utils.FullPath{Path: utils.ToR, PathSlice: []string{utils.ToR}}, &utils.DataNode{Type: utils.NMSliceType, Slice: []*utils.DataNode{{Type: utils.NMDataType, Value: &utils.DataLeaf{Data: utils.MetaVoice}}}})
agReq.CGRRequest.Set(&utils.FullPath{Path: utils.AccountField, PathSlice: []string{utils.AccountField}}, utils.NewLeafNode("1001"))
agReq.CGRRequest.Set(&utils.FullPath{Path: utils.Destination, PathSlice: []string{utils.Destination}}, utils.NewLeafNode("1002"))
agReq.CGRRequest.Set(&utils.FullPath{Path: utils.Tenant, PathSlice: []string{utils.Tenant}}, utils.NewLeafNode("cgrates.org"))
path := []string{utils.MetaCgreq, utils.Usage}
var expVal interface{}
@@ -990,6 +991,14 @@ func TestAgReqFieldAsInterface(t *testing.T) {
} else if !reflect.DeepEqual(rply, expVal) {
t.Errorf("Expected %v , received: %v", utils.ToJSON(expVal), utils.ToJSON(rply))
}
path = []string{utils.MetaTenant}
expVal = "cgrates.org"
if rply, err := agReq.FieldAsInterface(path); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(rply, expVal) {
t.Errorf("Expected %v , received: %v", utils.ToJSON(expVal), utils.ToJSON(rply))
}
}
func TestAgReqFieldAsInterfaceForOneFldPathCgrReq(t *testing.T) {