From f115b6928756167d5a0a3301cce954a86b6f1267 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 3 Nov 2015 18:10:50 +0200 Subject: [PATCH] init counters on account load --- engine/loader_csv_test.go | 26 +++++++++++++++++++++++--- engine/tp_reader.go | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index dd01947a9..9be5972ed 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -1048,15 +1048,35 @@ func TestLoadAccountActions(t *testing.T) { } aa := csvr.accountActions["vdf:minitsboy"] expected := &Account{ - Id: "vdf:minitsboy", + Id: "vdf:minitsboy", + UnitCounters: UnitCounters{ + &UnitCounter{ + BalanceType: "*voice", + CounterType: "*event", + Balances: BalanceChain{ + &Balance{ + Id: "2c2ce3c9-d62b-49dc-82a5-2a17bdc6eb4e", + Value: 0, + Directions: utils.NewStringMap("*out"), + DestinationIds: utils.NewStringMap("GERMANY_O2"), + SharedGroups: utils.StringMap{}, + Categories: utils.StringMap{}, + TimingIDs: utils.StringMap{}, + }, + }, + }, + }, ActionTriggers: csvr.actionsTriggers["STANDARD_TRIGGER"], } // set propper uuid for i, atr := range aa.ActionTriggers { csvr.actionsTriggers["STANDARD_TRIGGER"][i].Id = atr.Id } - if !reflect.DeepEqual(aa, expected) { - t.Errorf("Error loading account action: %+v", aa.ActionTriggers[0]) + for i, b := range aa.UnitCounters[0].Balances { + expected.UnitCounters[0].Balances[i].Id = b.Id + } + if !reflect.DeepEqual(aa.UnitCounters[0].Balances[0], expected.UnitCounters[0].Balances[0]) { + t.Errorf("Error loading account action: %+v \n %+v", aa.UnitCounters[0].Balances[0], expected.UnitCounters[0].Balances[0]) } // test that it does not overwrite balances existing, err := accountingStorage.GetAccount(aa.Id) diff --git a/engine/tp_reader.go b/engine/tp_reader.go index 3c2ef32fe..6364eb602 100644 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -867,6 +867,7 @@ func (tpr *TpReader) LoadAccountActions() (err error) { AllowNegative: aa.AllowNegative, Disabled: aa.Disabled, } + ub.InitCounters() tpr.accountActions[aa.KeyId()] = ub aTimings, exists := tpr.actionPlans[aa.ActionPlanId] if !exists {