Fixup responder trying to read nil in case of errors coming from above, adding some XML parsing tests

This commit is contained in:
DanB
2014-04-16 10:51:27 +02:00
parent 4e1776d6fd
commit f1b639b04e
4 changed files with 49 additions and 4 deletions

View File

@@ -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

View File

@@ -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>

View File

@@ -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
}

View File

@@ -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)
}
}