Fix actions cloning due to bug in gob

This commit is contained in:
DanB
2017-01-19 18:09:44 +01:00
parent 6ddcbbea04
commit 6bc64c73ce
2 changed files with 26 additions and 7 deletions

View File

@@ -761,5 +761,15 @@ func (apl Actions) Clone() (interface{}, error) {
if err := utils.Clone(apl, &cln); err != nil {
return nil, err
}
for i, act := range apl { // Fix issues with gob cloning nil pointer towards false value
if act.Balance != nil {
if act.Balance.Disabled != nil && !*act.Balance.Disabled {
cln[i].Balance.Disabled = utils.BoolPointer(*act.Balance.Disabled)
}
if act.Balance.Blocker != nil && !*act.Balance.Blocker {
cln[i].Balance.Blocker = utils.BoolPointer(*act.Balance.Blocker)
}
}
}
return cln, nil
}

View File

@@ -2387,14 +2387,23 @@ func TestCacheGetClonedActions(t *testing.T) {
Weight: float64(30),
},
&Action{
Id: "RECUR_FOR_V3HSILLMILLD5G",
ActionType: DEBIT,
Id: "REACT_FOR_V3HSILLMILL",
ActionType: SET_BALANCE,
Balance: &BalanceFilter{
ID: utils.StringPointer("*default"),
Value: &utils.ValueFormula{Static: 2},
Type: utils.StringPointer(utils.MONETARY),
ID: utils.StringPointer("for_v3hsillmill_sms_ill"),
Type: utils.StringPointer(utils.SMS),
Value: &utils.ValueFormula{Static: 20000},
DestinationIDs: &utils.StringMap{
"FRANCE_NATIONAL": true,
"FRANCE_NATIONAL_FREE": false,
"ZONE1": false},
Categories: &utils.StringMap{
"sms_eurotarif": true,
"sms_france": true},
Disabled: utils.BoolPointer(false),
Blocker: utils.BoolPointer(false),
},
Weight: float64(20),
Weight: float64(10),
},
}
cache.Set("MYTEST", actions, true, "")
@@ -2404,7 +2413,7 @@ func TestCacheGetClonedActions(t *testing.T) {
}
aCloned := clned.(Actions)
if !reflect.DeepEqual(actions, aCloned) {
t.Errorf("Expecting: %+v, received: %+v", actions, aCloned)
t.Errorf("Expecting: %+v, received: %+v", actions[1].Balance, aCloned[1].Balance)
}
}