Fixup CdrServer receiving nanoseconds as usage, more tests

This commit is contained in:
DanB
2014-05-19 17:50:31 +02:00
parent d5f6df9473
commit 1ad4068d73
8 changed files with 105 additions and 19 deletions

View File

@@ -35,10 +35,14 @@ func TestSetStorageDtChrg1(t *testing.T) {
}
func TestLoadCsvTpDtChrg1(t *testing.T) {
timings := `ALWAYS,*any,*any,*any,*any,00:00:00`
rates := `RT_DATA_2c,0,0.002,10,10,0`
destinationRates := `DR_DATA_1,*any,RT_DATA_2c,*up,4`
ratingPlans := `RP_DATA1,DR_DATA_1,ALWAYS,10`
timings := `TM1,*any,*any,*any,*any,00:00:00
TM2,*any,*any,*any,*any,01:00:00`
rates := `RT_DATA_2c,0,0.002,10,10,0
RT_DATA_1c,0,0.001,10,10,0`
destinationRates := `DR_DATA_1,*any,RT_DATA_2c,*up,4
DR_DATA_2,*any,RT_DATA_1c,*up,4`
ratingPlans := `RP_DATA1,DR_DATA_1,TM1,10
RP_DATA1,DR_DATA_2,TM2,10`
ratingProfiles := `*out,cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1,`
csvr := engine.NewStringCSVReader(ratingDb, acntDb, ',', "", timings, rates, destinationRates, ratingPlans, ratingProfiles,
"", "", "", "", "", "", "")
@@ -71,7 +75,51 @@ func TestLoadCsvTpDtChrg1(t *testing.T) {
func TestGetDataCostDtChrg1(t *testing.T) {
usedData := 20
usageDur := time.Duration(usedData) * time.Second
timeStart := time.Date(2014, 3, 4, 6, 0, 0, 0, time.UTC)
timeStart := time.Date(2014, 3, 4, 0, 0, 0, 0, time.Local)
cd := &engine.CallDescriptor{
Direction: "*out",
Category: "data",
Tenant: "cgrates.org",
Subject: "12345",
Account: "12345",
TimeStart: timeStart,
TimeEnd: timeStart.Add(usageDur),
DurationIndex: usageDur,
TOR: utils.DATA,
}
if cc, err := cd.GetCost(); err != nil {
t.Error(err)
} else if cc.Cost != 0.004 {
t.Error("Wrong cost returned: ", cc.Cost)
}
}
func TestGetDataCostSecondIntDtChrg1(t *testing.T) {
usedData := 20
usageDur := time.Duration(usedData) * time.Second
timeStart := time.Date(2014, 3, 4, 1, 0, 0, 0, time.Local)
cd := &engine.CallDescriptor{
Direction: "*out",
Category: "data",
Tenant: "cgrates.org",
Subject: "12345",
Account: "12345",
TimeStart: timeStart,
TimeEnd: timeStart.Add(usageDur),
DurationIndex: usageDur,
TOR: utils.DATA,
}
if cc, err := cd.GetCost(); err != nil {
t.Error(err)
} else if cc.Cost != 0.002 {
t.Error("Wrong cost returned: ", cc.Cost)
}
}
func TestGetBetweenCostDtChrg1(t *testing.T) {
usedData := 20
usageDur := time.Duration(usedData) * time.Second
timeStart := time.Date(2014, 3, 4, 0, 59, 50, 0, time.Local)
cd := &engine.CallDescriptor{
Direction: "*out",
Category: "data",