From 3a64f321eb0a4fc3089561790c1bbdfbcceb4ec7 Mon Sep 17 00:00:00 2001 From: adragusin Date: Thu, 7 Nov 2019 13:59:20 +0200 Subject: [PATCH] Added test for ActionTiming.Tasks --- engine/action_plan.go | 1 + engine/action_plan_test.go | 24 ++++++++++++++++++++++++ engine/actions_test.go | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/engine/action_plan.go b/engine/action_plan.go index e1220ef96..a2756e66c 100644 --- a/engine/action_plan.go +++ b/engine/action_plan.go @@ -62,6 +62,7 @@ func (at *ActionTiming) Tasks() (tsks []*Task) { ActionsID: at.ActionsID, AccountID: acntID, } + i++ } return } diff --git a/engine/action_plan_test.go b/engine/action_plan_test.go index 8e3a3d496..9a51ebab2 100644 --- a/engine/action_plan_test.go +++ b/engine/action_plan_test.go @@ -19,11 +19,35 @@ package engine import ( "reflect" + "sort" "testing" "github.com/cgrates/cgrates/utils" ) +func TestActionTimingTasks(t *testing.T) { + //empty check + actionTiming := new(ActionTiming) + eOut := []*Task{&Task{Uuid: "", ActionsID: ""}} + rcv := actionTiming.Tasks() + if !reflect.DeepEqual(eOut, rcv) { + t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) + } + //multiple check + actionTiming.ActionsID = "test" + actionTiming.Uuid = "test" + actionTiming.accountIDs = utils.StringMap{"1001": true, "1002": true, "1003": true} + eOut = []*Task{ + &Task{Uuid: "test", AccountID: "1001", ActionsID: "test"}, + &Task{Uuid: "test", AccountID: "1002", ActionsID: "test"}, + &Task{Uuid: "test", AccountID: "1003", ActionsID: "test"}, + } + rcv = actionTiming.Tasks() + sort.Slice(rcv, func(i, j int) bool { return rcv[i].AccountID < rcv[j].AccountID }) + if !reflect.DeepEqual(eOut, rcv) { + t.Errorf("Expecting: %+v, received: %+v", eOut, rcv) + } +} func TestActionPlanClone(t *testing.T) { at1 := &ActionPlan{ Id: "test", diff --git a/engine/actions_test.go b/engine/actions_test.go index fd01b7820..eaf6c33cd 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -445,7 +445,7 @@ func TestActionPlanFunctionNotAvailable(t *testing.T) { actions: []*Action{a}, } err := at.Execute(nil, nil) - if err != utils.ErrPartiallyExecuted { // because we want to return err if we can't execute all actions + if err != utils.ErrPartiallyExecuted { // because we want to return err if we can't execute all actions t.Errorf("Faild to detect wrong function type: %v", err) } }