From 6bc64c73cedca4b8cc76105ab6257681e4fc71ec Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 19 Jan 2017 18:09:44 +0100 Subject: [PATCH] Fix actions cloning due to bug in gob --- engine/action.go | 10 ++++++++++ engine/actions_test.go | 23 ++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/engine/action.go b/engine/action.go index fcabe7f4b..e4d83ba4f 100644 --- a/engine/action.go +++ b/engine/action.go @@ -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 } diff --git a/engine/actions_test.go b/engine/actions_test.go index 0c0e46433..118cda4a2 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -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) } }