From 43bdcb367c583599bbbe007956c65f7b7fc75a3e Mon Sep 17 00:00:00 2001 From: Edwardro22 Date: Tue, 24 Jan 2017 16:03:21 +0200 Subject: [PATCH] small fix --- engine/onstor_it_test.go | 36 ++++++++++++++++++++++++------------ engine/storage_map.go | 12 +++++++----- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 645043323..6db28f09a 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -37,6 +37,7 @@ var ( rdsITdb *RedisStorage mgoITdb *MongoStorage onStor DataDB + dbnames string ) // subtests to be executed for each confDIR @@ -66,8 +67,8 @@ var sTestsOnStorIT = []func(t *testing.T){ testOnStorITPushPop, testOnStorITCRUDRatingPlan, testOnStorITCRUDRatingProfile, - testOnStorITCRUDDestination, - testOnStorITCRUDReverseDestination, + testOnStorITCRUDDestinations, + testOnStorITCRUDReverseDestinations, testOnStorITCRUDLCR, testOnStorITCRUDCdrStats, testOnStorITCRUDActions, @@ -92,6 +93,14 @@ func TestOnStorITRedisConnect(t *testing.T) { if err != nil { t.Fatal("Could not connect to Redis", err.Error()) } + dbnames = cfg.DataDbName +} + +func TestOnStorITRedis(t *testing.T) { + onStor = rdsITdb + for _, stest := range sTestsOnStorIT { + t.Run("TestOnStorITRedis", stest) + } } func TestOnStorITMongoConnect(t *testing.T) { @@ -104,15 +113,8 @@ func TestOnStorITMongoConnect(t *testing.T) { utils.StorDB, nil, mgoITCfg.CacheConfig, mgoITCfg.LoadHistorySize); err != nil { t.Fatal(err) } + dbnames = mgoITCfg.StorDBName } - -func TestOnStorITRedis(t *testing.T) { - onStor = rdsITdb - for _, stest := range sTestsOnStorIT { - t.Run("TestOnStorITRedis", stest) - } -} - func TestOnStorITMongo(t *testing.T) { onStor = mgoITdb for _, stest := range sTestsOnStorIT { @@ -253,6 +255,7 @@ func testOnStorITCacheDestinations(t *testing.T) { if err := onStor.SetDestination(dst, utils.NonTransactional); err != nil { t.Error(err) } + if _, hasIt := cache.Get(utils.DESTINATION_PREFIX + dst.Id); hasIt { t.Error("Already in cache") } @@ -265,11 +268,20 @@ func testOnStorITCacheDestinations(t *testing.T) { if err := onStor.CacheDataFromDB(utils.DESTINATION_PREFIX, []string{dst.Id}, false); err != nil { t.Error(err) } + if err = onStor.SelectDatabase("13"); err != nil { + t.Error(err) + } + if _, rcvErr := onStor.GetReverseDestination(dst.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { + t.Error(rcvErr) + } if itm, hasIt := cache.Get(utils.DESTINATION_PREFIX + dst.Id); !hasIt { t.Error("Did not cache") } else if !reflect.DeepEqual(dst, itm.(*Destination)) { t.Error("Wrong item in the cache") } + if err = onStor.SelectDatabase(dbnames); err != nil { + t.Error(err) + } } func testOnStorITCacheReverseDestinations(t *testing.T) { @@ -913,7 +925,7 @@ func testOnStorITCRUDRatingProfile(t *testing.T) { } } -func testOnStorITCRUDDestination(t *testing.T) { +func testOnStorITCRUDDestinations(t *testing.T) { dst := &Destination{Id: "CRUDDestination2", Prefixes: []string{"+491", "+492", "+493"}} if _, rcvErr := onStor.GetDestination(dst.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { t.Error(rcvErr) @@ -934,7 +946,7 @@ func testOnStorITCRUDDestination(t *testing.T) { } } -func testOnStorITCRUDReverseDestination(t *testing.T) { +func testOnStorITCRUDReverseDestinations(t *testing.T) { dst := &Destination{Id: "CRUDReverseDestination", Prefixes: []string{"+494", "+495", "+496"}} dst2 := &Destination{Id: "CRUDReverseDestination2", Prefixes: []string{"+497", "+498", "+499"}} if _, rcvErr := onStor.GetReverseDestination(dst.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { diff --git a/engine/storage_map.go b/engine/storage_map.go index 015a3723c..254e4856c 100644 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -1028,15 +1028,17 @@ func (ms *MapStorage) GetAccountActionPlans(acntID string, skipCache bool, trans key := utils.AccountActionPlansPrefix + acntID var values []byte if !skipCache { - if ap, ok := cache.Get(key); !ok { - return nil, utils.ErrNotFound - } else { - return ap.([]string), nil + if x, ok := cache.Get(key); ok { + if x == nil { + return nil, utils.ErrNotFound + } + return x.([]string), nil } } if _, ok := ms.dict[key]; !ok { cache.Set(key, nil, cacheCommit(transactionID), transactionID) - return nil, utils.ErrNotFound + err = utils.ErrNotFound + return nil, err } if err = ms.ms.Unmarshal(values, &apIDs); err != nil {