exclude intervals that don't contain start time'

fix for integration tests
This commit is contained in:
Radu Ioan Fericean
2016-01-06 20:43:50 +02:00
parent b1e512bb57
commit 738406003e
3 changed files with 66 additions and 1 deletions

View File

@@ -89,6 +89,7 @@ type RatingInfo struct {
FallbackKeys []string
}
// SelectRatingIntevalsForTimespan orders rate intervals in time preserving only those which aply to the specified timestamp
func (ri RatingInfo) SelectRatingIntevalsForTimespan(ts *TimeSpan) (result RateIntervalList) {
ri.RateIntervals.Sort()
sorter := &RateIntervalTimeSorter{referenceTime: ts.TimeStart, ris: ri.RateIntervals}
@@ -97,6 +98,9 @@ func (ri RatingInfo) SelectRatingIntevalsForTimespan(ts *TimeSpan) (result RateI
var delta time.Duration = -1
var bestRateIntervalIndex int
for index, rateInterval := range rateIntervals {
if !rateInterval.Contains(ts.TimeStart, false) {
continue
}
startTime := rateInterval.Timing.getLeftMargin(ts.TimeStart)
tmpDelta := ts.TimeStart.Sub(startTime)
if (startTime.Before(ts.TimeStart) ||

View File

@@ -186,7 +186,7 @@ func TestRatingProfileRIforTSTwo(t *testing.T) {
}
}
func TestRatingProfileRIforTSThre(t *testing.T) {
func TestRatingProfileRIforTSThree(t *testing.T) {
ri := &RatingInfo{
RateIntervals: RateIntervalList{
&RateInterval{
@@ -218,3 +218,34 @@ func TestRatingProfileRIforTSThre(t *testing.T) {
t.Error("Wrong interval list: ", utils.ToIJSON(rIntervals))
}
}
func TestRatingProfileRIforTSMidnight(t *testing.T) {
ri := &RatingInfo{
RateIntervals: RateIntervalList{
&RateInterval{
Timing: &RITiming{
StartTime: "09:00:00",
},
},
&RateInterval{
Timing: &RITiming{
StartTime: "00:00:00",
},
},
&RateInterval{
Timing: &RITiming{
StartTime: "19:00:00",
},
},
},
}
ts := &TimeSpan{
TimeStart: time.Date(2016, 1, 6, 23, 40, 0, 0, time.UTC),
TimeEnd: time.Date(2016, 1, 7, 1, 1, 30, 0, time.UTC),
}
rIntervals := ri.SelectRatingIntevalsForTimespan(ts)
if len(rIntervals) != 1 ||
rIntervals[0].Timing.StartTime != "19:00:00" {
t.Error("Wrong interval list: ", utils.ToIJSON(rIntervals))
}
}

View File

@@ -344,6 +344,36 @@ func TestTutLocalGetCosts(t *testing.T) {
} else if cc.Cost != 0.327 { //
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1004",
TimeStart: time.Date(2016, 1, 6, 18, 31, 5, 0, time.UTC),
TimeEnd: time.Date(2016, 1, 6, 18, 32, 35, 0, time.UTC),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 1.3002 { //
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
cd = engine.CallDescriptor{
Direction: "*out",
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1002",
TimeStart: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC),
TimeEnd: time.Date(2014, 12, 7, 8, 44, 26, 0, time.UTC),
}
if err := tutLocalRpc.Call("Responder.GetCost", cd, &cc); err != nil {
t.Error("Got error on Responder.GetCost: ", err.Error())
} else if cc.Cost != 0.327 { //
t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON())
}
}
// Check call costs