From 21575ef78212b9189aec8a171b683c65f8bbcf71 Mon Sep 17 00:00:00 2001 From: rbarrabe Date: Fri, 25 Nov 2016 16:43:47 +0100 Subject: [PATCH 1/3] Update action.go --- engine/action.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/action.go b/engine/action.go index a2fc70e3b..e0ec37060 100644 --- a/engine/action.go +++ b/engine/action.go @@ -750,7 +750,7 @@ func (apl Actions) Sort() { } func (apl *Actions) Clone() (interface{}, error) { - cln := new(Actions) + //cln := new(Actions) if err := utils.Clone(*apl, cln); err != nil { return nil, err } From 0e306e59b87299c33e3b94f4ab590fbabe5e3af7 Mon Sep 17 00:00:00 2001 From: Regis Date: Fri, 25 Nov 2016 17:31:44 +0100 Subject: [PATCH 2/3] Cloned actions --- engine/action.go | 9 +++++---- engine/actions_test.go | 8 +++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/engine/action.go b/engine/action.go index e0ec37060..f15c58846 100644 --- a/engine/action.go +++ b/engine/action.go @@ -749,10 +749,11 @@ func (apl Actions) Sort() { sort.Sort(apl) } -func (apl *Actions) Clone() (interface{}, error) { - //cln := new(Actions) - if err := utils.Clone(*apl, cln); err != nil { +func (apl Actions) Clone() (Actions, error) { + + var cln Actions + if err := utils.Clone(apl, &cln); err != nil { return nil, err } - return interface{}(cln), nil + return cln, nil } diff --git a/engine/actions_test.go b/engine/actions_test.go index fa985e4e5..5bd3bc81f 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -2338,7 +2338,7 @@ func TestClonedAction(t *testing.T) { } func TestClonedActions(t *testing.T) { - actions := &Actions{ + actions := Actions{ &Action{ Id: "RECUR_FOR_V3HSILLMILLD1G", ActionType: TOPUP, @@ -2367,10 +2367,8 @@ func TestClonedActions(t *testing.T) { t.Error("error cloning actions: ", err) } - clonedActions := clone.(*Actions) - - if !reflect.DeepEqual(actions, clonedActions) { - t.Error("error cloning actions: ", utils.ToIJSON(clonedActions)) + if !reflect.DeepEqual(actions, clone) { + t.Error("error cloning actions: ", utils.ToIJSON(clone)) } } From d66fee84038eeb2a58c5c00407afb18e6b3316a1 Mon Sep 17 00:00:00 2001 From: Regis Date: Fri, 25 Nov 2016 17:55:14 +0100 Subject: [PATCH 3/3] TestCacheGetClonedActions --- engine/action.go | 2 +- engine/actions_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/engine/action.go b/engine/action.go index f15c58846..786039602 100644 --- a/engine/action.go +++ b/engine/action.go @@ -749,7 +749,7 @@ func (apl Actions) Sort() { sort.Sort(apl) } -func (apl Actions) Clone() (Actions, error) { +func (apl *Actions) Clone() (interface{}, error) { var cln Actions if err := utils.Clone(apl, &cln); err != nil { diff --git a/engine/actions_test.go b/engine/actions_test.go index 5bd3bc81f..4503a97f0 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -2373,6 +2373,43 @@ func TestClonedActions(t *testing.T) { } +/** +func TestCacheGetClonedActions(t *testing.T) { + actions := Actions{ + &Action{ + Id: "RECUR_FOR_V3HSILLMILLD1G", + ActionType: TOPUP, + Balance: &BalanceFilter{ + ID: utils.StringPointer("*default"), + Value: &utils.ValueFormula{Static: 1}, + Type: utils.StringPointer(utils.MONETARY), + }, + Weight: float64(30), + }, + &Action{ + Id: "RECUR_FOR_V3HSILLMILLD5G", + ActionType: DEBIT, + Balance: &BalanceFilter{ + ID: utils.StringPointer("*default"), + Value: &utils.ValueFormula{Static: 2}, + Type: utils.StringPointer(utils.MONETARY), + }, + Weight: float64(20), + }, + } + cache.Set("MYTEST", actions, true, "") + clned, err := cache.GetCloned("MYTEST") + if err != nil { + t.Error(err) + } + aCloned := clned.(Actions) + if !reflect.DeepEqual(actions, aCloned) { + t.Errorf("Expecting: %+v, received: %+v", actions, aCloned) + } +} + +*/ + /**************** Benchmarks ********************************/ func BenchmarkUUID(b *testing.B) {