Default requestType in agents

This commit is contained in:
andronache
2021-06-28 15:13:04 +03:00
committed by Dan Christian Bogos
parent db672ba0e5
commit 348dcb5d6a
5 changed files with 23 additions and 3 deletions

View File

@@ -144,7 +144,7 @@ func (smaEv *SMAsteriskEvent) Destination() string {
}
func (smaEv *SMAsteriskEvent) RequestType() string {
return smaEv.cachedFields[utils.CGRReqType]
return utils.FirstNonEmpty(smaEv.cachedFields[utils.CGRReqType], config.CgrConfig().GeneralCfg().DefaultReqType)
}
func (smaEv *SMAsteriskEvent) Tenant() string {

View File

@@ -211,7 +211,7 @@ func TestSMAEventRequestType(t *testing.T) {
}
ev = make(map[string]interface{}) // Clear previous data
smaEv = NewSMAsteriskEvent(ev, "127.0.0.1", "")
if smaEv.RequestType() != "" {
if smaEv.RequestType() != config.CgrConfig().GeneralCfg().DefaultReqType {
t.Error("Received:", smaEv.RequestType())
}
}
@@ -459,3 +459,19 @@ func TestSMAEventV1TerminateSessionArgs(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(exp2), utils.ToJSON(rcv))
}
}
func TestRequestType(t *testing.T) {
var ev map[string]interface{}
if err := json.Unmarshal([]byte(stasisStart), &ev); err != nil {
t.Error(err)
}
smaEv := NewSMAsteriskEvent(ev, "127.0.0.1", "")
if smaEv.RequestType() != "*prepaid" {
t.Error("Received:", smaEv.RequestType())
}
ev = make(map[string]interface{}) // Clear previous data
smaEv = NewSMAsteriskEvent(ev, "127.0.0.1", "")
if smaEv.RequestType() != config.CgrConfig().GeneralCfg().DefaultReqType {
t.Error("Received:", smaEv.RequestType())
}
}

View File

@@ -147,6 +147,9 @@ func (kev KamEvent) AsMapStringInterface() (mp map[string]interface{}) {
if _, has := mp[utils.Source]; !has {
mp[utils.Source] = utils.KamailioAgent
}
if _, has := mp[utils.RequestType]; !has {
mp[utils.RequestType] = config.CgrConfig().GeneralCfg().DefaultReqType
}
return
}

View File

@@ -102,6 +102,7 @@ func TestKamEvAsMapStringInterface(t *testing.T) {
expMp["from_tag"] = "bf71ad59"
expMp["to_tag"] = "7351fecf"
expMp["cgr_reqtype"] = utils.MetaPostpaid
expMp[utils.RequestType] = utils.MetaRated
expMp[utils.Source] = utils.KamailioAgent
rcv := kamEv.AsMapStringInterface()
if !reflect.DeepEqual(expMp, rcv) {

View File

@@ -74,7 +74,7 @@
# Install and config CGRateS
- name: Install and config CGRateS
include: cgrates.yaml
# Configure Asterisk
- name: Download Asterisk
become: yes