From d3ffb0c9eded1ddd60d48a64277d42b3a16f17eb Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 16 Jan 2017 18:09:35 +0100 Subject: [PATCH] Fix DataDB.RemAccountActionPlans --- engine/onstor_it_test.go | 22 +++++++++++----------- engine/storage_mongo_datadb.go | 4 ++-- engine/storage_redis.go | 6 +++++- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index d83187d97..fa67eb4fa 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -1215,20 +1215,20 @@ func testOnStorITCRUDAccountActionPlans(t *testing.T) { } else if !reflect.DeepEqual(expect, rcv) { t.Errorf("Expecting: %v, received: %v", expect, rcv) } - // if err := onStor.RemAccountActionPlans(acntID, aAPs2); err != nil { - // t.Error(err) - // } - // if rcv, err := onStor.GetAccountActionPlans(acntID, true, utils.NonTransactional); err != nil { - // t.Error(err) - // } else if !reflect.DeepEqual(aAPs, rcv) { - // t.Errorf("Expecting: %v, received: %v", aAPs, rcv) - // }onstor_it_test.go:1238: Expecting: [PACKAGE_10_SHARED_A_5 apl_PACKAGE_1001], received: [PACKAGE_10_SHARED_A_5 USE_SHARED_A apl_PACKAGE_1001] + if err := onStor.RemAccountActionPlans(acntID, aAPs2); err != nil { + t.Error(err) + } + if rcv, err := onStor.GetAccountActionPlans(acntID, true, utils.NonTransactional); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(aAPs, rcv) { + t.Errorf("Expecting: %v, received: %v", aAPs, rcv) + } if err := onStor.RemAccountActionPlans(acntID, aAPs); err != nil { t.Error(err) } - // if _, rcvErr := onStor.GetAccountActionPlans(acntID, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { - // t.Error(rcvErr) - // } + if _, rcvErr := onStor.GetAccountActionPlans(acntID, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { + t.Error(rcvErr) + } } func testOnStorITCRUDAccount(t *testing.T) { diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 3e64575f8..9f2a1e770 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1658,7 +1658,7 @@ func (ms *MongoStorage) RemAccountActionPlans(acntID string, aPlIDs []string) (e if len(aPlIDs) == 0 { return col.Remove(bson.M{"key": acntID}) } - oldAPlIDs, err := ms.GetAccountActionPlans(acntID, false, utils.NonTransactional) + oldAPlIDs, err := ms.GetAccountActionPlans(acntID, true, utils.NonTransactional) if err != nil { return err } @@ -1675,7 +1675,7 @@ func (ms *MongoStorage) RemAccountActionPlans(acntID string, aPlIDs []string) (e _, err = col.Upsert(bson.M{"key": acntID}, &struct { Key string Value []string - }{Key: acntID, Value: aPlIDs}) + }{Key: acntID, Value: oldAPlIDs}) return } diff --git a/engine/storage_redis.go b/engine/storage_redis.go index a202828c7..6ef04ada1 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1267,7 +1267,11 @@ func (rs *RedisStorage) RemAccountActionPlans(acntID string, aPlIDs []string) (e if len(oldaPlIDs) == 0 { // no more elements, remove the reference return rs.Cmd("DEL", key).Err } - return rs.Cmd("SET", key, oldaPlIDs).Err + var result []byte + if result, err = rs.ms.Marshal(oldaPlIDs); err != nil { + return err + } + return rs.Cmd("SET", key, result).Err } func (rs *RedisStorage) PushTask(t *Task) error {