From d3adaf16a39dd4ad48c8cbd47b9a608ea704bc2c Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 11 Jan 2021 17:32:11 +0200 Subject: [PATCH] Update integration test --- engine/model_helpers.go | 22 +- general_tests/export_it_test.go | 20 +- migrator/rateprofiles_it_test.go | 23 +- rates/librates_test.go | 393 +++++++++++++++++++++++-------- utils/decimal.go | 10 +- 5 files changed, 336 insertions(+), 132 deletions(-) diff --git a/engine/model_helpers.go b/engine/model_helpers.go index e7b8b6da6..3c2124060 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -3142,16 +3142,20 @@ func RateProfileToAPI(rp *RateProfile) (tpRp *utils.TPRateProfile, err error) { MaxCostStrategy: rp.MaxCostStrategy, Rates: make(map[string]*utils.TPRate), } - minCostF, ok := rp.MinCost.Float64() - if !ok { - return nil, fmt.Errorf("cannot convert <%+v> to float64", rp.MinCost) + if rp.MinCost != nil { + minCostF, ok := rp.MinCost.Float64() + if !ok { + return nil, fmt.Errorf("cannot convert <%+v> to float64", rp.MinCost) + } + tpRp.MinCost = minCostF } - tpRp.MinCost = minCostF - maxCostF, ok := rp.MaxCost.Float64() - if !ok { - return nil, fmt.Errorf("cannot convert <%+v> to float64", rp.MaxCost) + if rp.MaxCost != nil { + maxCostF, ok := rp.MaxCost.Float64() + if !ok { + return nil, fmt.Errorf("cannot convert <%+v> to float64", rp.MaxCost) + } + tpRp.MaxCost = maxCostF } - tpRp.MaxCost = maxCostF for key, rate := range rp.Rates { tpRp.Rates[key] = &utils.TPRate{ @@ -3405,7 +3409,7 @@ func ActionProfileToAPI(ap *ActionProfile) (tpAp *utils.TPActionProfile) { ActivationInterval: new(utils.TPActivationInterval), Weight: ap.Weight, Schedule: ap.Schedule, - Targets: make([]*utils.TPActionTarget, len(ap.Targets)), + Targets: make([]*utils.TPActionTarget, 0, len(ap.Targets)), Actions: make([]*utils.TPAPAction, len(ap.Actions)), } for i, fli := range ap.FilterIDs { diff --git a/general_tests/export_it_test.go b/general_tests/export_it_test.go index 92be69d44..f15caeaa0 100644 --- a/general_tests/export_it_test.go +++ b/general_tests/export_it_test.go @@ -365,6 +365,15 @@ func testExpVerifyRoutes(t *testing.T) { func testExpVerifyRateProfiles(t *testing.T) { var reply *engine.RateProfile + minDecimal, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } + secDecimal, err := utils.NewDecimalFromUnit("1s") + if err != nil { + t.Error(err) + } + splPrf := &engine.RateProfile{ Tenant: "cgrates.org", ID: "RT_SPECIAL_1002", @@ -373,8 +382,8 @@ func testExpVerifyRateProfiles(t *testing.T) { Weight: 10, RoundingDecimals: 4, RoundingMethod: utils.MetaRoundingUp, - MinCost: 0, - MaxCost: 0, + MinCost: utils.NewDecimal(0, 0), + MaxCost: utils.NewDecimal(0, 0), MaxCostStrategy: utils.MetaMaxCostFree, Rates: map[string]*engine.Rate{ "RT_ALWAYS": { @@ -386,9 +395,10 @@ func testExpVerifyRateProfiles(t *testing.T) { IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0 * time.Second, - RecurrentFee: 0.01, - Unit: time.Minute, - Increment: time.Second, + FixedFee: utils.NewDecimal(0, 0), + RecurrentFee: utils.NewDecimal(1, 2), + Unit: minDecimal, + Increment: secDecimal, }, }, }, diff --git a/migrator/rateprofiles_it_test.go b/migrator/rateprofiles_it_test.go index 2c3d4ec9e..ac3adbe07 100644 --- a/migrator/rateprofiles_it_test.go +++ b/migrator/rateprofiles_it_test.go @@ -25,7 +25,6 @@ import ( "path" "reflect" "testing" - "time" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -185,35 +184,21 @@ func testRatePrfITMigrateAndMove(t *testing.T) { Weight: 0, RoundingMethod: "*up", RoundingDecimals: 4, - MinCost: 0.1, - MaxCost: 0.6, - MaxCostStrategy: "*free", + + MaxCostStrategy: "*free", Rates: map[string]*engine.Rate{ "FIRST_GI": { ID: "FIRST_GI", FilterIDs: []string{"*gi:~*req.Usage:0"}, Weight: 0, - IntervalRates: []*engine.IntervalRate{ - { - RecurrentFee: 0.12, - Unit: time.Minute, - Increment: time.Minute, - }, - }, + Blocker: false, }, "SECOND_GI": { ID: "SECOND_GI", FilterIDs: []string{"*gi:~*req.Usage:1m"}, Weight: 10, - IntervalRates: []*engine.IntervalRate{ - { - RecurrentFee: 0.06, - Unit: time.Minute, - Increment: time.Second, - }, - }, - Blocker: false, + Blocker: false, }, }, } diff --git a/rates/librates_test.go b/rates/librates_test.go index 574aac1cc..9447d114b 100644 --- a/rates/librates_test.go +++ b/rates/librates_test.go @@ -3198,46 +3198,64 @@ func TestComputeRatesIntervalsEveryTwoSeconds(t *testing.T) { } } -/* func TestComputeRateSIntervalsOneHourRate(t *testing.T) { + minDecimal, err := utils.NewDecimalFromUnit("15m") + if err != nil { + t.Error(err) + } + fminDeminal, err := utils.NewDecimalFromUnit("5m") + if err != nil { + t.Error(err) + } + cDecimal, err := utils.NewDecimalFromUnit("1m30s") + if err != nil { + t.Error(err) + } rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0, RecurrentFee: utils.NewDecimal(5, 3), - Unit: 15 * time.Minute, - Increment: 15 * time.Minute, + Unit: minDecimal, + Increment: minDecimal, }, { IntervalStart: time.Hour, - RecurrentFee: 0.50, - Unit: 5 * time.Minute, - Increment: time.Minute + 30*time.Second, + RecurrentFee: utils.NewDecimal(5, 1), + Unit: fminDeminal, + Increment: cDecimal, }, }, } - + tminDeminal, err := utils.NewDecimalFromUnit("10m") + if err != nil { + t.Error(err) + } + ominDeminal, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } rt2 := &engine.Rate{ ID: "RATE2", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 15 * time.Minute, RecurrentFee: utils.NewDecimal(1, 1), - Unit: 10 * time.Minute, - Increment: time.Minute, + Unit: tminDeminal, + Increment: ominDeminal, }, { IntervalStart: 30 * time.Minute, - RecurrentFee: 0.15, - Unit: 10 * time.Minute, - Increment: time.Minute, + RecurrentFee: utils.NewDecimal(15, 2), + Unit: tminDeminal, + Increment: ominDeminal, }, { IntervalStart: 45 * time.Minute, RecurrentFee: utils.NewDecimal(2, 1), - Unit: 10 * time.Minute, - Increment: time.Minute, + Unit: tminDeminal, + Increment: ominDeminal, }, }, } @@ -3333,6 +3351,15 @@ func TestComputeRateSIntervalsOneHourRate(t *testing.T) { } func TestComputeRateSIntervalsCompressIncrements(t *testing.T) { + minDecimal, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } + tsecDecimal, err := utils.NewDecimalFromUnit("30s") + if err != nil { + t.Error(err) + } + rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ @@ -3436,14 +3463,36 @@ func TestComputeRateSIntervalsCompressIncrements(t *testing.T) { } func TestComputeRateSIntervalsStartAfterIntervalStartDifferentRates(t *testing.T) { + tsecDecimal, err := utils.NewDecimalFromUnit("30s") + if err != nil { + t.Error(err) + } + + tminDecimal, err := utils.NewDecimalFromUnit("10m") + if err != nil { + t.Error(err) + } + minDecimal, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } + secDecimal, err := utils.NewDecimalFromUnit("1s") + if err != nil { + t.Error(err) + } + tensecDecimal, err := utils.NewDecimalFromUnit("10s") + if err != nil { + t.Error(err) + } + rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0, - RecurrentFee: 0.22, + RecurrentFee: utils.NewDecimal(22, 2), Unit: minDecimal, - Increment: time.Second, + Increment: secDecimal, }, }, } @@ -3454,31 +3503,43 @@ func TestComputeRateSIntervalsStartAfterIntervalStartDifferentRates(t *testing.T { IntervalStart: 60 * time.Minute, RecurrentFee: utils.NewDecimal(2, 1), - Unit: 10 * time.Minute, - Increment: 10 * time.Second, + Unit: tminDecimal, + Increment: tensecDecimal, }, }, } + twminDecimal, err := utils.NewDecimalFromUnit("20m") + if err != nil { + t.Error(err) + } + twsecDecimal, err := utils.NewDecimalFromUnit("20s") + if err != nil { + t.Error(err) + } rt3 := &engine.Rate{ ID: "RATE3", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 120 * time.Minute, - RecurrentFee: 0.18, - Unit: 20 * time.Minute, - Increment: 20 * time.Second, + RecurrentFee: utils.NewDecimal(18, 2), + Unit: twminDecimal, + Increment: twsecDecimal, }, }, } + trminDecimal, err := utils.NewDecimalFromUnit("30m") + if err != nil { + t.Error(err) + } rt4 := &engine.Rate{ ID: "RATE4", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 180 * time.Minute, - RecurrentFee: 0.16, - Unit: 30 * time.Minute, + RecurrentFee: utils.NewDecimal(16, 2), + Unit: trminDecimal, Increment: tsecDecimal, }, }, @@ -3580,31 +3641,63 @@ func TestComputeRateSIntervalsStartAfterIntervalStartDifferentRates(t *testing.T } func TestComputeRateSIntervalsStartAfterIntervalStartSameRate(t *testing.T) { + tsecDecimal, err := utils.NewDecimalFromUnit("30s") + if err != nil { + t.Error(err) + } + minDecimal, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } + secDecimal, err := utils.NewDecimalFromUnit("1s") + if err != nil { + t.Error(err) + } + twsecDecimal, err := utils.NewDecimalFromUnit("20s") + if err != nil { + t.Error(err) + } + tssecDecimal, err := utils.NewDecimalFromUnit("10s") + if err != nil { + t.Error(err) + } + tminDecimal, err := utils.NewDecimalFromUnit("10m") + if err != nil { + t.Error(err) + } + twminDecimal, err := utils.NewDecimalFromUnit("20m") + if err != nil { + t.Error(err) + } + thminDecimal, err := utils.NewDecimalFromUnit("30m") + if err != nil { + t.Error(err) + } rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0, - RecurrentFee: 0.22, + RecurrentFee: utils.NewDecimal(22, 2), Unit: minDecimal, - Increment: time.Second, + Increment: secDecimal, }, { IntervalStart: 60 * time.Minute, RecurrentFee: utils.NewDecimal(2, 1), - Unit: 10 * time.Minute, - Increment: 10 * time.Second, + Unit: tminDecimal, + Increment: tssecDecimal, }, { IntervalStart: 120 * time.Minute, - RecurrentFee: 0.18, - Unit: 20 * time.Minute, - Increment: 20 * time.Second, + RecurrentFee: utils.NewDecimal(18, 2), + Unit: twminDecimal, + Increment: twsecDecimal, }, { IntervalStart: 180 * time.Minute, - RecurrentFee: 0.16, - Unit: 30 * time.Minute, + RecurrentFee: utils.NewDecimal(16, 2), + Unit: thminDecimal, Increment: tsecDecimal, }, }, @@ -3794,20 +3887,37 @@ func TestComputeRateSIntervalsStartAfterIntervalStartSameRate(t *testing.T) { } func TestComputeRateSIntervalsHalfDayIntervals(t *testing.T) { + twminDecimal, err := utils.NewDecimalFromUnit("30m") + if err != nil { + t.Error(err) + } + + nminDecimal, err := utils.NewDecimalFromUnit("9m") + if err != nil { + t.Error(err) + } + minDecimal, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } + secDecimal, err := utils.NewDecimalFromUnit("1s") + if err != nil { + t.Error(err) + } rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0, - RecurrentFee: 0.50, - Unit: 30 * time.Minute, - Increment: time.Minute, + RecurrentFee: utils.NewDecimal(5, 1), + Unit: twminDecimal, + Increment: minDecimal, }, { IntervalStart: 24 * time.Hour, RecurrentFee: utils.NewDecimal(1, 1), - Unit: 30 * time.Minute, - Increment: time.Second, + Unit: twminDecimal, + Increment: secDecimal, }, }, } @@ -3817,27 +3927,27 @@ func TestComputeRateSIntervalsHalfDayIntervals(t *testing.T) { IntervalRates: []*engine.IntervalRate{ { IntervalStart: 4*time.Hour + 30*time.Minute, - RecurrentFee: 0.45, - Unit: 30 * time.Minute, - Increment: 9 * time.Minute, + RecurrentFee: utils.NewDecimal(45, 2), + Unit: twminDecimal, + Increment: nminDecimal, }, { IntervalStart: 8*time.Hour + 30*time.Minute, - RecurrentFee: 0.40, - Unit: 30 * time.Minute, - Increment: 9 * time.Minute, + RecurrentFee: utils.NewDecimal(4, 1), + Unit: twminDecimal, + Increment: nminDecimal, }, { IntervalStart: 16*time.Hour + 30*time.Minute, - RecurrentFee: 0.35, - Unit: 30 * time.Minute, - Increment: 9 * time.Minute, + RecurrentFee: utils.NewDecimal(35, 2), + Unit: twminDecimal, + Increment: nminDecimal, }, { IntervalStart: 20*time.Hour + 30*time.Minute, RecurrentFee: utils.NewDecimal(3, 1), - Unit: 30 * time.Minute, - Increment: 9 * time.Minute, + Unit: twminDecimal, + Increment: nminDecimal, }, }, } @@ -3848,8 +3958,8 @@ func TestComputeRateSIntervalsHalfDayIntervals(t *testing.T) { { IntervalStart: 12 * time.Hour, RecurrentFee: utils.NewDecimal(2, 1), - Unit: 30 * time.Minute, - Increment: time.Second, + Unit: twminDecimal, + Increment: secDecimal, }, }, } @@ -3987,21 +4097,41 @@ func TestComputeRateSIntervalsHalfDayIntervals(t *testing.T) { } func TestComputeRateSIntervalsConsecutiveRates(t *testing.T) { + fminDecimal, err := utils.NewDecimalFromUnit("15m") + if err != nil { + t.Error(err) + } + eminDecimal, err := utils.NewDecimalFromUnit("11m") + if err != nil { + t.Error(err) + } + nminDecimal, err := utils.NewDecimalFromUnit("9m") + if err != nil { + t.Error(err) + } + sminDecimal, err := utils.NewDecimalFromUnit("7m") + if err != nil { + t.Error(err) + } + fvminDecimal, err := utils.NewDecimalFromUnit("5m") + if err != nil { + t.Error(err) + } rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ {}, { IntervalStart: 15 * time.Minute, - RecurrentFee: 0.50, - Unit: 15 * time.Minute, - Increment: 11 * time.Minute, + RecurrentFee: utils.NewDecimal(5, 1), + Unit: fminDecimal, + Increment: eminDecimal, }, { IntervalStart: 30 * time.Minute, - RecurrentFee: 0.40, - Unit: 15 * time.Minute, - Increment: 9 * time.Minute, + RecurrentFee: utils.NewDecimal(4, 1), + Unit: fminDecimal, + Increment: nminDecimal, }, }, } @@ -4012,14 +4142,14 @@ func TestComputeRateSIntervalsConsecutiveRates(t *testing.T) { { IntervalStart: 45 * time.Minute, RecurrentFee: utils.NewDecimal(3, 1), - Unit: 15 * time.Minute, - Increment: 7 * time.Minute, + Unit: fminDecimal, + Increment: sminDecimal, }, { IntervalStart: time.Hour, RecurrentFee: utils.NewDecimal(2, 1), - Unit: 15 * time.Minute, - Increment: 5 * time.Minute, + Unit: fminDecimal, + Increment: fvminDecimal, }, }, } @@ -4098,26 +4228,50 @@ func TestComputeRateSIntervalsConsecutiveRates(t *testing.T) { } func TestComputeRateSIntervalsRatesByMinutes(t *testing.T) { + tsecDecimal, err := utils.NewDecimalFromUnit("2s") + if err != nil { + t.Error(err) + } + secDecimal, err := utils.NewDecimalFromUnit("1s") + if err != nil { + t.Error(err) + } + tminDecimal, err := utils.NewDecimalFromUnit("2m") + if err != nil { + t.Error(err) + } + sminDecimal, err := utils.NewDecimalFromUnit("6m") + if err != nil { + t.Error(err) + } + nminDecimal, err := utils.NewDecimalFromUnit("9m") + if err != nil { + t.Error(err) + } + eminDecimal, err := utils.NewDecimalFromUnit("8m") + if err != nil { + t.Error(err) + } rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0, - RecurrentFee: 0.50, - Unit: 2 * time.Minute, - Increment: 2 * time.Second, + RecurrentFee: utils.NewDecimal(5, 1), + Unit: tminDecimal, + Increment: tsecDecimal, }, { IntervalStart: 12*time.Minute + 35*time.Second, - RecurrentFee: 0.40, - Unit: 6 * time.Minute, - Increment: time.Second, + RecurrentFee: utils.NewDecimal(4, 1), + Unit: sminDecimal, + Increment: secDecimal, }, { IntervalStart: time.Hour + 37*time.Minute + 19*time.Second, RecurrentFee: utils.NewDecimal(2, 1), - Unit: 9 * time.Minute, - Increment: 6 * time.Minute, + Unit: nminDecimal, + Increment: sminDecimal, }, }, } @@ -4129,8 +4283,8 @@ func TestComputeRateSIntervalsRatesByMinutes(t *testing.T) { { IntervalStart: 38*time.Minute + 15*time.Second, RecurrentFee: utils.NewDecimal(1, 1), - Unit: 8 * time.Minute, - Increment: time.Second, + Unit: eminDecimal, + Increment: secDecimal, }, }, } @@ -4208,14 +4362,34 @@ func TestComputeRateSIntervalsRatesByMinutes(t *testing.T) { } func TestComputeRateSIntervalsSwitchingRates2(t *testing.T) { + tsecDecimal, err := utils.NewDecimalFromUnit("2s") + if err != nil { + t.Error(err) + } + tminDecimal, err := utils.NewDecimalFromUnit("2m") + if err != nil { + t.Error(err) + } + ttminDecimal, err := utils.NewDecimalFromUnit("10m") + if err != nil { + t.Error(err) + } + fsecDecimal, err := utils.NewDecimalFromUnit("4s") + if err != nil { + t.Error(err) + } + fminDecimal, err := utils.NewDecimalFromUnit("4m") + if err != nil { + t.Error(err) + } rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0, - RecurrentFee: 0.50, - Unit: 2 * time.Minute, - Increment: 2 * time.Second, + RecurrentFee: utils.NewDecimal(5, 1), + Unit: tminDecimal, + Increment: tsecDecimal, }, }, } @@ -4226,27 +4400,27 @@ func TestComputeRateSIntervalsSwitchingRates2(t *testing.T) { IntervalRates: []*engine.IntervalRate{ { IntervalStart: 20 * time.Minute, - RecurrentFee: 0.40, - Unit: 10 * time.Minute, - Increment: 2 * time.Second, + RecurrentFee: utils.NewDecimal(4, 1), + Unit: ttminDecimal, + Increment: tsecDecimal, }, { IntervalStart: 40 * time.Minute, RecurrentFee: utils.NewDecimal(3, 1), - Unit: 10 * time.Minute, - Increment: 4 * time.Second, + Unit: ttminDecimal, + Increment: fsecDecimal, }, { IntervalStart: time.Hour, RecurrentFee: utils.NewDecimal(2, 1), - Unit: 10 * time.Minute, - Increment: 2 * time.Minute, + Unit: ttminDecimal, + Increment: tminDecimal, }, { IntervalStart: 2 * time.Hour, RecurrentFee: utils.NewDecimal(1, 1), - Unit: 10 * time.Minute, - Increment: 4 * time.Minute, + Unit: ttminDecimal, + Increment: fminDecimal, }, }, } @@ -4419,14 +4593,26 @@ func TestComputeRateSIntervalsSwitchingRates2(t *testing.T) { } func TestComputeRateSIntervalsSOneWeekCall(t *testing.T) { + minDecimal, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } + hourDecimal, err := utils.NewDecimalFromUnit("1h") + if err != nil { + t.Error(err) + } + fminDecimal, err := utils.NewDecimalFromUnit("17m") + if err != nil { + t.Error(err) + } rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0, - RecurrentFee: 0.50, - Unit: time.Hour, - Increment: 17 * time.Minute, + RecurrentFee: utils.NewDecimal(5, 1), + Unit: hourDecimal, + Increment: fminDecimal, }, }, } @@ -4437,9 +4623,9 @@ func TestComputeRateSIntervalsSOneWeekCall(t *testing.T) { IntervalRates: []*engine.IntervalRate{ { IntervalStart: 168 * time.Hour, - RecurrentFee: 0.50, + RecurrentFee: utils.NewDecimal(5, 1), Unit: minDecimal, - Increment: time.Minute, + Increment: minDecimal, }, }, } @@ -4493,20 +4679,36 @@ func TestComputeRateSIntervalsSOneWeekCall(t *testing.T) { } func TestComputeRateSIntervalsPauseBetweenRates(t *testing.T) { + minDecimal, err := utils.NewDecimalFromUnit("1m") + if err != nil { + t.Error(err) + } + secDecimal, err := utils.NewDecimalFromUnit("1s") + if err != nil { + t.Error(err) + } + fminDecimal, err := utils.NewDecimalFromUnit("5m") + if err != nil { + t.Error(err) + } + tminDecimal, err := utils.NewDecimalFromUnit("10m") + if err != nil { + t.Error(err) + } rt1 := &engine.Rate{ ID: "RATE1", IntervalRates: []*engine.IntervalRate{ { IntervalStart: 0, RecurrentFee: utils.NewDecimal(2, 1), - Unit: 5 * time.Minute, - Increment: time.Minute, + Unit: fminDecimal, + Increment: minDecimal, }, { IntervalStart: 20 * time.Minute, - RecurrentFee: 0.40, + RecurrentFee: utils.NewDecimal(4, 1), Unit: minDecimal, - Increment: time.Second, + Increment: secDecimal, }, }, } @@ -4517,14 +4719,14 @@ func TestComputeRateSIntervalsPauseBetweenRates(t *testing.T) { { IntervalStart: 50 * time.Minute, RecurrentFee: utils.NewDecimal(1, 1), - Unit: 10 * time.Minute, - Increment: time.Minute, + Unit: tminDecimal, + Increment: minDecimal, }, { IntervalStart: time.Hour, RecurrentFee: utils.NewDecimal(5, 3), - Unit: 5 * time.Minute, - Increment: time.Second, + Unit: fminDecimal, + Increment: secDecimal, }, }, } @@ -4582,4 +4784,3 @@ func TestComputeRateSIntervalsPauseBetweenRates(t *testing.T) { t.Errorf("Expected %+v, \nreceived %+v", utils.ToJSON(expOrdRts), utils.ToJSON(rcvOrdRts)) } } -*/ diff --git a/utils/decimal.go b/utils/decimal.go index 1ad7f3662..3aab97947 100644 --- a/utils/decimal.go +++ b/utils/decimal.go @@ -65,7 +65,6 @@ func NewDecimalFromFloat64(f float64) (*Decimal, error) { // NewDecimalFromUnit is a constructor for Decimal out of unit represents as string func NewDecimalFromUnit(u string) (*Decimal, error) { - d := new(decimal.Big) switch { //"ns", "us" (or "µs"), "ms", "s", "m", "h" case strings.HasSuffix(u, "ns"), strings.HasSuffix(u, "us"), strings.HasSuffix(u, "µs"), strings.HasSuffix(u, "ms"), strings.HasSuffix(u, "s"), strings.HasSuffix(u, "m"), strings.HasSuffix(u, "h"): @@ -73,10 +72,15 @@ func NewDecimalFromUnit(u string) (*Decimal, error) { if err != nil { return nil, err } - d.SetUint64(uint64(tm)) + return NewDecimal(int64(tm), 0), nil + default: + i, err := strconv.ParseInt(u, 10, 64) + if err != nil { + return nil, err + } + return NewDecimal(i, 0), nil } - return &Decimal{d}, nil } // NewDecimal is a constructor for Decimal, following the one of decimal.Big