mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added tests for covering rateprofile and rates directory
This commit is contained in:
committed by
Dan Christian Bogos
parent
cf81fc80e0
commit
5bcd909046
@@ -221,6 +221,33 @@ func TestRateProfileSort(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRateCompile(t *testing.T) {
|
||||
rt := &RateProfile{
|
||||
Rates: map[string]*Rate{
|
||||
"randomVal1": {
|
||||
ID: "RT_CHRISTMAS",
|
||||
Weight: 30,
|
||||
ActivationTimes: "* * 24 12 *",
|
||||
},
|
||||
"randomVal2": {
|
||||
ID: "RT_CHRISTMAS",
|
||||
Weight: 30,
|
||||
ActivationTimes: utils.EmptyString,
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := rt.Compile(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
rt.Rates["randomVal1"].ActivationTimes = "* * * *"
|
||||
rt.Rates["randomVal2"].ActivationTimes = "* * * *"
|
||||
expectedErr := "expected exactly 5 fields, found 4: [* * * *]"
|
||||
if err := rt.Compile(); err == nil || err.Error() != expectedErr {
|
||||
t.Errorf("Expected %+v, received %+v ", expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRateProfileCompile(t *testing.T) {
|
||||
rt := &Rate{
|
||||
ID: "RT_CHRISTMAS",
|
||||
|
||||
2
go.sum
2
go.sum
@@ -66,8 +66,6 @@ github.com/cgrates/aringo v0.0.0-20191121125609-d85002bd1667 h1:eNku7bwLtSTpn6FQ
|
||||
github.com/cgrates/aringo v0.0.0-20191121125609-d85002bd1667/go.mod h1:l0xi5JUVqxL4P7RZ9YitbSCiOtjMY2j7JBOCJIysRWk=
|
||||
github.com/cgrates/baningo v0.0.0-20200925111414-e65b237006c9 h1:WwluddhgQoHkB72AzbC781qtB2xJLt+B9Rc2+NYy0Ts=
|
||||
github.com/cgrates/baningo v0.0.0-20200925111414-e65b237006c9/go.mod h1:3SwVROaS1Iml5lqEhj0gRhDRtmbBgypZpKcEkVTSleU=
|
||||
github.com/cgrates/cron v0.0.0-20200906113840-dd008627fdca h1:neuTTEjWsM+WXRyJ+MF1OzsNc+e7DGjrNZKIEIr8x4A=
|
||||
github.com/cgrates/cron v0.0.0-20200906113840-dd008627fdca/go.mod h1:I9cUDn/uzkakr0hmYTjXkQqf6wagg44L2p01gSYRRz0=
|
||||
github.com/cgrates/cron v0.0.0-20201005140714-2e0bdf04c9a5 h1:zRfZqy+YiSy8WaY1C9BNaVtpLbUCONZGkFfDMLjo8Ic=
|
||||
github.com/cgrates/cron v0.0.0-20201005140714-2e0bdf04c9a5/go.mod h1:I9cUDn/uzkakr0hmYTjXkQqf6wagg44L2p01gSYRRz0=
|
||||
github.com/cgrates/fsock v0.0.0-20191107070144-e7a331109df7 h1:dxtBWRAr62vRRKkExmJZ0u1EbCw/y0vOkSfdFND5qXw=
|
||||
|
||||
@@ -134,3 +134,49 @@ func TestOrderRatesOnIntervals(t *testing.T) {
|
||||
utils.ToIJSON(expOrdered), utils.ToIJSON(ordRts))
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrderRatesOnIntervalsCase1(t *testing.T) {
|
||||
rt0 := &engine.Rate{
|
||||
ID: "RATE0",
|
||||
Weight: 0,
|
||||
IntervalRates: []*engine.IntervalRate{
|
||||
{
|
||||
IntervalStart: time.Duration(0),
|
||||
},
|
||||
},
|
||||
}
|
||||
rt0.Compile()
|
||||
rtChristmas := &engine.Rate{
|
||||
ID: "RT_CHRISTMAS",
|
||||
ActivationTimes: "* * 24 12 *",
|
||||
Weight: 50,
|
||||
IntervalRates: []*engine.IntervalRate{
|
||||
{
|
||||
IntervalStart: time.Duration(0),
|
||||
},
|
||||
},
|
||||
}
|
||||
rtChristmas.Compile()
|
||||
aRts := []*engine.Rate{rt0, rtChristmas}
|
||||
sTime := time.Date(2020, time.December, 23, 23, 59, 05, 0, time.UTC)
|
||||
usage := 2 * time.Minute
|
||||
expectedErr := "maximum iterations reached"
|
||||
if _, err := orderRatesOnIntervals(aRts, sTime, usage, true, 0); err == nil || err.Error() != expectedErr {
|
||||
t.Errorf("Expected %+v, received %+v", expectedErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRatesWithWinner(t *testing.T) {
|
||||
rt := &rateWithTimes{
|
||||
uId: "randomID",
|
||||
}
|
||||
expected := &ratesWithWinner{
|
||||
rts: map[string]*rateWithTimes{
|
||||
"randomID": rt,
|
||||
},
|
||||
wnr: rt,
|
||||
}
|
||||
if !reflect.DeepEqual(expected, newRatesWithWinner(rt)) {
|
||||
t.Errorf("Expected %+v, received %+v", expected, newRatesWithWinner(rt))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user