From e74757e30e64de6030ca4b9d244e420c8bdbe80e Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Fri, 9 Apr 2021 18:06:58 +0300 Subject: [PATCH] Cover functions in engine/event_cost.go --- engine/eventcost_test.go | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/engine/eventcost_test.go b/engine/eventcost_test.go index 725b7f853..27c387557 100644 --- a/engine/eventcost_test.go +++ b/engine/eventcost_test.go @@ -3801,3 +3801,78 @@ func TestECFieldAsInterfaceNilEventCost(t *testing.T) { t.Fatalf("Expected error:%s, received: %v", utils.ErrNotFound.Error(), err) } } + +func TestECnewChargingIncrementMissingBalanceInfo(t *testing.T) { + ec := &EventCost{} + incr := &Increment{} + rf := make(RatingMatchedFilters) + + exp := &ChargingIncrement{ + Usage: incr.Duration, + Cost: incr.Cost, + CompressFactor: incr.CompressFactor, + } + rcv := ec.newChargingIncrement(incr, rf, false, false) + + if !reflect.DeepEqual(rcv, exp) { + t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv) + } +} + +func TestECnewChargingIncrementWithUnitInfo(t *testing.T) { + ec := &EventCost{ + Accounting: Accounting{}, + } + incr := &Increment{ + BalanceInfo: &DebitInfo{ + Unit: &UnitInfo{}, + Monetary: &MonetaryInfo{}, + }, + } + rf := make(RatingMatchedFilters) + + exp := &ChargingIncrement{ + Usage: incr.Duration, + Cost: incr.Cost, + CompressFactor: incr.CompressFactor, + AccountingID: utils.MetaPause, + } + rcv := ec.newChargingIncrement(incr, rf, false, true) + + if !reflect.DeepEqual(rcv, exp) { + t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv) + } +} + +func TestECnewChargingIncrementNoUnitInfo(t *testing.T) { + ec := &EventCost{ + Accounting: Accounting{}, + } + incr := &Increment{ + BalanceInfo: &DebitInfo{ + Monetary: &MonetaryInfo{}, + }, + } + rf := make(RatingMatchedFilters) + + exp := &ChargingIncrement{ + Usage: incr.Duration, + Cost: incr.Cost, + CompressFactor: incr.CompressFactor, + AccountingID: utils.MetaPause, + } + expEC := &EventCost{ + Accounting: Accounting{ + utils.MetaPause: &BalanceCharge{}, + }, + } + rcv := ec.newChargingIncrement(incr, rf, false, true) + + if !reflect.DeepEqual(rcv, exp) { + t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv) + } + + if !reflect.DeepEqual(ec, expEC) { + t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", expEC, ec) + } +}