diff --git a/engine/action.go b/engine/action.go index dc43cbfe5..d2f4cf85a 100644 --- a/engine/action.go +++ b/engine/action.go @@ -749,9 +749,10 @@ func (apl Actions) Sort() { } func (apl *Actions) Clone() (interface{}, error) { - cln := new(Actions) - if err := utils.Clone(*apl, cln); err != nil { + + 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..4503a97f0 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,14 +2367,49 @@ 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)) } } +/** +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) {