mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
Tested the resolved panic with evChargers in account
This commit is contained in:
committed by
Dan Christian Bogos
parent
9ef188e3eb
commit
05e7900aea
@@ -114,7 +114,8 @@ func (aB *abstractBalance) debitAbstracts(ctx *context.Context, usage *decimal.B
|
||||
aB.rateSConns, aB.blnCfg.RateProfileIDs,
|
||||
costIcrm, dbted); err != nil {
|
||||
return
|
||||
} else if ecCost.Abstracts.Compare(utils.NewDecimal(0, 0)) == 0 { // no debit performed
|
||||
} else if ecCost.Abstracts.Compare(utils.NewDecimal(0, 0)) == 0 {
|
||||
// no debit performed
|
||||
return ecCost, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1984,3 +1984,75 @@ func TestV1DebitAbstractsWithRecurrentFeeNegative(t *testing.T) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func TestDebitAbstractsMaxDebitAbstractFromConcreteNoConcrBal(t *testing.T) {
|
||||
// this test will call maxDebitAbstractsFromConcretes but without any concreteBal and not calling rates
|
||||
cache := engine.Cache
|
||||
engine.Cache.Clear(nil)
|
||||
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
dm := engine.NewDataManager(engine.NewInternalDB(nil, nil, true), cfg.CacheCfg(), nil)
|
||||
filterS := engine.NewFilterS(cfg, nil, dm)
|
||||
|
||||
acnts := NewAccountS(cfg, filterS, nil, dm)
|
||||
acnt := &utils.Account{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestV1DebitAbstractsWithRecurrentFeeNegative",
|
||||
Balances: map[string]*utils.Balance{
|
||||
"ab1": &utils.Balance{
|
||||
ID: "ab1",
|
||||
Type: utils.MetaAbstract,
|
||||
Units: utils.NewDecimal(int64(60*time.Second), 0),
|
||||
CostIncrements: []*utils.CostIncrement{
|
||||
{
|
||||
FixedFee: utils.NewDecimal(1, 1),
|
||||
Increment: utils.NewDecimal(1, 0),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dm.SetAccount(context.Background(), acnt, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
cgrEv := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "EV",
|
||||
Event: map[string]interface{}{
|
||||
utils.ToR: utils.MetaVoice,
|
||||
utils.AccountField: "1001",
|
||||
utils.Destination: "1002",
|
||||
},
|
||||
APIOpts: map[string]interface{}{
|
||||
utils.MetaUsage: 2 * time.Minute,
|
||||
utils.OptsAccountS: true,
|
||||
},
|
||||
}
|
||||
|
||||
extAc, err := acnt.AsExtAccount()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
expEcCh := utils.ExtEventCharges{
|
||||
Abstracts: utils.Float64Pointer(0),
|
||||
Accounting: make(map[string]*utils.ExtAccountCharge),
|
||||
UnitFactors: make(map[string]*utils.ExtUnitFactor),
|
||||
Rating: make(map[string]*utils.ExtRateSInterval),
|
||||
Rates: make(map[string]*utils.ExtIntervalRate),
|
||||
Accounts: map[string]*utils.ExtAccount{
|
||||
"TestV1DebitAbstractsWithRecurrentFeeNegative": extAc,
|
||||
},
|
||||
}
|
||||
|
||||
// not having concrBal and connection to rates, this will not perform a debit, so the EventChargers abstract will be empty
|
||||
var eEc utils.ExtEventCharges
|
||||
if err := acnts.V1DebitAbstracts(context.Background(), cgrEv, &eEc); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eEc, expEcCh) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expEcCh), utils.ToJSON(eEc))
|
||||
}
|
||||
|
||||
engine.Cache = cache
|
||||
}
|
||||
|
||||
@@ -174,50 +174,40 @@ func (ec *EventCharges) AsExtEventCharges() (eEc *ExtEventCharges, err error) {
|
||||
if ec.Accounting != nil {
|
||||
eEc.Accounting = make(map[string]*ExtAccountCharge, len(eEc.Accounting))
|
||||
for key, val := range ec.Accounting {
|
||||
if extAcc, err := val.AsExtAccountCharge(); err != nil {
|
||||
if eEc.Accounting[key], err = val.AsExtAccountCharge(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eEc.Accounting[key] = extAcc
|
||||
}
|
||||
}
|
||||
}
|
||||
if ec.UnitFactors != nil {
|
||||
eEc.UnitFactors = make(map[string]*ExtUnitFactor, len(ec.UnitFactors))
|
||||
for key, val := range ec.UnitFactors {
|
||||
if extUnit, err := val.AsExtUnitFactor(); err != nil {
|
||||
if eEc.UnitFactors[key], err = val.AsExtUnitFactor(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eEc.UnitFactors[key] = extUnit
|
||||
}
|
||||
}
|
||||
}
|
||||
if ec.Rating != nil {
|
||||
eEc.Rating = make(map[string]*ExtRateSInterval, len(ec.Rating))
|
||||
for key, val := range ec.Rating {
|
||||
if extRate, err := val.AsExtRateSInterval(); err != nil {
|
||||
if eEc.Rating[key], err = val.AsExtRateSInterval(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eEc.Rating[key] = extRate
|
||||
}
|
||||
}
|
||||
}
|
||||
if ec.Rates != nil {
|
||||
eEc.Rates = make(map[string]*ExtIntervalRate, len(ec.Rates))
|
||||
for key, val := range ec.Rates {
|
||||
if extRate, err := val.AsExtIntervalRate(); err != nil {
|
||||
if eEc.Rates[key], err = val.AsExtIntervalRate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eEc.Rates[key] = extRate
|
||||
}
|
||||
}
|
||||
}
|
||||
if ec.Accounts != nil {
|
||||
eEc.Accounts = make(map[string]*ExtAccount, len(ec.Accounts))
|
||||
for acntID, acnt := range ec.Accounts {
|
||||
if extAccs, err := acnt.AsExtAccount(); err != nil {
|
||||
if eEc.Accounts[acntID], err = acnt.AsExtAccount(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
eEc.Accounts[acntID] = extAccs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,11 +324,6 @@ func (rI *RateSInterval) AsRatesIntervalsCost() (rIc *RateSIntervalCost) {
|
||||
rIc = &RateSIntervalCost{
|
||||
CompressFactor: rI.CompressFactor,
|
||||
}
|
||||
/*
|
||||
if rI.cost != nil {
|
||||
rIc.cost = rI.cost
|
||||
}
|
||||
*/
|
||||
if rI.Increments != nil {
|
||||
rIc.Increments = make([]*RateSIncrementCost, len(rI.Increments))
|
||||
for idx, incr := range rI.Increments {
|
||||
@@ -508,8 +503,6 @@ type RateProfileCost struct {
|
||||
type RateSIntervalCost struct {
|
||||
Increments []*RateSIncrementCost
|
||||
CompressFactor int64
|
||||
|
||||
cost *decimal.Big // unexported total interval cost
|
||||
}
|
||||
|
||||
// RateSIncrementCost is used in the RateProfileCost to reflect RateSIncrement
|
||||
@@ -518,8 +511,6 @@ type RateSIncrementCost struct {
|
||||
RateID string
|
||||
RateIntervalIndex int
|
||||
CompressFactor int64
|
||||
|
||||
cost *decimal.Big // unexported total increment cost
|
||||
}
|
||||
|
||||
// AsRateSIncrementCost converts RateSIncrement to RateSIncrementCost
|
||||
@@ -533,11 +524,6 @@ func (rI *RateSIncrement) AsRateSIncrementCost() (rIc *RateSIncrementCost) {
|
||||
if rI.Usage != nil {
|
||||
rIc.Usage = rI.Usage
|
||||
}
|
||||
/*
|
||||
if rI.cost != nil {
|
||||
rIc.cost = rI.cost
|
||||
}
|
||||
*/
|
||||
return
|
||||
|
||||
}
|
||||
@@ -720,6 +706,7 @@ func (rIcr *RateSIncrement) Cost(rts map[string]*IntervalRate) (cost *decimal.Bi
|
||||
return rIcr.cost
|
||||
}
|
||||
|
||||
/*
|
||||
// CostForIntervals sums the costs for all intervals
|
||||
func CostForIntervals(rtIvls []*RateSInterval, rts map[string]*IntervalRate) (cost *decimal.Big) {
|
||||
cost = new(decimal.Big)
|
||||
@@ -728,6 +715,7 @@ func CostForIntervals(rtIvls []*RateSInterval, rts map[string]*IntervalRate) (co
|
||||
}
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
// CompressIntervals will compress intervals which equal
|
||||
func CompressIntervals(rtIvls []*RateSInterval) {
|
||||
|
||||
Reference in New Issue
Block a user