diff --git a/apis/account_it_test.go b/apis/account_it_test.go index 68408aac3..c43e66ed3 100644 --- a/apis/account_it_test.go +++ b/apis/account_it_test.go @@ -455,8 +455,8 @@ func testAccMaxAbstracts(t *testing.T) { CostIncrements: []*utils.APICostIncrement{ { Increment: utils.Float64Pointer(float64(time.Second)), - FixedFee: utils.Float64Pointer(0), - RecurrentFee: utils.Float64Pointer(0), + FixedFee: utils.NewDecimal(int64(0, 0), + RecurrentFee: utils.NewDecimal(int64(0, 0), }, }, @@ -473,7 +473,7 @@ func testAccMaxAbstracts(t *testing.T) { t.Error(err) } - var reply3 utils.ExtEventCharges + var reply3 utils.EventCharges ev2 := &utils.CGREvent{ Tenant: utils.CGRateSorg, ID: "testIDEvent", @@ -500,15 +500,11 @@ func testAccMaxAbstracts(t *testing.T) { accKEy = key rtID = val.RatingID } - expRating := &utils.ExtRateSInterval{ - IntervalStart: nil, - Increments: []*utils.ExtRateSIncrement{ + expRating := &utils.RateSInterval{ + Increments: []*utils.RateSIncrement{ { - IncrementStart: nil, - IntervalRateIndex: 0, - RateID: "", + RateIntervalIndex: 0, CompressFactor: 1, - Usage: nil, }, }, CompressFactor: 1, @@ -520,30 +516,28 @@ func testAccMaxAbstracts(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expRating), utils.ToJSON(val)) } } - reply3.Rating = map[string]*utils.ExtRateSInterval{} - expected2 := utils.ExtEventCharges{ - Abstracts: utils.Float64Pointer(27000000000), + reply3.Rating = map[string]*utils.RateSInterval{} + expected2 := utils.EventCharges{ + Abstracts: utils.NewDecimal(int64(27*time.Second), 0), Charges: []*utils.ChargeEntry{ { ChargingID: crgID, CompressFactor: 1, }, }, - Accounting: map[string]*utils.ExtAccountCharge{ - accKEy: &utils.ExtAccountCharge{ - AccountID: "TEST_ACC_IT_TEST4", - BalanceID: "AbstractBalance1", - Units: utils.Float64Pointer(27000000000), - BalanceLimit: utils.Float64Pointer(0), - UnitFactorID: "", - RatingID: rtID, - JoinedChargeIDs: nil, + Accounting: map[string]*utils.AccountCharge{ + accKEy: &utils.AccountCharge{ + AccountID: "TEST_ACC_IT_TEST4", + BalanceID: "AbstractBalance1", + Units: utils.NewDecimal(int64(27*time.Second), 0), + BalanceLimit: utils.NewDecimal(0, 0), + RatingID: rtID, }, }, - UnitFactors: map[string]*utils.ExtUnitFactor{}, - Rating: map[string]*utils.ExtRateSInterval{}, - Rates: map[string]*utils.ExtIntervalRate{}, - Accounts: map[string]*utils.ExtAccount{ + UnitFactors: map[string]*utils.UnitFactor{}, + Rating: map[string]*utils.RateSInterval{}, + Rates: map[string]*utils.IntervalRate{}, + Accounts: map[string]*utils.Account{ "TEST_ACC_IT_TEST4": { Tenant: "cgrates.org", ID: "TEST_ACC_IT_TEST4", @@ -553,7 +547,7 @@ func testAccMaxAbstracts(t *testing.T) { Weight: 0, }, }, - Balances: map[string]*utils.ExtBalance{ + Balances: map[string]*utils.Balance{ "AbstractBalance1": { ID: "AbstractBalance1", Weights: utils.DynamicWeights{ @@ -562,14 +556,14 @@ func testAccMaxAbstracts(t *testing.T) { }, }, Type: "*abstract", - CostIncrements: []*utils.ExtCostIncrement{ + CostIncrements: []*utils.CostIncrement{ { - Increment: utils.Float64Pointer(1000000000), - FixedFee: utils.Float64Pointer(0), - RecurrentFee: utils.Float64Pointer(0), + Increment: utils.NewDecimal(int64(time.Second), 0), + FixedFee: utils.NewDecimal(0, 0), + RecurrentFee: utils.NewDecimal(0, 0), }, }, - Units: utils.Float64Pointer(13000000000), + Units: utils.NewDecimal(int64(13*time.Second), 0), }, "ConcreteBalance2": { ID: "ConcreteBalance2", @@ -580,7 +574,7 @@ func testAccMaxAbstracts(t *testing.T) { }, }, Type: "*concrete", - Units: utils.Float64Pointer(213), + Units: utils.NewDecimal(213, 0), }, }, }, @@ -630,7 +624,7 @@ func testAccDebitAbstracts(t *testing.T) { t.Error(err) } - var reply3 utils.ExtEventCharges + var reply3 utils.EventCharges ev2 := &utils.CGREvent{ Tenant: utils.CGRateSorg, ID: "testIDEvent", @@ -657,12 +651,10 @@ func testAccDebitAbstracts(t *testing.T) { accKEy = key rtID = val.RatingID } - expRating := &utils.ExtRateSInterval{ - IntervalStart: nil, - Increments: []*utils.ExtRateSIncrement{ + expRating := &utils.RateSInterval{ + Increments: []*utils.RateSIncrement{ { - IntervalRateIndex: 0, - RateID: "", + RateIntervalIndex: 0, CompressFactor: 1, }, }, @@ -675,30 +667,29 @@ func testAccDebitAbstracts(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expRating), utils.ToJSON(val)) } } - reply3.Rating = map[string]*utils.ExtRateSInterval{} - expected2 := utils.ExtEventCharges{ - Abstracts: utils.Float64Pointer(27000000000), + reply3.Rating = map[string]*utils.RateSInterval{} + expected2 := utils.EventCharges{ + Abstracts: utils.NewDecimal(int64(27*time.Second), 0), Charges: []*utils.ChargeEntry{ { ChargingID: crgID, CompressFactor: 1, }, }, - Accounting: map[string]*utils.ExtAccountCharge{ - accKEy: &utils.ExtAccountCharge{ + Accounting: map[string]*utils.AccountCharge{ + accKEy: &utils.AccountCharge{ AccountID: "TEST_ACC_IT_TEST5", BalanceID: "AbstractBalance1", - Units: utils.Float64Pointer(27000000000), - BalanceLimit: utils.Float64Pointer(0), - UnitFactorID: "", + Units: utils.NewDecimal(int64(27*time.Second), 0), + BalanceLimit: utils.NewDecimal(0, 0), RatingID: rtID, JoinedChargeIDs: nil, }, }, - UnitFactors: map[string]*utils.ExtUnitFactor{}, - Rating: map[string]*utils.ExtRateSInterval{}, - Rates: map[string]*utils.ExtIntervalRate{}, - Accounts: map[string]*utils.ExtAccount{ + UnitFactors: map[string]*utils.UnitFactor{}, + Rating: map[string]*utils.RateSInterval{}, + Rates: map[string]*utils.IntervalRate{}, + Accounts: map[string]*utils.Account{ "TEST_ACC_IT_TEST5": { Tenant: "cgrates.org", ID: "TEST_ACC_IT_TEST5", @@ -708,7 +699,7 @@ func testAccDebitAbstracts(t *testing.T) { Weight: 0, }, }, - Balances: map[string]*utils.ExtBalance{ + Balances: map[string]*utils.Balance{ "AbstractBalance1": { ID: "AbstractBalance1", Weights: utils.DynamicWeights{ @@ -717,14 +708,14 @@ func testAccDebitAbstracts(t *testing.T) { }, }, Type: "*abstract", - CostIncrements: []*utils.ExtCostIncrement{ + CostIncrements: []*utils.CostIncrement{ { - Increment: utils.Float64Pointer(1000000000), - FixedFee: utils.Float64Pointer(0), - RecurrentFee: utils.Float64Pointer(0), + Increment: utils.NewDecimal(int64(time.Second), 0), + FixedFee: utils.NewDecimal(0, 0), + RecurrentFee: utils.NewDecimal(0, 0), }, }, - Units: utils.Float64Pointer(13000000000), + Units: utils.NewDecimal(int64(13*time.Second), 0), }, "ConcreteBalance2": { ID: "ConcreteBalance2", @@ -735,7 +726,7 @@ func testAccDebitAbstracts(t *testing.T) { }, }, Type: "*concrete", - Units: utils.Float64Pointer(213), + Units: utils.NewDecimal(213, 0), }, }, }, @@ -785,7 +776,7 @@ func testAccMaxConcretes(t *testing.T) { t.Error(err) } - var reply3 utils.ExtEventCharges + var reply3 utils.EventCharges ev2 := &utils.CGREvent{ Tenant: utils.CGRateSorg, ID: "testIDEvent", @@ -812,11 +803,11 @@ func testAccMaxConcretes(t *testing.T) { accKEy = key rtID = val.RatingID } - expRating := &utils.ExtRateSInterval{ + expRating := &utils.RateSInterval{ IntervalStart: nil, - Increments: []*utils.ExtRateSIncrement{ + Increments: []*utils.RateSIncrement{ { - IntervalRateIndex: 0, + RateIntervalIndex: 0, RateID: utils.EmptyString, CompressFactor: 0, }, @@ -828,29 +819,28 @@ func testAccMaxConcretes(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expRating, val) } } - reply3.Rating = map[string]*utils.ExtRateSInterval{} - expected2 := utils.ExtEventCharges{ - Concretes: utils.Float64Pointer(213), + reply3.Rating = map[string]*utils.RateSInterval{} + expected2 := utils.EventCharges{ + Concretes: utils.NewDecimal(213, 0), Charges: []*utils.ChargeEntry{ { ChargingID: crgID, CompressFactor: 1, }, }, - Accounting: map[string]*utils.ExtAccountCharge{ - accKEy: &utils.ExtAccountCharge{ + Accounting: map[string]*utils.AccountCharge{ + accKEy: &utils.AccountCharge{ AccountID: "TEST_ACC_IT_TEST6", BalanceID: "ConcreteBalance2", - Units: utils.Float64Pointer(213), - BalanceLimit: utils.Float64Pointer(0), - UnitFactorID: "", + Units: utils.NewDecimal(213, 0), + BalanceLimit: utils.NewDecimal(0, 0), RatingID: rtID, }, }, - UnitFactors: map[string]*utils.ExtUnitFactor{}, - Rating: map[string]*utils.ExtRateSInterval{}, - Rates: map[string]*utils.ExtIntervalRate{}, - Accounts: map[string]*utils.ExtAccount{ + UnitFactors: map[string]*utils.UnitFactor{}, + Rating: map[string]*utils.RateSInterval{}, + Rates: map[string]*utils.IntervalRate{}, + Accounts: map[string]*utils.Account{ "TEST_ACC_IT_TEST6": { Tenant: "cgrates.org", ID: "TEST_ACC_IT_TEST6", @@ -860,7 +850,7 @@ func testAccMaxConcretes(t *testing.T) { Weight: 0, }, }, - Balances: map[string]*utils.ExtBalance{ + Balances: map[string]*utils.Balance{ "AbstractBalance1": { ID: "AbstractBalance1", Weights: utils.DynamicWeights{ @@ -869,14 +859,14 @@ func testAccMaxConcretes(t *testing.T) { }, }, Type: "*abstract", - CostIncrements: []*utils.ExtCostIncrement{ + CostIncrements: []*utils.CostIncrement{ { - Increment: utils.Float64Pointer(1000000000), - FixedFee: utils.Float64Pointer(0), - RecurrentFee: utils.Float64Pointer(0), + Increment: utils.NewDecimal(int64(time.Second), 0), + FixedFee: utils.NewDecimal(0, 0), + RecurrentFee: utils.NewDecimal(0, 0), }, }, - Units: utils.Float64Pointer(40000000000), + Units: utils.NewDecimal(int64(40*time.Second), 0), }, "ConcreteBalance2": { ID: "ConcreteBalance2", @@ -886,7 +876,7 @@ func testAccMaxConcretes(t *testing.T) { }, }, Type: "*concrete", - Units: utils.Float64Pointer(0), + Units: utils.NewDecimal(0, 0), }, }, }, @@ -936,7 +926,7 @@ func testAccDebitConcretes(t *testing.T) { t.Error(err) } - var reply3 utils.ExtEventCharges + var reply3 utils.EventCharges ev2 := &utils.CGREvent{ Tenant: utils.CGRateSorg, ID: "testIDEvent", @@ -963,12 +953,10 @@ func testAccDebitConcretes(t *testing.T) { accKEy = key rtID = val.RatingID } - expRating := &utils.ExtRateSInterval{ - IntervalStart: nil, - Increments: []*utils.ExtRateSIncrement{ + expRating := &utils.RateSInterval{ + Increments: []*utils.RateSIncrement{ { - IntervalRateIndex: 0, - RateID: utils.EmptyString, + RateIntervalIndex: 0, CompressFactor: 0, }, }, @@ -979,29 +967,28 @@ func testAccDebitConcretes(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expRating, val) } } - reply3.Rating = map[string]*utils.ExtRateSInterval{} - expected2 := utils.ExtEventCharges{ - Concretes: utils.Float64Pointer(213), + reply3.Rating = map[string]*utils.RateSInterval{} + expected2 := utils.EventCharges{ + Concretes: utils.NewDecimal(213, 0), Charges: []*utils.ChargeEntry{ { ChargingID: crgID, CompressFactor: 1, }, }, - Accounting: map[string]*utils.ExtAccountCharge{ - accKEy: &utils.ExtAccountCharge{ + Accounting: map[string]*utils.AccountCharge{ + accKEy: &utils.AccountCharge{ AccountID: "TEST_ACC_IT_TEST7", BalanceID: "ConcreteBalance2", - Units: utils.Float64Pointer(213), - BalanceLimit: utils.Float64Pointer(0), - UnitFactorID: "", + Units: utils.NewDecimal(213, 0), + BalanceLimit: utils.NewDecimal(0, 0), RatingID: rtID, }, }, - UnitFactors: map[string]*utils.ExtUnitFactor{}, - Rating: map[string]*utils.ExtRateSInterval{}, - Rates: map[string]*utils.ExtIntervalRate{}, - Accounts: map[string]*utils.ExtAccount{ + UnitFactors: map[string]*utils.UnitFactor{}, + Rating: map[string]*utils.RateSInterval{}, + Rates: map[string]*utils.IntervalRate{}, + Accounts: map[string]*utils.Account{ "TEST_ACC_IT_TEST7": { Tenant: "cgrates.org", ID: "TEST_ACC_IT_TEST7", @@ -1011,7 +998,7 @@ func testAccDebitConcretes(t *testing.T) { Weight: 0, }, }, - Balances: map[string]*utils.ExtBalance{ + Balances: map[string]*utils.Balance{ "AbstractBalance1": { ID: "AbstractBalance1", Weights: utils.DynamicWeights{ @@ -1020,14 +1007,14 @@ func testAccDebitConcretes(t *testing.T) { }, }, Type: "*abstract", - CostIncrements: []*utils.ExtCostIncrement{ + CostIncrements: []*utils.CostIncrement{ { - Increment: utils.Float64Pointer(1000000000), - FixedFee: utils.Float64Pointer(0), - RecurrentFee: utils.Float64Pointer(0), + Increment: utils.NewDecimal(int64(time.Second), 0), + FixedFee: utils.NewDecimal(0, 0), + RecurrentFee: utils.NewDecimal(0, 0), }, }, - Units: utils.Float64Pointer(40000000000), + Units: utils.NewDecimal(int64(40*time.Second), 0), }, "ConcreteBalance2": { ID: "ConcreteBalance2", @@ -1037,7 +1024,7 @@ func testAccDebitConcretes(t *testing.T) { }, }, Type: "*concrete", - Units: utils.Float64Pointer(0), + Units: utils.NewDecimal(0, 0), }, }, }, diff --git a/apis/account_test.go b/apis/account_test.go index c3929434a..dc9b0a496 100644 --- a/apis/account_test.go +++ b/apis/account_test.go @@ -1168,12 +1168,12 @@ func TestAccountMaxAbstracts(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err) } - expRating := &utils.ExtRateSInterval{ + expRating := &utils.RateSInterval{ IntervalStart: nil, - Increments: []*utils.ExtRateSIncrement{ + Increments: []*utils.RateSIncrement{ { IncrementStart: nil, - IntervalRateIndex: 0, + RateIntervalIndex: 0, RateID: "id_for_Test", CompressFactor: 1, Usage: nil, @@ -1355,10 +1355,10 @@ func TestAccountDebitAbstracts(t *testing.T) { } - expRating := &utils.ExtRateSInterval{ - Increments: []*utils.ExtRateSIncrement{ + expRating := &utils.RateSInterval{ + Increments: []*utils.RateSIncrement{ { - IntervalRateIndex: 0, + RateIntervalIndex: 0, RateID: "id_for_test", CompressFactor: 1, }, @@ -1538,11 +1538,11 @@ func TestAccountActionSetBalance(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err) } - expRating := &utils.ExtRateSInterval{ + expRating := &utils.RateSInterval{ IntervalStart: nil, - Increments: []*utils.ExtRateSIncrement{ + Increments: []*utils.RateSIncrement{ { - IntervalRateIndex: 0, + RateIntervalIndex: 0, RateID: "id_for_test", CompressFactor: 1, }, @@ -1650,7 +1650,6 @@ func TestAccountActionRemoveBalance(t *testing.T) { if err := accSv1.ActionRemoveBalance(context.Background(), args, &reply); err != nil { t.Errorf("Expected %+v, received %+v", nil, err) } - } func TestAccountMaxConcretes(t *testing.T) { @@ -1735,20 +1734,20 @@ func TestAccountMaxConcretes(t *testing.T) { } accPrf.Balances["AbstractBalance1"].Weights = "" - extAccPrf := &utils.ExtAccount{ + extAccPrf := &utils.Account{ Tenant: "cgrates.org", ID: "TestV1DebitAbstracts", FilterIDs: []string{"*string:~*req.Account:1004"}, - Balances: map[string]*utils.ExtBalance{ + Balances: map[string]*utils.Balance{ "AbstractBalance1": { ID: "AbstractBalance1", Type: utils.MetaAbstract, - Units: utils.Float64Pointer(float64(40 * time.Second)), - CostIncrements: []*utils.ExtCostIncrement{ + Units: utils.NewDecimal(int64(40*time.Second), 0), + CostIncrements: []*utils.CostIncrement{ { - Increment: utils.Float64Pointer(float64(time.Second)), - FixedFee: utils.Float64Pointer(float64(0)), - RecurrentFee: utils.Float64Pointer(float64(1)), + Increment: utils.NewDecimal(int64(time.Second), 0), + FixedFee: utils.NewDecimal(0, 0), + RecurrentFee: utils.NewDecimal(1, 0), }, }, }, @@ -1760,12 +1759,12 @@ func TestAccountMaxConcretes(t *testing.T) { }, }, Type: utils.MetaConcrete, - Units: utils.Float64Pointer(float64(time.Minute)), - CostIncrements: []*utils.ExtCostIncrement{ + Units: utils.NewDecimal(int64(time.Minute), 0), + CostIncrements: []*utils.CostIncrement{ { - Increment: utils.Float64Pointer(float64(time.Second)), - FixedFee: utils.Float64Pointer(float64(0)), - RecurrentFee: utils.Float64Pointer(float64(1)), + Increment: utils.NewDecimal(int64(time.Second), 0), + FixedFee: utils.NewDecimal(0, 0), + RecurrentFee: utils.NewDecimal(1, 0), }, }, }, @@ -1777,19 +1776,19 @@ func TestAccountMaxConcretes(t *testing.T) { }, }, Type: utils.MetaConcrete, - Units: utils.Float64Pointer(float64(30 * time.Second)), - CostIncrements: []*utils.ExtCostIncrement{ + Units: utils.NewDecimal(int64(30*time.Second), 0), + CostIncrements: []*utils.CostIncrement{ { - Increment: utils.Float64Pointer(float64(time.Second)), - FixedFee: utils.Float64Pointer(float64(0)), - RecurrentFee: utils.Float64Pointer(float64(1)), + Increment: utils.NewDecimal(int64(time.Second), 0), + FixedFee: utils.NewDecimal(0, 0), + RecurrentFee: utils.NewDecimal(1, 0), }, }, }, }, } - extAccPrf.Balances["ConcreteBalance1"].Units = utils.Float64Pointer(0) - extAccPrf.Balances["ConcreteBalance2"].Units = utils.Float64Pointer(0) + extAccPrf.Balances["ConcreteBalance1"].Units = utils.NewDecimal(0, 0) + extAccPrf.Balances["ConcreteBalance2"].Units = utils.NewDecimal(0, 0) exEvCh := utils.EventCharges{ Concretes: utils.NewDecimal(int64(time.Minute+30*time.Second), 0), diff --git a/apis/indexes_after_load_it_test.go b/apis/indexes_after_load_it_test.go index bec684093..9d07defc3 100644 --- a/apis/indexes_after_load_it_test.go +++ b/apis/indexes_after_load_it_test.go @@ -67,7 +67,7 @@ func TestIdxCheckAfterLoad(t *testing.T) { t.Fatal("Unknown Database type") } for _, stest := range idxLoadAccPrf { - t.Run(idxLoadConfigDIR, stest) + t.Run(idxLoadConfigDIR+"config", stest) } } @@ -122,10 +122,16 @@ func testIdxLoadTariffPlan(t *testing.T) { func testIdxLoadCheckIndexes(t *testing.T) { expected := []string{ - "*none:*any:*any:RP_ABS_BALANCE1", - "*none:*any:*any:RP_ABS_BALANCE2", - "*none:*any:*any:RP_CNCRT_BALANCE1", - "*none:*any:*any:RP_ROUTE2", + "*string:*req.RouteID:supplier1:RP_SUPPLIER1", + "*string:*req.RouteID:supplier2:RP_SUPPLIER2", + "*string:*req.RouteID:supplier3:RP_SUPPLIER3", + "*string:*req.RouteID:supplier4:RP_SUPPLIER4", + "*string:*req.RunID:balanceonly:RP_ABS_VOLUME2", + "*string:*req.RunID:customers:RP_CUSTOMER1", + "*string:*req.RunID:suppliers:RP_SUPPLIER1", + "*string:*req.RunID:suppliers:RP_SUPPLIER2", + "*string:*req.RunID:suppliers:RP_SUPPLIER3", + "*string:*req.RunID:suppliers:RP_SUPPLIER4", } //get indexes *rate_profiles var reply []string @@ -138,7 +144,7 @@ func testIdxLoadCheckIndexes(t *testing.T) { sort.Strings(expected) sort.Strings(reply) if !reflect.DeepEqual(expected, reply) && idxLoadConfigDIR != "session_volume_discount_internal" { - t.Errorf("Expected %+v, received %+v", expected, reply) + t.Errorf("Expected %+v \n, received %+v", expected, reply) } } diff --git a/dispatchers/accounts_test.go b/dispatchers/accounts_test.go index 68a63525a..f51052828 100644 --- a/dispatchers/accounts_test.go +++ b/dispatchers/accounts_test.go @@ -100,7 +100,7 @@ func TestDspMaxAbstractsNil(t *testing.T) { CGREvent := &utils.CGREvent{ Tenant: "tenant", } - var reply *utils.ExtEventCharges + var reply *utils.EventCharges result := dspSrv.MaxAbstracts(CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { @@ -115,7 +115,7 @@ func TestDspMaxAbstractsErrorNil(t *testing.T) { CGREvent := &utils.CGREvent{ Tenant: "tenant", } - var reply *utils.ExtEventCharges + var reply *utils.EventCharges result := dspSrv.MaxAbstracts(CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { @@ -129,7 +129,7 @@ func TestDspDebitAbstractsNil(t *testing.T) { CGREvent := &utils.CGREvent{ Tenant: "tenant", } - var reply *utils.ExtEventCharges + var reply *utils.EventCharges result := dspSrv.DebitAbstracts(CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { @@ -144,7 +144,7 @@ func TestDspDebitAbstractsErrorNil(t *testing.T) { CGREvent := &utils.CGREvent{ Tenant: "tenant", } - var reply *utils.ExtEventCharges + var reply *utils.EventCharges result := dspSrv.DebitAbstracts(CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { @@ -158,7 +158,7 @@ func TestDspMaxConcretesNil(t *testing.T) { CGREvent := &utils.CGREvent{ Tenant: "tenant", } - var reply *utils.ExtEventCharges + var reply *utils.EventCharges result := dspSrv.MaxConcretes(CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { @@ -173,7 +173,7 @@ func TestDspMaxConcretesErrorNil(t *testing.T) { CGREvent := &utils.CGREvent{ Tenant: "tenant", } - var reply *utils.ExtEventCharges + var reply *utils.EventCharges result := dspSrv.MaxConcretes(CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { @@ -187,7 +187,7 @@ func TestDspDebitConcretesNil(t *testing.T) { CGREvent := &utils.CGREvent{ Tenant: "tenant", } - var reply *utils.ExtEventCharges + var reply *utils.EventCharges result := dspSrv.DebitConcretes(CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { @@ -202,7 +202,7 @@ func TestDspDebitConcretesErrorNil(t *testing.T) { CGREvent := &utils.CGREvent{ Tenant: "tenant", } - var reply *utils.ExtEventCharges + var reply *utils.EventCharges result := dspSrv.DebitConcretes(CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { diff --git a/utils/account_test.go b/utils/account_test.go index b3f11f468..6acbe8b55 100644 --- a/utils/account_test.go +++ b/utils/account_test.go @@ -19,7 +19,6 @@ along with this program. If not, see package utils import ( - "math" "reflect" "testing" "time" @@ -672,555 +671,6 @@ func TestEqualsUnitFactor(t *testing.T) { } } -func TestAsExtUnitFactor(t *testing.T) { - uF := &UnitFactor{ - FilterIDs: []string{"test1"}, - Factor: NewDecimal(123, 2), - } - expUf := &ExtUnitFactor{ - FilterIDs: []string{"test1"}, - Factor: Float64Pointer(1.23), - } - if rcv, err := uF.AsExtUnitFactor(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(rcv, expUf) { - t.Errorf("Expected %+v, received %+v", ToJSON(expUf), ToJSON(rcv)) - } - - uF = &UnitFactor{ - FilterIDs: []string{}, - } - expUf = &ExtUnitFactor{ - FilterIDs: []string{}, - } - if rcv, err := uF.AsExtUnitFactor(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(rcv, expUf) { - t.Errorf("Expected %+v, received %+v", ToJSON(expUf), ToJSON(rcv)) - } - - uF.Factor = NewDecimal(int64(math.Inf(1))-1, 0) - expErr := "cannot convert decimal Factor to float64 " - if _, err := uF.AsExtUnitFactor(); err == nil || err.Error() != expErr { - t.Errorf("Expected %+v, received %+v", expErr, err) - } -} - -func TestAsExtAccount(t *testing.T) { - acc := &Account{ - Tenant: "tcgrates.org", - ID: "TestAsExtAccount", - FilterIDs: []string{"fltr1", "fltr2", "*ai:~*req.AnswerTime:2021-12-12T00:00:00Z|2021-05-12T10:00:00Z"}, - Weights: DynamicWeights{ - { - FilterIDs: []string{}, - Weight: 20.5, - }, - }, - Opts: map[string]interface{}{ - Usage: time.Minute, - }, - Balances: map[string]*Balance{ - "BL1": { - ID: "BL1", - FilterIDs: []string{"fltr3"}, - Weights: DynamicWeights{ - { - FilterIDs: []string{}, - Weight: 1.5, - }, - }, - Type: MetaAbstract, - Units: &Decimal{decimal.New(300, 2)}, - UnitFactors: []*UnitFactor{ - { - FilterIDs: []string{"uf_fltr1"}, - Factor: NewDecimal(13, 4), - }, - }, - Opts: map[string]interface{}{ - RequestType: Prepaid, - }, - CostIncrements: []*CostIncrement{ - { - FilterIDs: []string{}, - FixedFee: NewDecimal(int64(time.Minute), 0), - Increment: NewDecimal(int64(time.Minute), 0), - RecurrentFee: NewDecimal(0, 0), - }, - }, - AttributeIDs: []string{}, - RateProfileIDs: []string{"RT1"}, - }, - }, - ThresholdIDs: []string{"THRESHOLD1", "THRESHOLD2"}, - } - - expAcc := &ExtAccount{ - Tenant: "tcgrates.org", - ID: "TestAsExtAccount", - FilterIDs: []string{"fltr1", "fltr2", "*ai:~*req.AnswerTime:2021-12-12T00:00:00Z|2021-05-12T10:00:00Z"}, - Weights: DynamicWeights{ - { - FilterIDs: []string{}, - Weight: 20.5, - }, - }, - Opts: map[string]interface{}{ - Usage: time.Minute, - }, - Balances: map[string]*ExtBalance{ - "BL1": { - ID: "BL1", - FilterIDs: []string{"fltr3"}, - Weights: DynamicWeights{ - { - FilterIDs: []string{}, - Weight: 1.5, - }, - }, - Type: MetaAbstract, - Units: Float64Pointer(3.00), - UnitFactors: []*ExtUnitFactor{ - { - FilterIDs: []string{"uf_fltr1"}, - Factor: Float64Pointer(0.0013), - }, - }, - Opts: map[string]interface{}{ - RequestType: Prepaid, - }, - CostIncrements: []*ExtCostIncrement{ - { - FilterIDs: []string{}, - FixedFee: Float64Pointer(float64(time.Minute)), - Increment: Float64Pointer(float64(time.Minute)), - RecurrentFee: Float64Pointer(0), - }, - }, - AttributeIDs: []string{}, - RateProfileIDs: []string{"RT1"}, - }, - }, - ThresholdIDs: []string{"THRESHOLD1", "THRESHOLD2"}, - } - - if rcv, err := acc.AsExtAccount(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(rcv, expAcc) { - t.Errorf("Expected %+v, received %+v", ToJSON(expAcc), ToJSON(rcv)) - } -} - -func TestAsExtAccountCheckErrors(t *testing.T) { - acc := &Account{ - Tenant: "tcgrates.org", - ID: "TestAsExtAccount", - FilterIDs: []string{"fltr1", "fltr2", "*ai:~*req.AnswerTime:2021-12-12T00:00:00Z|2021-05-12T10:00:00Z"}, - Weights: DynamicWeights{ - { - FilterIDs: []string{}, - Weight: 20.5, - }, - }, - Opts: map[string]interface{}{ - Usage: time.Minute, - }, - Balances: map[string]*Balance{ - "BL1": { - ID: "BL1", - FilterIDs: []string{"fltr3"}, - Weights: DynamicWeights{ - { - FilterIDs: []string{}, - Weight: 1.5, - }, - }, - Type: MetaAbstract, - Units: NewDecimal(int64(math.Inf(1))-1, 0), - UnitFactors: []*UnitFactor{ - { - FilterIDs: []string{"uf_fltr1"}, - Factor: NewDecimal(13, 4), - }, - }, - Opts: map[string]interface{}{ - RequestType: Prepaid, - }, - CostIncrements: []*CostIncrement{ - { - FilterIDs: []string{}, - FixedFee: NewDecimal(int64(time.Minute), 0), - Increment: NewDecimal(int64(time.Minute), 0), - RecurrentFee: NewDecimal(0, 0), - }, - }, - AttributeIDs: []string{}, - RateProfileIDs: []string{"RT1"}, - }, - }, - ThresholdIDs: []string{}, - } - - acc.Balances["BL1"].CostIncrements[0].FixedFee = NewDecimal(int64(math.Inf(1))-1, 0) - expected := "cannot convert decimal FixedFee to float64 " - if _, err := acc.AsExtAccount(); err == nil || err.Error() != expected { - t.Errorf("Expected %+q, received %+q", expected, err) - } - acc.Balances["BL1"].CostIncrements[0].FixedFee = NewDecimal(0, 0) - - acc.Balances["BL1"].CostIncrements[0].Increment = NewDecimal(int64(math.Inf(1))-1, 0) - expected = "cannot convert decimal Increment to float64 " - if _, err := acc.AsExtAccount(); err == nil || err.Error() != expected { - t.Errorf("Expected %+q, received %+q", expected, err) - } - acc.Balances["BL1"].CostIncrements[0].Increment = NewDecimal(0, 0) - - acc.Balances["BL1"].CostIncrements[0].RecurrentFee = NewDecimal(int64(math.Inf(1))-1, 0) - expected = "cannot convert decimal RecurrentFee to float64 " - if _, err := acc.AsExtAccount(); err == nil || err.Error() != expected { - t.Errorf("Expected %+q, received %+q", expected, err) - } - acc.Balances["BL1"].CostIncrements[0].RecurrentFee = NewDecimal(0, 0) - - acc.Balances["BL1"].UnitFactors[0].Factor = NewDecimal(int64(math.Inf(1))-1, 0) - expected = "cannot convert decimal Factor to float64 " - if _, err := acc.AsExtAccount(); err == nil || err.Error() != expected { - t.Errorf("Expected %+q, received %+q", expected, err) - } - acc.Balances["BL1"].UnitFactors[0].Factor = NewDecimal(0, 0) -} - -func TestExtAccountEqualsCase1(t *testing.T) { - eAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - } - - extAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "49f2ba", - } - - if rcv := eAc.Equals(extAc); rcv { - t.Error("Accounts should not match") - } -} - -func TestExtAccountEqualsCase2(t *testing.T) { - eAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - FilterIDs: []string{"*string:*req.Account:1001"}, - } - - extAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - FilterIDs: []string{"*string:*req.Account:1003"}, - } - - if rcv := eAc.Equals(extAc); rcv { - t.Error("Filters should not match") - } -} - -func TestExtAccountEqualsCase3(t *testing.T) { - eAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - Weights: DynamicWeights{ - { - FilterIDs: []string{"*string:*req.Account:1003"}, - Weight: 20, - }, - }, - } - - extAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - Weights: DynamicWeights{ - { - FilterIDs: []string{"*string:*req.Account:1003"}, - Weight: 10, - }, - }, - } - - if rcv := eAc.Equals(extAc); rcv { - t.Error("Weights should not match") - } -} - -func TestExtAccountEqualsCase4(t *testing.T) { - eAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - Opts: map[string]interface{}{ - "Opt1": "*opt", - }, - } - - extAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - Opts: map[string]interface{}{ - "Opt1": "*opt2", - }, - } - - if eAc.Equals(extAc) { - t.Error("Opts should not match") - } -} - -func TestExtAccountEqualsCase5(t *testing.T) { - eAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - Balances: map[string]*ExtBalance{ - "*monetary": { - ID: "b24d37", - FilterIDs: []string{}, - Weights: DynamicWeights{ - { - FilterIDs: []string{"*string:*req.Account:1001"}, - Weight: 10, - }, - }, - Type: "*monetary", - Units: Float64Pointer(3.14), - UnitFactors: []*ExtUnitFactor{ - { - FilterIDs: []string{}, - Factor: Float64Pointer(2.1), - }, - }, - Opts: map[string]interface{}{}, - CostIncrements: []*ExtCostIncrement{}, - AttributeIDs: []string{MetaNone}, - RateProfileIDs: []string{MetaNone}, - }, - }, - } - - extAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - Balances: map[string]*ExtBalance{ - "*monetary": { - ID: "b24d37", - FilterIDs: []string{}, - Weights: DynamicWeights{ - { - FilterIDs: []string{"*string:*req.Account:1003"}, - Weight: 10, - }, - }, - Type: "*monetary", - Units: Float64Pointer(3.14), - UnitFactors: []*ExtUnitFactor{ - { - FilterIDs: []string{}, - Factor: Float64Pointer(2.1), - }, - }, - Opts: map[string]interface{}{}, - CostIncrements: []*ExtCostIncrement{}, - AttributeIDs: []string{MetaNone}, - RateProfileIDs: []string{MetaNone}, - }, - }, - } - - if rcv := eAc.Equals(extAc); rcv { - t.Error("Balances should not match") - } -} - -func TestExtAccountEqualsCase6(t *testing.T) { - eAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - ThresholdIDs: []string{"ACNT_THSD_1003"}, - } - - extAc := &ExtAccount{ - Tenant: "cgrates.org", - ID: "f43a2c", - ThresholdIDs: []string{"ACNT_THSD_1001"}, - } - - if rcv := eAc.Equals(extAc); rcv { - t.Error("Thresholds should not match") - } -} - -func TestExtBalanceEqualsCase1(t *testing.T) { - eBL := &ExtBalance{ - ID: "2f5ba2", - } - - extBl := &ExtBalance{ - ID: "68d1c5", - } - - if rcv := eBL.Equals(extBl); rcv { - t.Error("Balances should not match") - } -} - -func TestExtBalanceEqualsCase2(t *testing.T) { - eBL := &ExtBalance{ - ID: "2f5ba2", - Weights: DynamicWeights{ - { - FilterIDs: []string{"*string:*req.Account:1003"}, - Weight: 10, - }, - }, - } - - extBl := &ExtBalance{ - ID: "2f5ba2", - Weights: DynamicWeights{ - { - FilterIDs: []string{"*string:*req.Account:1003"}, - Weight: 20, - }, - }, - } - - if rcv := eBL.Equals(extBl); rcv { - t.Error("Balances should not match") - } -} - -func TestExtBalanceEqualsCase3(t *testing.T) { - eBL := &ExtBalance{ - ID: "2f5ba2", - FilterIDs: []string{"*string:*req.Account:1001"}, - } - - extBl := &ExtBalance{ - ID: "2f5ba2", - FilterIDs: []string{"*string:*req.Account:1002"}, - } - - if rcv := eBL.Equals(extBl); rcv { - t.Error("Filters should not match") - } -} - -func TestExtBalanceEqualsCase4(t *testing.T) { - eBL := &ExtBalance{ - ID: "2f5ba2", - UnitFactors: []*ExtUnitFactor{ - { - FilterIDs: []string{"*string:*req.Account:1001"}, - Factor: Float64Pointer(21.7), - }, - }, - } - - extBl := &ExtBalance{ - ID: "2f5ba2", - UnitFactors: []*ExtUnitFactor{ - { - FilterIDs: []string{"*string:*req.Account:1002"}, - Factor: Float64Pointer(4.20), - }, - }, - } - - if rcv := eBL.Equals(extBl); rcv { - t.Error("UnitFactors should not match") - } -} - -func TestExtBalanceEqualsCase5(t *testing.T) { - eBL := &ExtBalance{ - ID: "2f5ba2", - Opts: map[string]interface{}{ - "Opt1": "*opt", - }, - } - - extBl := &ExtBalance{ - ID: "2f5ba2", - Opts: map[string]interface{}{ - "Opt1": "*opt2", - }, - } - - if rcv := eBL.Equals(extBl); rcv { - t.Error("Opts should not match") - } -} - -func TestExtBalanceEqualsCase6(t *testing.T) { - eBL := &ExtBalance{ - ID: "2f5ba2", - CostIncrements: []*ExtCostIncrement{ - { - FilterIDs: []string{}, - Increment: Float64Pointer(0.2), - FixedFee: Float64Pointer(0.4), - RecurrentFee: Float64Pointer(1.2), - }, - }, - } - - extBl := &ExtBalance{ - ID: "2f5ba2", - CostIncrements: []*ExtCostIncrement{ - { - FilterIDs: []string{}, - Increment: Float64Pointer(0.3), - FixedFee: Float64Pointer(0.4), - RecurrentFee: Float64Pointer(1.2), - }, - }, - } - - if rcv := eBL.Equals(extBl); rcv { - t.Error("CostIncrements should not match") - } -} - -func TestExtBalanceEqualsCase7(t *testing.T) { - eBL := &ExtBalance{ - ID: "2f5ba2", - AttributeIDs: []string{"ATTR_ID_1001"}, - } - - extBl := &ExtBalance{ - ID: "2f5ba2", - AttributeIDs: []string{"ATTR_ID_1003"}, - } - - if rcv := eBL.Equals(extBl); rcv { - t.Error("Attributes should not match") - } -} - -func TestExtBalanceEqualsCase8(t *testing.T) { - eBL := &ExtBalance{ - ID: "2f5ba2", - RateProfileIDs: []string{"RP_1001"}, - } - - extBl := &ExtBalance{ - ID: "2f5ba2", - RateProfileIDs: []string{"RP_1002"}, - } - - if rcv := eBL.Equals(extBl); rcv { - t.Error("RateProfiles should not match") - } -} - func TestBalanceEqualsCase1(t *testing.T) { eBL := &Balance{ ID: "2f5ba2", @@ -1399,46 +849,6 @@ func TestBalanceEqualsCase8(t *testing.T) { } } -func TestExtCostIncrementCase1(t *testing.T) { - eCi := &ExtCostIncrement{ - FilterIDs: []string{}, - Increment: Float64Pointer(0.2), - FixedFee: Float64Pointer(0.4), - RecurrentFee: Float64Pointer(1.2), - } - - extCi := &ExtCostIncrement{ - FilterIDs: []string{"*string:*req.Account:1002"}, - Increment: Float64Pointer(0.2), - FixedFee: Float64Pointer(0.4), - RecurrentFee: Float64Pointer(1.2), - } - - if rcv := eCi.Equals(extCi); rcv { - t.Error("RateProfiles should not match") - } -} - -func TestExtCostIncrementCase2(t *testing.T) { - eCi := &ExtCostIncrement{ - FilterIDs: []string{"*string:*req.Account:1001"}, - Increment: Float64Pointer(0.2), - FixedFee: Float64Pointer(0.4), - RecurrentFee: Float64Pointer(1.2), - } - - extCi := &ExtCostIncrement{ - FilterIDs: []string{"*string:*req.Account:1002"}, - Increment: Float64Pointer(0.2), - FixedFee: Float64Pointer(0.4), - RecurrentFee: Float64Pointer(1.2), - } - - if rcv := eCi.Equals(extCi); rcv { - t.Error("RateProfiles should not match") - } -} - func TestCostIncrementCase1(t *testing.T) { eCi := &CostIncrement{ FilterIDs: []string{}, @@ -1479,38 +889,6 @@ func TestCostIncrementCase2(t *testing.T) { } } -func TestExtUnitFactorCase1(t *testing.T) { - eUf := &ExtUnitFactor{ - FilterIDs: []string{}, - Factor: Float64Pointer(2.1), - } - - extUf := &ExtUnitFactor{ - FilterIDs: []string{"*string:*req.Account:1002"}, - Factor: Float64Pointer(2.1), - } - - if rcv := eUf.Equals(extUf); rcv { - t.Error("RateProfiles should not match") - } -} - -func TestExtUnitFactorCase2(t *testing.T) { - eUf := &ExtUnitFactor{ - FilterIDs: []string{"*string:*req.Account:1001"}, - Factor: Float64Pointer(2.1), - } - - extUf := &ExtUnitFactor{ - FilterIDs: []string{"*string:*req.Account:1002"}, - Factor: Float64Pointer(2.1), - } - - if rcv := eUf.Equals(extUf); rcv { - t.Error("RateProfiles should not match") - } -} - func TestAccountEqualsCase1(t *testing.T) { eAc := &Account{ Tenant: "cgrates.org", diff --git a/utils/eventcharges_test.go b/utils/eventcharges_test.go index f65f132e1..c3692b491 100644 --- a/utils/eventcharges_test.go +++ b/utils/eventcharges_test.go @@ -20,7 +20,6 @@ package utils import ( "fmt" - "math" "reflect" "testing" "time" @@ -93,147 +92,6 @@ func TestECMergeAbstracts(t *testing.T) { } } -func TestECAsExtEventChargesEmpty(t *testing.T) { - ec := &EventCharges{ - Abstracts: nil, - Concretes: nil, - } - - expected := &ExtEventCharges{ - Abstracts: nil, - Concretes: nil, - } - received, err := ec.AsExtEventCharges() - if err != nil { - t.Error(err) - } - - if !reflect.DeepEqual(received, expected) { - t.Errorf("\nExpected: <%+v>, \nReceived: <%+v>", expected, received) - } - -} - -func TestECAsExtEventChargesSuccess(t *testing.T) { - ec := &EventCharges{ - Abstracts: &Decimal{ - decimal.New(1234, 3), - }, - Concretes: &Decimal{ - decimal.New(4321, 5), - }, - } - - expected := &ExtEventCharges{ - Abstracts: Float64Pointer(1.234), - Concretes: Float64Pointer(0.04321), - } - received, err := ec.AsExtEventCharges() - if err != nil { - t.Errorf("\nExpected: %v,\nReceived: %v", nil, err) - } - - if !reflect.DeepEqual(received, expected) { - t.Errorf( - "\nExpected: <%v>,\nReceived: <%v>", - ToJSON(expected), - ToJSON(received), - ) - } -} - -func TestAsExtAccountCharge(t *testing.T) { - ac := &AccountCharge{ - AccountID: "ACCID_1", - BalanceID: "BALID_1", - Units: NewDecimal(123, 4), - BalanceLimit: NewDecimal(10, 1), - UnitFactorID: "seven", - AttributeIDs: []string{"TEST_ID1", "TEST_ID2"}, - RatingID: "RTID_1", - JoinedChargeIDs: []string{"TEST_ID2", "TEST_ID2"}, - } - expAcc := &ExtAccountCharge{ - AccountID: "ACCID_1", - BalanceID: "BALID_1", - Units: Float64Pointer(0.0123), - BalanceLimit: Float64Pointer(1.0), - UnitFactorID: "seven", - AttributeIDs: []string{"TEST_ID1", "TEST_ID2"}, - RatingID: "RTID_1", - JoinedChargeIDs: []string{"TEST_ID2", "TEST_ID2"}, - } - if rcv, err := ac.AsExtAccountCharge(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(rcv, expAcc) { - t.Errorf("Expected %+v, received %+v", ToJSON(expAcc), ToJSON(rcv)) - } - - ac = &AccountCharge{ - AccountID: "ACCID_1", - BalanceID: "BALID_1", - Units: NewDecimal(123, 4), - UnitFactorID: "seven", - JoinedChargeIDs: []string{}, - } - expAcc = &ExtAccountCharge{ - AccountID: "ACCID_1", - BalanceID: "BALID_1", - Units: Float64Pointer(0.0123), - UnitFactorID: "seven", - JoinedChargeIDs: []string{}, - } - if rcv, err := ac.AsExtAccountCharge(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(rcv, expAcc) { - t.Errorf("Expected %+v, received %+v", ToJSON(expAcc), ToJSON(rcv)) - } - - ac.BalanceLimit = NewDecimal(int64(math.Inf(1))-1, 0) - expErr := "cannot convert decimal BalanceLimit to float64 " - if _, err := ac.AsExtAccountCharge(); err == nil || err.Error() != expErr { - t.Errorf("Expected %+v, received %+v", expErr, err) - } - - ac.Units = NewDecimal(int64(math.Inf(1))-1, 0) - expErr = "cannot convert decimal Units to float64 " - if _, err := ac.AsExtAccountCharge(); err == nil || err.Error() != expErr { - t.Errorf("Expected %+v, received %+v", expErr, err) - } -} - -func TestECAsExtEventChargesErrConvertAbstracts(t *testing.T) { - v, _ := new(decimal.Big).SetString("900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993") - - ec := &EventCharges{ - Abstracts: &Decimal{v}, - Concretes: &Decimal{decimal.New(1234, 3)}, - } - - expected := "cannot convert decimal Abstracts to float64" - _, err := ec.AsExtEventCharges() - - if err == nil || err.Error() != expected { - t.Errorf("\nExpected: %v,\nReceived: %v", expected, err) - } -} - -func TestECAsExtEventChargesErrConvertConcretes(t *testing.T) { - v, _ := new(decimal.Big).SetString("900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993900719925474099390071992547409939007199254740993") - - ec := &EventCharges{ - Abstracts: &Decimal{decimal.New(1234, 3)}, - Concretes: &Decimal{v}, - } - - expected := "cannot convert decimal Concretes to float64" - _, err := ec.AsExtEventCharges() - - if err == nil || err.Error() != expected { - t.Errorf("\nExpected: %v,\nReceived: %v", expected, err) - } -} - /* func TestEqualsAccountCharge(t *testing.T) { accCharge1 := &AccountCharge{ @@ -352,241 +210,6 @@ func TestEqualsAccountCharge(t *testing.T) { } } */ -/* -func TestCompressEqualsChargingInterval(t *testing.T) { - chIn1 := &ChargingInterval{ - Increments: []*ChargingIncrement{ - { - Units: NewDecimal(10, 0), - AccountChargeID: "CHARGER1", - CompressFactor: 1, - }, - }, - CompressFactor: 2, - } - chIn2 := &ChargingInterval{ - Increments: []*ChargingIncrement{ - { - Units: NewDecimal(10, 0), - AccountChargeID: "CHARGER1", - CompressFactor: 1, - }, - }, - CompressFactor: 4, - } - - // compressEquals is not looking for compress factor - if !chIn1.CompressEquals(chIn2) { - t.Errorf("Intervals %+v and %+v are not equal", ToJSON(chIn1), ToJSON(chIn2)) - } - - //same thing in ChargingIncrements - chIn1.Increments[0].CompressFactor = 2 - if !chIn1.CompressEquals(chIn2) { - t.Errorf("Intervals %+v and %+v are not equal", ToJSON(chIn1), ToJSON(chIn2)) - } - - //not equals for AccountChargeID - chIn1.Increments[0].AccountChargeID = "Changed_Charger" - if chIn1.CompressEquals(chIn2) { - t.Errorf("Intervals %+v and %+v are equal", ToJSON(chIn1), ToJSON(chIn2)) - } - chIn1.Increments[0].AccountChargeID = "CHARGER1" - - chIn2.Increments[0].AccountChargeID = "Changed_Charger" - if chIn1.CompressEquals(chIn2) { - t.Errorf("Intervals %+v and %+v are equal", ToJSON(chIn1), ToJSON(chIn2)) - } - chIn2.Increments[0].AccountChargeID = "CHARGER1" - - //not equals for Units - chIn1.Increments[0].Units = NewDecimal(30, 0) - if chIn1.CompressEquals(chIn2) { - t.Errorf("Intervals %+v and %+v are equal", ToJSON(chIn1), ToJSON(chIn2)) - } - chIn1.Increments[0].Units = NewDecimal(10, 0) - - chIn2.Increments[0].Units = NewDecimal(30, 0) - if chIn1.CompressEquals(chIn2) { - t.Errorf("Intervals %+v and %+v are equal", ToJSON(chIn1), ToJSON(chIn2)) - } - chIn2.Increments[0].Units = NewDecimal(10, 0) - - //not equals by the length of increments - chIn1 = &ChargingInterval{ - Increments: []*ChargingIncrement{ - { - Units: NewDecimal(10, 0), - AccountChargeID: "CHARGER1", - CompressFactor: 1, - }, - { - Units: NewDecimal(12, 0), - AccountChargeID: "CHARGER2", - CompressFactor: 6, - }, - }, - CompressFactor: 0, - } - if chIn1.CompressEquals(chIn2) { - t.Errorf("Intervals %+v and %+v are equal", ToJSON(chIn1), ToJSON(chIn2)) - } -} -*/ -/* -func TestAsExtEventCharges(t *testing.T) { - evCh := &EventCharges{ - ChargingIntervals: []*ChargingInterval{ - { - Increments: []*ChargingIncrement{ - { - Units: NewDecimal(1, 0), - }, - }, - CompressFactor: 2, - }, - }, - Accounts: []*Account{ - { - Balances: map[string]*Balance{ - "BL1": { - Units: NewDecimal(300, 0), - }, - }, - }, - }, - Accounting: map[string]*AccountCharge{ - "first_accounting": { - BalanceLimit: NewDecimal(2, 0), - }, - }, - UnitFactors: map[string]*UnitFactor{ - "first_factor": { - Factor: NewDecimal(10, 0), - }, - }, - Rating: map[string]*RateSInterval{ - "first_rates_interval": { - IntervalStart: NewDecimal(int64(time.Minute), 0), - }, - }, - } - - expEvCh := &ExtEventCharges{ - ChargingIntervals: []*ExtChargingInterval{ - { - Increments: []*ExtChargingIncrement{ - { - Units: Float64Pointer(1.0), - }, - }, - CompressFactor: 2, - }, - }, - Accounts: []*ExtAccount{ - { - Balances: map[string]*ExtBalance{ - "BL1": { - Units: Float64Pointer(300), - }, - }, - }, - }, - Accounting: map[string]*ExtAccountCharge{ - "first_accounting": { - BalanceLimit: Float64Pointer(2), - }, - }, - UnitFactors: map[string]*ExtUnitFactor{ - "first_factor": { - Factor: Float64Pointer(10), - }, - }, - Rating: map[string]*ExtRateSInterval{ - "first_rates_interval": { - IntervalStart: Float64Pointer(float64(time.Minute)), - }, - }, - } - if rcv, err := evCh.AsExtEventCharges(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(rcv, expEvCh) { - t.Errorf("Expected %+v, received %+v", ToJSON(expEvCh), ToJSON(rcv)) - } -} - -func TestAsExtEventChargersCheckErrors(t *testing.T) { - evCh := &EventCharges{ - ChargingIntervals: []*ChargingInterval{ - { - Increments: []*ChargingIncrement{ - { - Units: NewDecimal(int64(math.Inf(1))-1, 0), - }, - }, - CompressFactor: 2, - }, - }, - Accounts: []*Account{ - { - Balances: map[string]*Balance{ - "BL1": { - Units: NewDecimal(300, 0), - }, - }, - }, - }, - Accounting: map[string]*AccountCharge{ - "first_accounting": { - BalanceLimit: NewDecimal(2, 0), - }, - }, - UnitFactors: map[string]*UnitFactor{ - "first_factor": { - Factor: NewDecimal(10, 0), - }, - }, - Rating: map[string]*RateSInterval{ - "first_rates_interval": { - IntervalStart: NewDecimal(int64(time.Minute), 0), - }, - }, - } - expected := "Cannot convert decimal ChargingIncrement into float64 " - if _, err := evCh.AsExtEventCharges(); err == nil || err.Error() != expected { - t.Errorf("Expected %+v, received %+v", expected, err) - } - evCh.ChargingIntervals[0].Increments[0].Units = NewDecimal(0, 0) - - evCh.Accounts[0].Balances["BL1"].Units = NewDecimal(int64(math.Inf(1))-1, 0) - expected = "cannot convert decimal Units to float64 " - if _, err := evCh.AsExtEventCharges(); err == nil || err.Error() != expected { - t.Errorf("Expected %+v, received %+v", expected, err) - } - evCh.Accounts[0].Balances["BL1"].Units = NewDecimal(0, 0) - - evCh.Accounting["first_accounting"].BalanceLimit = NewDecimal(int64(math.Inf(1))-1, 0) - expected = "cannot convert decimal BalanceLimit to float64 " - if _, err := evCh.AsExtEventCharges(); err == nil || err.Error() != expected { - t.Errorf("Expected %+v, received %+v", expected, err) - } - evCh.Accounting["first_accounting"].BalanceLimit = NewDecimal(0, 0) - - evCh.UnitFactors["first_factor"].Factor = NewDecimal(int64(math.Inf(1))-1, 0) - expected = "cannot convert decimal Factor to float64 " - if _, err := evCh.AsExtEventCharges(); err == nil || err.Error() != expected { - t.Errorf("Expected %+v, received %+v", expected, err) - } - evCh.UnitFactors["first_factor"].Factor = NewDecimal(0, 0) - - evCh.Rating["first_rates_interval"].IntervalStart = NewDecimal(int64(math.Inf(1))-1, 0) - expected = "Cannot convert decimal IntervalStart into float64 " - if _, err := evCh.AsExtEventCharges(); err == nil || err.Error() != expected { - t.Errorf("Expected %+q, received %+q", expected, err) - } - evCh.Rating["first_rates_interval"].IntervalStart = NewDecimal(0, 0) -} -*/ func TestEventChargesEquals(t *testing.T) { eEvChgs := &EventCharges{ @@ -971,381 +594,6 @@ func TestEventChargesEquals(t *testing.T) { t.Errorf("Expected %+v, received %+v", ToJSON(eEvChgs), ToJSON(expectedEqual)) } } - -func TestEqualsExtEventCharges(t *testing.T) { - eEvChgs := &EventCharges{ - Abstracts: NewDecimal(47500, 3), - Concretes: NewDecimal(515, 2), - Charges: []*ChargeEntry{ - { - ChargingID: "GENUUID1", - CompressFactor: 1, - }, - { - ChargingID: "GENUUID2", - CompressFactor: 1, - }, - }, - Accounting: map[string]*AccountCharge{ - "THIS_GENUUID1": { - AccountID: "TestEventChargesEquals", - BalanceID: "CONCRETE1", - Units: NewDecimal(8, 1), - BalanceLimit: NewDecimal(200, 0), - UnitFactorID: "GENUUID_FACTOR1", - }, - "GENUUID1": { - AccountID: "TestEventChargesEquals", - BalanceID: "ABSTRACT2", - BalanceLimit: NewDecimal(0, 0), - RatingID: "GENUUID_RATING1", - JoinedChargeIDs: []string{"THIS_GENUUID1"}, - }, - "GENUUID2": { - AccountID: "TestEventChargesEquals", - BalanceID: "CONCRETE1", - Units: NewDecimal(2, 0), - BalanceLimit: NewDecimal(200, 0), - UnitFactorID: "GENUUID_FACTOR2", - RatingID: "ID_FOR_RATING", - AttributeIDs: []string{"ATTR1", "ATTR2"}, - }, - }, - UnitFactors: map[string]*UnitFactor{ - "GENUUID_FACTOR1": { - Factor: NewDecimal(100, 0), - FilterIDs: []string{"*string:~*req.Account:1003"}, - }, - "GENUUID_FACTOR2": { - Factor: NewDecimal(200, 0), - }, - }, - Rating: map[string]*RateSInterval{ - "GENUUID_RATING1": { - Increments: []*RateSIncrement{ - { - Usage: NewDecimal(int64(time.Minute), 0), - RateIntervalIndex: 0, - RateID: "RATE_2", - CompressFactor: 1, - }, - }, - IntervalStart: NewDecimal(int64(time.Second), 0), - CompressFactor: 1, - }, - "GENUUID_RATING2": { - Increments: []*RateSIncrement{ - { - IncrementStart: NewDecimal(4, 2), - Usage: NewDecimal(int64(30*time.Second), 0), - RateIntervalIndex: 0, - RateID: "RATE_1", - CompressFactor: 1, - }, - }, - IntervalStart: NewDecimal(0, 0), - CompressFactor: 2, - }, - }, - Rates: map[string]*IntervalRate{ - "RATE_1": { - IntervalStart: NewDecimal(0, 0), - FixedFee: NewDecimal(4, 1), - RecurrentFee: NewDecimal(24, 1), - }, - "RATE_2": { - IntervalStart: NewDecimal(12, 1), - FixedFee: NewDecimal(1, 0), - RecurrentFee: NewDecimal(5, 2), - }, - }, - Accounts: map[string]*Account{ - "ACC1": { - Tenant: CGRateSorg, - ID: "account_1", - FilterIDs: []string{"*string:~*req.Account:1003"}, - Weights: []*DynamicWeight{ - { - Weight: 25, - }, - { - FilterIDs: []string{"*string:~*req.Account:1002"}, - }, - }, - Opts: map[string]interface{}{ - Subsys: MetaSessionS, - }, - Balances: map[string]*Balance{ - "bal1": { - ID: "BAL1", - FilterIDs: []string{"*string:~*req.Account:1003"}, - Weights: []*DynamicWeight{ - { - Weight: 25, - }, - }, - Type: MetaAbstract, - Units: NewDecimal(int64(30*time.Second), 0), - UnitFactors: []*UnitFactor{ - { - Factor: NewDecimal(100, 0), - FilterIDs: []string{"*string:~*req.Account:1003"}, - }, - { - Factor: NewDecimal(200, 0), - }, - }, - CostIncrements: []*CostIncrement{ - { - Increment: NewDecimal(int64(time.Second), 0), - RecurrentFee: NewDecimal(5, 0), - }, - { - FilterIDs: []string{"*string:~*req.Account:1003"}, - Increment: NewDecimal(int64(2*time.Second), 0), - FixedFee: NewDecimal(1, 0), - RecurrentFee: NewDecimal(5, 0), - }, - }, - AttributeIDs: []string{"ATTRIBUTE1"}, - }, - "bal2": { - ID: "BAL2", - FilterIDs: []string{"*string:~*req.Account:1004"}, - Weights: []*DynamicWeight{ - { - Weight: 25, - }, - }, - Type: MetaConcrete, - Units: NewDecimal(2000, 0), - UnitFactors: []*UnitFactor{ - { - Factor: NewDecimal(200, 0), - }, - }, - CostIncrements: []*CostIncrement{ - { - FilterIDs: []string{"*string:~*req.Account:1004"}, - Increment: NewDecimal(int64(2*time.Second), 0), - FixedFee: NewDecimal(1, 0), - RecurrentFee: NewDecimal(5, 0), - }, - }, - AttributeIDs: []string{"ATTRIBUTE1"}, - RateProfileIDs: []string{"RATE1", "RATE2"}, - }, - }, - ThresholdIDs: []string{}, - }, - "ACC2": { - Tenant: CGRateSorg, - ID: "account_2", - Weights: []*DynamicWeight{ - { - Weight: 25, - }, - }, - FilterIDs: []string{"*ai:~*req.AnswerTime:2020-10-10T10:00:00Z"}, - Opts: map[string]interface{}{ - Subsys: MetaSessionS, - }, - ThresholdIDs: []string{}, - }, - }, - } - - // ext equals - extEvCh := &ExtEventCharges{ - Abstracts: Float64Pointer(47.5), - Concretes: Float64Pointer(5.15), - Charges: []*ChargeEntry{ - { - ChargingID: "GENUUID1", - CompressFactor: 1, - }, - { - ChargingID: "GENUUID2", - CompressFactor: 1, - }, - }, - Accounting: map[string]*ExtAccountCharge{ - "THIS_GENUUID1": { - AccountID: "TestEventChargesEquals", - BalanceID: "CONCRETE1", - Units: Float64Pointer(0.8), - BalanceLimit: Float64Pointer(200), - UnitFactorID: "GENUUID_FACTOR1", - }, - "GENUUID1": { - AccountID: "TestEventChargesEquals", - BalanceID: "ABSTRACT2", - BalanceLimit: Float64Pointer(0), - RatingID: "GENUUID_RATING1", - JoinedChargeIDs: []string{"THIS_GENUUID1"}, - }, - "GENUUID2": { - AccountID: "TestEventChargesEquals", - BalanceID: "CONCRETE1", - Units: Float64Pointer(2), - BalanceLimit: Float64Pointer(200), - UnitFactorID: "GENUUID_FACTOR2", - RatingID: "ID_FOR_RATING", - AttributeIDs: []string{"ATTR1", "ATTR2"}, - }, - }, - UnitFactors: map[string]*ExtUnitFactor{ - "GENUUID_FACTOR1": { - Factor: Float64Pointer(100), - FilterIDs: []string{"*string:~*req.Account:1003"}, - }, - "GENUUID_FACTOR2": { - Factor: Float64Pointer(200), - }, - }, - Rating: map[string]*ExtRateSInterval{ - "GENUUID_RATING1": { - Increments: []*ExtRateSIncrement{ - { - Usage: Float64Pointer(float64(time.Minute)), - IntervalRateIndex: 0, - RateID: "RATE_2", - CompressFactor: 1, - }, - }, - IntervalStart: Float64Pointer(float64(time.Second)), - CompressFactor: 1, - }, - "GENUUID_RATING2": { - Increments: []*ExtRateSIncrement{ - { - IncrementStart: Float64Pointer(0.04), - Usage: Float64Pointer(float64(30 * time.Second)), - IntervalRateIndex: 0, - RateID: "RATE_1", - CompressFactor: 1, - }, - }, - IntervalStart: Float64Pointer(0), - CompressFactor: 2, - }, - }, - Rates: map[string]*ExtIntervalRate{ - "RATE_1": { - IntervalStart: Float64Pointer(0), - FixedFee: Float64Pointer(0.4), - RecurrentFee: Float64Pointer(2.4), - }, - "RATE_2": { - IntervalStart: Float64Pointer(1.2), - FixedFee: Float64Pointer(1), - RecurrentFee: Float64Pointer(0.05), - }, - }, - Accounts: map[string]*ExtAccount{ - "ACC1": { - Tenant: CGRateSorg, - ID: "account_1", - FilterIDs: []string{"*string:~*req.Account:1003"}, - Weights: []*DynamicWeight{ - { - Weight: 25, - }, - { - FilterIDs: []string{"*string:~*req.Account:1002"}, - }, - }, - Opts: map[string]interface{}{ - Subsys: MetaSessionS, - }, - Balances: map[string]*ExtBalance{ - "bal1": { - ID: "BAL1", - FilterIDs: []string{"*string:~*req.Account:1003"}, - Weights: []*DynamicWeight{ - { - Weight: 25, - }, - }, - Type: MetaAbstract, - Units: Float64Pointer(float64(30 * time.Second)), - UnitFactors: []*ExtUnitFactor{ - { - Factor: Float64Pointer(100), - FilterIDs: []string{"*string:~*req.Account:1003"}, - }, - { - Factor: Float64Pointer(200), - }, - }, - CostIncrements: []*ExtCostIncrement{ - { - Increment: Float64Pointer(float64(time.Second)), - RecurrentFee: Float64Pointer(5), - }, - { - FilterIDs: []string{"*string:~*req.Account:1003"}, - Increment: Float64Pointer(float64(2 * time.Second)), - FixedFee: Float64Pointer(1), - RecurrentFee: Float64Pointer(5), - }, - }, - AttributeIDs: []string{"ATTRIBUTE1"}, - }, - "bal2": { - ID: "BAL2", - FilterIDs: []string{"*string:~*req.Account:1004"}, - Weights: []*DynamicWeight{ - { - Weight: 25, - }, - }, - Type: MetaConcrete, - Units: Float64Pointer(2000), - UnitFactors: []*ExtUnitFactor{ - { - Factor: Float64Pointer(200), - }, - }, - CostIncrements: []*ExtCostIncrement{ - { - FilterIDs: []string{"*string:~*req.Account:1004"}, - Increment: Float64Pointer(float64(2 * time.Second)), - FixedFee: Float64Pointer(1), - RecurrentFee: Float64Pointer(5), - }, - }, - AttributeIDs: []string{"ATTRIBUTE1"}, - RateProfileIDs: []string{"RATE1", "RATE2"}, - }, - }, - ThresholdIDs: []string{}, - }, - "ACC2": { - Tenant: CGRateSorg, - ID: "account_2", - Weights: []*DynamicWeight{ - { - Weight: 25, - }, - }, - FilterIDs: []string{"*ai:~*req.AnswerTime:2020-10-10T10:00:00Z"}, - Opts: map[string]interface{}{ - Subsys: MetaSessionS, - }, - ThresholdIDs: []string{}, - }, - }, - } - rcv, err := eEvChgs.AsExtEventCharges() - if err != nil { - t.Error(err) - } - if ok := rcv.Equals(extEvCh); !ok { - t.Errorf("Expected %+v \n, received %+v", ToJSON(extEvCh), ToJSON(rcv)) - } -} - func TestEventChargerMerge(t *testing.T) { eEvChgs := &EventCharges{ Abstracts: NewDecimal(47500, 3), diff --git a/utils/librates_test.go b/utils/librates_test.go index 4ab762953..1554f61e7 100644 --- a/utils/librates_test.go +++ b/utils/librates_test.go @@ -19,7 +19,6 @@ along with this program. If not, see package utils import ( - "math" "reflect" "testing" "time" @@ -199,7 +198,6 @@ func TestLibratesRunTimes(t *testing.T) { /* func TestLibratesCorrectCost(t *testing.T) { - //CorrectCost does nothing rPc := &RateProfileCost{ Cost: NewDecimal(1234, 3), @@ -222,7 +220,7 @@ func TestLibratesCorrectCost(t *testing.T) { //CorrectCost rounds the cost expected = &RateProfileCost{ - Cost: NewDecimal(124, 2), + Cost: NewDecimal(12, 1), MinCost: NewDecimal(1, 0), MaxCost: NewDecimal(2, 0), Altered: []string{RoundingDecimals}, @@ -235,7 +233,6 @@ func TestLibratesCorrectCost(t *testing.T) { } //CorrectCost assigns MaxCost to Cost when Cost > MaxCost - expected = &RateProfileCost{ Cost: NewDecimal(2, 0), MinCost: NewDecimal(1, 0), @@ -264,7 +261,6 @@ func TestLibratesCorrectCost(t *testing.T) { t.Errorf("\nExpected: <%+v>, \nReceived: <%+v>", expected, rPc) } } - */ func TestRateProfileSort(t *testing.T) { @@ -1281,107 +1277,6 @@ func TestRatesIncrementEquals(t *testing.T) { incr2.CompressFactor = 2 } -func TestAsExtRateSInterval(t *testing.T) { - rI := &RateSInterval{ - IntervalStart: NewDecimal(int64(time.Second), 0), - Increments: []*RateSIncrement{ - { - IncrementStart: NewDecimal(int64(time.Nanosecond), 0), - Usage: NewDecimal(int64(time.Minute), 0), - RateIntervalIndex: 0, - CompressFactor: 1, - cost: NewDecimal(1000, 0).Big, - }, - { - IncrementStart: NewDecimal(int64(time.Minute), 0), - Usage: NewDecimal(int64(2*time.Minute), 0), - RateIntervalIndex: 2, - CompressFactor: 5, - }, - }, - CompressFactor: 1, - cost: NewDecimal(1234, 1).Big, - } - - expRi := &ExtRateSInterval{ - IntervalStart: Float64Pointer(float64(time.Second)), - Increments: []*ExtRateSIncrement{ - { - IncrementStart: Float64Pointer(float64(time.Nanosecond)), - Usage: Float64Pointer(float64(time.Minute)), - IntervalRateIndex: 0, - CompressFactor: 1, - cost: Float64Pointer(1000), - }, - { - IncrementStart: Float64Pointer(float64(time.Minute)), - Usage: Float64Pointer(float64(2 * time.Minute)), - IntervalRateIndex: 2, - CompressFactor: 5, - }, - }, - CompressFactor: 1, - cost: Float64Pointer(123.4), - } - - if rcv, err := rI.AsExtRateSInterval(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(rcv, expRi) { - t.Errorf("Expected %+v \n, received %+v", ToJSON(expRi), ToJSON(rcv)) - } -} - -func TestAsExtRateSIntervalErrorsCheck(t *testing.T) { - rI := &RateSInterval{ - IntervalStart: NewDecimal(int64(math.Inf(1))-1, 0), - Increments: []*RateSIncrement{ - { - IncrementStart: NewDecimal(int64(time.Nanosecond), 0), - Usage: NewDecimal(int64(time.Minute), 0), - RateIntervalIndex: 0, - CompressFactor: 1, - cost: NewDecimal(1000, 0).Big, - }, - }, - CompressFactor: 1, - cost: NewDecimal(1234, 1).Big, - } - - expErr := "Cannot convert decimal IntervalStart into float64 " - if _, err := rI.AsExtRateSInterval(); err == nil || err.Error() != expErr { - t.Errorf("Expected %+v, received %+v", expErr, err) - } - rI.IntervalStart = NewDecimal(0, 0) - - rI.cost = NewDecimal(int64(math.Inf(1))-1, 0).Big - expErr = "Cannot convert decimal cost into float64 " - if _, err := rI.AsExtRateSInterval(); err == nil || err.Error() != expErr { - t.Errorf("Expected %+q, received %+q", expErr, err) - } - rI.cost = NewDecimal(0, 0).Big - - rI.Increments[0].IncrementStart = NewDecimal(int64(math.Inf(1))-1, 0) - expErr = "Cannot convert decimal IncrementStart into float64 " - if _, err := rI.AsExtRateSInterval(); err == nil || err.Error() != expErr { - t.Errorf("Expected %+q, received %+q", expErr, err) - } - rI.Increments[0].IncrementStart = NewDecimal(0, 0) - - rI.Increments[0].Usage = NewDecimal(int64(math.Inf(1))-1, 0) - expErr = "Cannot convert decimal Usage into float64 " - if _, err := rI.AsExtRateSInterval(); err == nil || err.Error() != expErr { - t.Errorf("Expected %+q, received %+q", expErr, err) - } - rI.Increments[0].Usage = NewDecimal(0, 0) - - rI.Increments[0].cost = NewDecimal(int64(math.Inf(1))-1, 0).Big - expErr = "Cannot convert decimal cost into float64 " - if _, err := rI.AsExtRateSInterval(); err == nil || err.Error() != expErr { - t.Errorf("Expected %+q, received %+q", expErr, err) - } - rI.Increments[0].cost = NewDecimal(0, 0).Big -} - func TestRateProfileCostEquals(t *testing.T) { rtPrfCost := &RateProfileCost{ ID: "RATE_1",