GetClone for actions

This commit is contained in:
Regis
2016-11-25 13:56:16 +01:00
parent 73d8147a56
commit d3f71279c4
2 changed files with 68 additions and 9 deletions

View File

@@ -81,15 +81,9 @@ const (
)
func (a *Action) Clone() *Action {
return &Action{
Id: a.Id,
ActionType: a.ActionType,
//BalanceType: a.BalanceType,
ExtraParameters: a.ExtraParameters,
ExpirationString: a.ExpirationString,
Weight: a.Weight,
Balance: a.Balance,
}
var clonedAction Action
utils.Clone(a, &clonedAction)
return &clonedAction
}
type actionTypeFunc func(*Account, *StatsQueueTriggered, *Action, Actions) error
@@ -754,3 +748,11 @@ func (apl Actions) Less(j, i int) bool {
func (apl Actions) Sort() {
sort.Sort(apl)
}
func (apl *Actions) Clone() (interface{}, error) {
cln := new(Actions)
if err := utils.Clone(*apl, cln); err != nil {
return nil, err
}
return interface{}(cln), nil
}

View File

@@ -2318,6 +2318,63 @@ func TestValueFormulaDebit(t *testing.T) {
}
}
func TestClonedAction(t *testing.T) {
a := &Action{
Id: "test1",
ActionType: TOPUP,
Balance: &BalanceFilter{
ID: utils.StringPointer("*default"),
Value: &utils.ValueFormula{Static: 1},
Type: utils.StringPointer(utils.MONETARY),
},
Weight: float64(10),
}
clone := a.Clone()
if !reflect.DeepEqual(a, clone) {
t.Error("error cloning action: ", utils.ToIJSON(clone))
}
}
func TestClonedActions(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),
},
}
clone, err := actions.Clone()
if err != nil {
t.Error("error cloning actions: ", err)
}
clonedActions := clone.(*Actions)
if !reflect.DeepEqual(actions, clonedActions) {
t.Error("error cloning actions: ", utils.ToIJSON(clonedActions))
}
}
/**************** Benchmarks ********************************/
func BenchmarkUUID(b *testing.B) {