From 3b9cc4895ad4bf0637fb279709a6d97b2fb58e39 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 27 May 2020 10:33:47 +0300 Subject: [PATCH] Updated utils tests --- config/eescfg.go | 24 ++++++++++++------------ engine/account_test.go | 15 ++++++++------- engine/caches.go | 4 ++-- engine/storage_mongo_datadb.go | 1 - utils/pathitem_test.go | 8 ++++++++ 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/config/eescfg.go b/config/eescfg.go index 3191f7983..bea954fe0 100644 --- a/config/eescfg.go +++ b/config/eescfg.go @@ -192,18 +192,18 @@ func (eeC *EventExporterCfg) loadFromJsonCfg(jsnEec *EventExporterJsonCfg, separ eeC.headerFields = make([]*FCTemplate, 0) eeC.contentFields = make([]*FCTemplate, 0) eeC.trailerFields = make([]*FCTemplate, 0) - if eeC.Fields, err = FCTemplatesFromFCTemplatesJsonCfg(*jsnEec.Fields, separator); err != nil { - return err - } else { - for _, field := range eeC.Fields { - switch field.GetPathSlice()[0] { - case utils.MetaHdr: - eeC.headerFields = append(eeC.headerFields, field) - case utils.MetaExp: - eeC.contentFields = append(eeC.contentFields, field) - case utils.MetaTrl: - eeC.trailerFields = append(eeC.trailerFields, field) - } + eeC.Fields, err = FCTemplatesFromFCTemplatesJsonCfg(*jsnEec.Fields, separator) + if err != nil { + return + } + for _, field := range eeC.Fields { + switch field.GetPathSlice()[0] { + case utils.MetaHdr: + eeC.headerFields = append(eeC.headerFields, field) + case utils.MetaExp: + eeC.contentFields = append(eeC.contentFields, field) + case utils.MetaTrl: + eeC.trailerFields = append(eeC.trailerFields, field) } } } diff --git a/engine/account_test.go b/engine/account_test.go index 473b83b2e..bce1616fd 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -92,8 +92,9 @@ func TestAccountStorageStoreRestore(t *testing.T) { b2 := &Balance{Value: 100, Weight: 20, DestinationIDs: utils.StringMap{"RET": true}} rifsBalance := &Account{ID: "other", - BalanceMap: map[string]Balances{utils.VOICE: Balances{b1, b2}, - utils.MONETARY: Balances{&Balance{Value: 21}}}} + BalanceMap: map[string]Balances{ + utils.VOICE: {b1, b2}, + utils.MONETARY: {&Balance{Value: 21}}}} dm.SetAccount(rifsBalance) ub1, err := dm.GetAccount("other") if err != nil || @@ -110,8 +111,8 @@ func TestGetSecondsForPrefix(t *testing.T) { DestinationIDs: utils.StringMap{"RET": true}} ub1 := &Account{ID: "CUSTOMER_1:rif", BalanceMap: map[string]Balances{ - utils.VOICE: Balances{b1, b2}, - utils.MONETARY: Balances{&Balance{Value: 200}}}} + utils.VOICE: {b1, b2}, + utils.MONETARY: {&Balance{Value: 200}}}} cd := &CallDescriptor{ Category: "0", Tenant: "vdf", @@ -139,8 +140,8 @@ func TestGetSpecialPricedSeconds(t *testing.T) { ub1 := &Account{ ID: "OUT:CUSTOMER_1:rif", BalanceMap: map[string]Balances{ - utils.VOICE: Balances{b1, b2}, - utils.MONETARY: Balances{&Balance{Value: 21}}, + utils.VOICE: {b1, b2}, + utils.MONETARY: {&Balance{Value: 21}}, }, } cd := &CallDescriptor{ @@ -219,7 +220,7 @@ func TestDebitCreditZeroSecond(t *testing.T) { var err error cc, err = rifsBalance.debitCreditBalance(cd, false, false, true) if err != nil { - t.Error("Error debiting balance: ", err) + t.Fatal("Error debiting balance: ", err) } if cc.Timespans[0].Increments[0].BalanceInfo.Unit.UUID != "testb" { t.Logf("%+v", cc.Timespans[0]) diff --git a/engine/caches.go b/engine/caches.go index cf234e520..19ab9a4c8 100644 --- a/engine/caches.go +++ b/engine/caches.go @@ -167,12 +167,12 @@ func (chS *CacheS) RollbackTransaction(transID string) { chS.tCache.RollbackTransaction(transID) } -// RollbackTransaction is an exported method from TransCache +// CommitTransaction is an exported method from TransCache func (chS *CacheS) CommitTransaction(transID string) { chS.tCache.CommitTransaction(transID) } -// RollbackTransaction is an exported method from TransCache +// GetCloned is an exported method from TransCache func (chS *CacheS) GetCloned(chID, itmID string) (cln interface{}, err error) { return chS.tCache.GetCloned(chID, itmID) } diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 3c4f1e25d..34f60eb09 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1009,7 +1009,6 @@ func (ms *MongoStorage) SetReverseDestinationDrv(dest *Destination, ) return err }); err != nil { - return err } } diff --git a/utils/pathitem_test.go b/utils/pathitem_test.go index 9e2d979bd..676582418 100644 --- a/utils/pathitem_test.go +++ b/utils/pathitem_test.go @@ -155,3 +155,11 @@ func TestGetPathWithoutIndex(t *testing.T) { t.Errorf("Expected: %s, received: %s", expected, rply) } } + +func TestPathItemsSlice(t *testing.T) { + expected := []string{"*req", "Field1[0]", "Account"} + path := NewPathItems(expected) + if rply := path.Slice(); !reflect.DeepEqual(expected, rply) { + t.Errorf("Expected: %q, received: %q", expected, rply) + } +}