Initialize config defaults if missing for NewMapStorage

This commit is contained in:
DanB
2017-02-26 13:38:12 +01:00
parent 82d46c04f3
commit 7f75d2bad2
3 changed files with 28 additions and 45 deletions

View File

@@ -1213,25 +1213,24 @@ func TestActionMakeNegative(t *testing.T) {
}
}
// FixMe
// func TestRemoveAction(t *testing.T) {
// if _, err := accountingStorage.GetAccount("cgrates.org:remo"); err != nil {
// t.Errorf("account to be removed not found: %v", err)
// }
// a := &Action{
// ActionType: REMOVE_ACCOUNT,
// }
//
// at := &ActionTiming{
// accountIDs: utils.StringMap{"cgrates.org:remo": true},
// actions: Actions{a},
// }
// at.Execute(nil, nil)
// afterUb, err := accountingStorage.GetAccount("cgrates.org:remo")
// if err == nil || afterUb != nil {
// t.Error("error removing account: ", err, afterUb)
// }
// }
func TestRemoveAction(t *testing.T) {
if _, err := accountingStorage.GetAccount("cgrates.org:remo"); err != nil {
t.Errorf("account to be removed not found: %v", err)
}
a := &Action{
ActionType: REMOVE_ACCOUNT,
}
at := &ActionTiming{
accountIDs: utils.StringMap{"cgrates.org:remo": true},
actions: Actions{a},
}
at.Execute(nil, nil)
afterUb, err := accountingStorage.GetAccount("cgrates.org:remo")
if err == nil || afterUb != nil {
t.Error("error removing account: ", err, afterUb)
}
}
func TestTopupAction(t *testing.T) {
initialUb, _ := accountingStorage.GetAccount("vdf:minu")
@@ -2313,26 +2312,6 @@ func TestCgrRpcAction(t *testing.T) {
}
}
<<<<<<< HEAD
//FixMe
// func TestValueFormulaDebit(t *testing.T) {
// if _, err := accountingStorage.GetAccount("cgrates.org:vf"); err != nil {
// t.Errorf("account to be removed not found: %v", err)
// }
//
// at := &ActionTiming{
// accountIDs: utils.StringMap{"cgrates.org:vf": true},
// ActionsID: "VF",
// }
// at.Execute(nil, nil)
// afterUb, err := accountingStorage.GetAccount("cgrates.org:vf")
// // not an exact value, depends of month
// v := afterUb.BalanceMap[utils.MONETARY].GetTotalValue()
// if err != nil || v > -0.30 || v < -0.35 {
// t.Error("error debiting account: ", err, utils.ToIJSON(afterUb))
// }
// }
=======
func TestValueFormulaDebit(t *testing.T) {
if _, err := accountingStorage.GetAccount("cgrates.org:vf"); err != nil {
t.Errorf("account to be removed not found: %v", err)
@@ -2350,7 +2329,6 @@ func TestValueFormulaDebit(t *testing.T) {
t.Error("error debiting account: ", err, utils.ToIJSON(afterUb), v)
}
}
>>>>>>> c6d07d6701a472079c21729212dbec7ac43e9cb7
func TestClonedAction(t *testing.T) {
a := &Action{

View File

@@ -45,6 +45,10 @@ func init() {
var err error
switch DB {
case "map":
if cgrCfg := config.CgrConfig(); cgrCfg == nil {
cgrCfg, _ = config.NewDefaultCGRConfig()
config.SetCgrConfig(cgrCfg)
}
ratingStorage, _ = NewMapStorage()
accountingStorage, _ = NewMapStorage()
case utils.MONGO:

View File

@@ -71,11 +71,13 @@ func (s storage) smembers(key string, ms Marshaler) (idMap utils.StringMap, ok b
}
func NewMapStorage() (*MapStorage, error) {
return &MapStorage{dict: make(map[string][]byte), ms: NewCodecMsgpackMarshaler(), cacheCfg: &config.CacheConfig{RatingPlans: &config.CacheParamConfig{Precache: true}}}, nil
return &MapStorage{dict: make(map[string][]byte), ms: NewCodecMsgpackMarshaler(), cacheCfg: config.CgrConfig().CacheConfig}, nil
}
func NewMapStorageJson() (*MapStorage, error) {
return &MapStorage{dict: make(map[string][]byte), ms: new(JSONBufMarshaler), cacheCfg: &config.CacheConfig{RatingPlans: &config.CacheParamConfig{Precache: true}}}, nil
func NewMapStorageJson() (mpStorage *MapStorage, err error) {
mpStorage, err = NewMapStorage()
mpStorage.ms = new(JSONBufMarshaler)
return
}
func (ms *MapStorage) Close() {}
@@ -96,7 +98,7 @@ func (ms *MapStorage) SelectDatabase(dbName string) (err error) {
}
func (ms *MapStorage) RebuildReverseForPrefix(prefix string) error {
// FIXME: should do transaction
// ToDo: should do transaction
keys, err := ms.GetKeysForPrefix(prefix)
if err != nil {
return err
@@ -143,7 +145,6 @@ func (ms *MapStorage) RebuildReverseForPrefix(prefix string) error {
return nil
}
// FixMe
func (ms *MapStorage) LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs []string) error {
if ms.cacheCfg == nil {
return nil