mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 14:48:43 +05:00
Fixup responder trying to read nil in case of errors coming from above, adding some XML parsing tests
This commit is contained in:
@@ -1315,6 +1315,30 @@ func TestGetCallCostLog(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxDebitInexistentAcnt(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
cc := &engine.CallCost{}
|
||||
cd := engine.CallDescriptor{
|
||||
Direction: "*out",
|
||||
Tenant: "cgrates.org",
|
||||
TOR: "call",
|
||||
Subject: "INVALID",
|
||||
Account: "INVALID",
|
||||
Destination: "1002",
|
||||
TimeStart: time.Date(2014, 3, 27, 10, 42, 26, 0, time.UTC),
|
||||
TimeEnd: time.Date(2014, 3, 27, 10, 42, 26, 0, time.UTC).Add(time.Duration(10) * time.Second),
|
||||
}
|
||||
if err := rater.Call("Responder.MaxDebit", cd, cc); err == nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
if err := rater.Call("Responder.Debit", cd, cc); err == nil {
|
||||
t.Error(err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCdrServer(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestParseXmlConfig(t *testing.T) {
|
||||
<field name="CallId" type="cdrfield" value="accid" width="16"/>
|
||||
<field name="Filler" type="filler" width="8"/>
|
||||
<field name="Filler" type="filler" width="8"/>
|
||||
<field name="TerminationCode" type="concatenated_cdrfield" value="operator,product" width="5"/>
|
||||
<field name="TerminationCode" type="cdrfield" value='~cost_details:s/"MatchedDestId":".+_(\s\s\s\s\s)"/$1/' width="5"/>
|
||||
<field name="Cost" type="cdrfield" value="cost" padding="zeroleft" width="9"/>
|
||||
<field name="CalledMask" type="cdrfield" value="calledmask" width="1"/>
|
||||
</fields>
|
||||
|
||||
@@ -46,7 +46,11 @@ func (rs *Responder) GetCost(arg CallDescriptor, reply *CallCost) (err error) {
|
||||
r, e := AccLock.GuardGetCost(arg.GetAccountKey(), func() (*CallCost, error) {
|
||||
return arg.GetCost()
|
||||
})
|
||||
*reply, err = *r, e
|
||||
if e != nil {
|
||||
return e
|
||||
} else if r != nil {
|
||||
*reply = *r
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -59,7 +63,11 @@ func (rs *Responder) Debit(arg CallDescriptor, reply *CallCost) (err error) {
|
||||
r, e := AccLock.GuardGetCost(arg.GetAccountKey(), func() (*CallCost, error) {
|
||||
return arg.Debit()
|
||||
})
|
||||
*reply, err = *r, e
|
||||
if e != nil {
|
||||
return e
|
||||
} else if r != nil {
|
||||
*reply = *r
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -72,7 +80,11 @@ func (rs *Responder) MaxDebit(arg CallDescriptor, reply *CallCost) (err error) {
|
||||
r, e := AccLock.GuardGetCost(arg.GetAccountKey(), func() (*CallCost, error) {
|
||||
return arg.MaxDebit()
|
||||
})
|
||||
*reply, err = *r, e
|
||||
if e != nil {
|
||||
return e
|
||||
} else if r != nil {
|
||||
*reply = *r
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -92,3 +92,12 @@ func TestNewRSRFieldDDz(t *testing.T) {
|
||||
t.Errorf("Unexpected RSRField received: %v", rsrField)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRSRFieldIvo(t *testing.T) {
|
||||
expectRSRField := &RSRField{Id: "cost_details", RSRule: &ReSearchReplace{regexp.MustCompile(`MatchedDestId":".+_(\s\s\s\s\s)"`), "$1"}}
|
||||
if rsrField, err := NewRSRField(`~cost_details:s/MatchedDestId":".+_(\s\s\s\s\s)"/$1/`); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rsrField, expectRSRField) {
|
||||
t.Errorf("Unexpected RSRField received: %v", rsrField)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user