mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
AgentRequest FieldAsInterface return Data instead NMItem fixes #2077
This commit is contained in:
committed by
Dan Christian Bogos
parent
236558137d
commit
e3a7800cb0
@@ -137,6 +137,12 @@ func (ar *AgentRequest) FieldAsInterface(fldPath []string) (val interface{}, err
|
||||
case utils.MetaOpts:
|
||||
val, err = ar.Opts.FieldAsInterface(fldPath[1:])
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if nmItems, isNMItems := val.(*utils.NMSlice); isNMItems { // special handling of NMItems, take the last value out of it
|
||||
val = (*nmItems)[len(*nmItems)-1].Interface()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -169,9 +175,6 @@ func (ar *AgentRequest) FieldAsString(fldPath []string) (val string, err error)
|
||||
if iface, err = ar.FieldAsInterface(fldPath); err != nil {
|
||||
return
|
||||
}
|
||||
if nmItems, isNMItems := iface.(*utils.NMSlice); isNMItems { // special handling of NMItems, take the last value out of it
|
||||
iface = (*nmItems)[len(*nmItems)-1].Interface()
|
||||
}
|
||||
return utils.IfaceAsString(iface), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -963,7 +963,7 @@ func TestAgReqFieldAsInterface(t *testing.T) {
|
||||
|
||||
path := []string{utils.MetaCgreq, utils.Usage}
|
||||
var expVal interface{}
|
||||
expVal = &utils.NMSlice{&config.NMItem{Data: 3 * time.Minute}}
|
||||
expVal = 3 * time.Minute
|
||||
if rply, err := agReq.FieldAsInterface(path); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rply, expVal) {
|
||||
@@ -971,7 +971,7 @@ func TestAgReqFieldAsInterface(t *testing.T) {
|
||||
}
|
||||
|
||||
path = []string{utils.MetaCgreq, utils.ToR}
|
||||
expVal = &utils.NMSlice{&config.NMItem{Data: utils.VOICE}}
|
||||
expVal = utils.VOICE
|
||||
if rply, err := agReq.FieldAsInterface(path); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rply, expVal) {
|
||||
@@ -1827,13 +1827,13 @@ func TestAgReqSetFieldsInCache(t *testing.T) {
|
||||
|
||||
if val, err := agReq.FieldAsInterface([]string{utils.MetaCache, utils.Tenant}); err != nil {
|
||||
t.Error(err)
|
||||
} else if (*val.(*utils.NMSlice))[0].Interface() != "cgrates.org" {
|
||||
} else if val != "cgrates.org" {
|
||||
t.Errorf("expecting: %+v, \n received: %+v ", "cgrates.org", utils.ToJSON(val))
|
||||
}
|
||||
|
||||
if val, err := agReq.FieldAsInterface([]string{utils.MetaCache, utils.Account}); err != nil {
|
||||
t.Error(err)
|
||||
} else if (*val.(*utils.NMSlice))[0].Interface() != "1001" {
|
||||
} else if val != "1001" {
|
||||
t.Errorf("expecting: %+v, \n received: %+v ", "1001", utils.ToJSON(val))
|
||||
}
|
||||
|
||||
@@ -1870,13 +1870,13 @@ func TestAgReqSetFieldsInCacheWithTimeOut(t *testing.T) {
|
||||
|
||||
if val, err := agReq.FieldAsInterface([]string{utils.MetaCache, utils.Tenant}); err != nil {
|
||||
t.Error(err)
|
||||
} else if (*val.(*utils.NMSlice))[0].Interface() != "cgrates.org" {
|
||||
} else if val != "cgrates.org" {
|
||||
t.Errorf("expecting: %+v, \n received: %+v ", "cgrates.org", utils.ToJSON(val))
|
||||
}
|
||||
|
||||
if val, err := agReq.FieldAsInterface([]string{utils.MetaCache, utils.Account}); err != nil {
|
||||
t.Error(err)
|
||||
} else if (*val.(*utils.NMSlice))[0].Interface() != "1001" {
|
||||
} else if val != "1001" {
|
||||
t.Errorf("expecting: %+v, \n received: %+v ", "1001", utils.ToJSON(val))
|
||||
}
|
||||
|
||||
@@ -1959,8 +1959,11 @@ func TestAgReqFiltersInsideField(t *testing.T) {
|
||||
v.ComputePath()
|
||||
}
|
||||
if err := agReq.SetFields(tplFlds); err != nil {
|
||||
// here we get error
|
||||
//t.Error(err)
|
||||
t.Error(err)
|
||||
}
|
||||
if val, err := agReq.FieldAsInterface([]string{utils.MetaCgreq, utils.AnswerTime}); err != nil {
|
||||
t.Error(err)
|
||||
} else if !val.(time.Time).Equal(time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC)) {
|
||||
t.Errorf("expecting: %+v, \n received: %+v ", time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC), val)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ cgrates (0.11.0~dev) UNRELEASED; urgency=medium
|
||||
* [SessionS] Added support for *stir_initiate
|
||||
* [RouteS] Renaming from SupplierS to RouteS
|
||||
* [AgentRequest] Improved NavigableMap
|
||||
* [General] Default timingIDs start from time.Now() (i.e. *monthly time.Now() + 1 month )
|
||||
* [AgentS] FieldAsInterface return data instead of NMItem
|
||||
|
||||
-- Alexandru Tripon <alexandru.tripon@itsyscom.com> Wed, 19 Feb 2020 13:25:52 +0200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user