From 794e60e5dfc59909f91afc91caeaeebbfbc3adb6 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 13 Dec 2021 16:03:08 +0200 Subject: [PATCH] Updated logger message --- engine/calldesc.go | 2 +- engine/calldesc_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/engine/calldesc.go b/engine/calldesc.go index aec90d6f9..d0e32a203 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -920,7 +920,7 @@ func (cd *CallDescriptor) refundIncrements() (acnt *Account, err error) { // check money too if increment.BalanceInfo.Monetary != nil && increment.BalanceInfo.Monetary.UUID != "" { if balance = account.BalanceMap[utils.MONETARY].GetBalance(increment.BalanceInfo.Monetary.UUID); balance == nil { - utils.Logger.Warning(fmt.Sprintf("Could not get the balnce: <%s> to be refunded for account: <%s>", increment.BalanceInfo.Unit.UUID, increment.BalanceInfo.AccountID)) + utils.Logger.Warning(fmt.Sprintf("Could not get the balnce: <%s> to be refunded for account: <%s>", increment.BalanceInfo.Monetary.UUID, increment.BalanceInfo.AccountID)) continue } balance.AddValue(increment.Cost) diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 8d5e081c7..61cad9d78 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -2017,3 +2017,29 @@ func BenchmarkStorageMultipleGetSessionTime(b *testing.B) { cd.GetMaxSessionDuration() } } + +func TestCDRefundIncrementspanic(t *testing.T) { + ub := &Account{ + ID: "test:refpanic", + BalanceMap: map[string]Balances{ + utils.MONETARY: { + &Balance{Uuid: "moneya", Value: 100}, + }, + }, + } + dm.SetAccount(ub) + increments := Increments{ + &Increment{Cost: 2, BalanceInfo: &DebitInfo{ + Monetary: &MonetaryInfo{UUID: "moneya2"}, AccountID: ub.ID}}, + } + cd := &CallDescriptor{ToR: utils.VOICE, Increments: increments} + if _, err := cd.refundIncrements(); err != nil { + t.Fatal(err) + } + ub, _ = dm.GetAccount(ub.ID) + if ub.BalanceMap[utils.MONETARY][0].GetValue() != 100 || // no refund because of missing balance with ID + len(ub.BalanceMap) != 1 || + len(ub.BalanceMap[utils.MONETARY]) != 1 { + t.Error("Error refunding money: ", utils.ToIJSON(ub.BalanceMap)) + } +}