From bf8e6c6c5a22895971081c1656734c2f93e59fb7 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 23 Oct 2015 15:43:52 +0300 Subject: [PATCH] more test fixes --- apier/v1/scheduler.go | 14 +++++--------- console/action_execute.go | 4 ++-- engine/action.go | 6 +++--- general_tests/tutorial_local_test.go | 4 ++-- utils/apitpdata.go | 12 ++++++------ 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/apier/v1/scheduler.go b/apier/v1/scheduler.go index 216feb41a..ec02807a5 100644 --- a/apier/v1/scheduler.go +++ b/apier/v1/scheduler.go @@ -98,14 +98,14 @@ import ( */ type AttrsGetScheduledActions struct { - Direction, Tenant, Account string - TimeStart, TimeEnd time.Time // Filter based on next runTime + Tenant, Account string + TimeStart, TimeEnd time.Time // Filter based on next runTime utils.Paginator } type ScheduledActions struct { NextRunTime time.Time - Accounts []*utils.DirectionTenantAccount + Accounts []*utils.TenantAccount ActionsId, ActionPlanId, ActionPlanUuid string } @@ -142,22 +142,18 @@ func (self *ApierV1) GetScheduledActions(attrs AttrsGetScheduledActions, reply * } acntFiltersMatch := false for _, acntKey := range qActions.AccountIds { - directionMatched := len(attrs.Direction) == 0 tenantMatched := len(attrs.Tenant) == 0 accountMatched := len(attrs.Account) == 0 - dta, _ := utils.NewDTAFromAccountKey(acntKey) + dta, _ := utils.NewTAFromAccountKey(acntKey) sas.Accounts = append(sas.Accounts, dta) // One member matching - if !directionMatched && attrs.Direction == dta.Direction { - directionMatched = true - } if !tenantMatched && attrs.Tenant == dta.Tenant { tenantMatched = true } if !accountMatched && attrs.Account == dta.Account { accountMatched = true } - if directionMatched && tenantMatched && accountMatched { + if tenantMatched && accountMatched { acntFiltersMatch = true } } diff --git a/console/action_execute.go b/console/action_execute.go index 15ee3838c..52eb40fe6 100644 --- a/console/action_execute.go +++ b/console/action_execute.go @@ -26,7 +26,7 @@ func init() { c := &CmdExecuteAction{ name: "action_execute", rpcMethod: "ApierV1.ExecuteAction", - rpcParams: &utils.AttrExecuteAction{Direction: utils.OUT}, + rpcParams: &utils.AttrExecuteAction{}, } commands[c.Name()] = c c.CommandExecuter = &CommandExecuter{c} @@ -50,7 +50,7 @@ func (self *CmdExecuteAction) RpcMethod() string { func (self *CmdExecuteAction) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = &utils.AttrExecuteAction{Direction: utils.OUT} + self.rpcParams = &utils.AttrExecuteAction{} } return self.rpcParams } diff --git a/engine/action.go b/engine/action.go index 861788953..8eae10d38 100644 --- a/engine/action.go +++ b/engine/action.go @@ -146,9 +146,9 @@ func logAction(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions) (er // Used by cdrLogAction to dynamically parse values out of account and action func parseTemplateValue(rsrFlds utils.RSRFields, acnt *Account, action *Action) string { - dta, err := utils.NewDTAFromAccountKey(acnt.Id) // Account information should be valid + dta, err := utils.NewTAFromAccountKey(acnt.Id) // Account information should be valid if err != nil { - dta = new(utils.DirectionTenantAccount) // Init with empty values + dta = new(utils.TenantAccount) // Init with empty values } var parsedValue string // Template values for _, rsrFld := range rsrFlds { @@ -156,7 +156,7 @@ func parseTemplateValue(rsrFlds utils.RSRFields, acnt *Account, action *Action) case "account_id": parsedValue += rsrFld.ParseValue(acnt.Id) case "direction": - parsedValue += rsrFld.ParseValue(dta.Direction) + parsedValue += rsrFld.ParseValue(action.Balance.Directions.String()) case "tenant": parsedValue += rsrFld.ParseValue(dta.Tenant) case "account": diff --git a/general_tests/tutorial_local_test.go b/general_tests/tutorial_local_test.go index 2c72e35de..a3ef716fc 100644 --- a/general_tests/tutorial_local_test.go +++ b/general_tests/tutorial_local_test.go @@ -1105,7 +1105,7 @@ func TestTutLocalSetAccount(t *testing.T) { t.Errorf("Accounts received: %+v", acnts) } else { acnt := acnts[0] - dta, _ := utils.NewDTAFromAccountKey(acnt.Id) + dta, _ := utils.NewTAFromAccountKey(acnt.Id) if dta.Tenant != attrs.Tenant || dta.Account != attrs.Account { t.Error("Unexpected account id received: ", acnt.Id) } @@ -1134,7 +1134,7 @@ func TestTutLocalSetAccount(t *testing.T) { t.Errorf("Accounts received: %+v", acnts) } else { acnt := acnts[0] - dta, _ := utils.NewDTAFromAccountKey(acnt.Id) + dta, _ := utils.NewTAFromAccountKey(acnt.Id) if dta.Tenant != attrs.Tenant || dta.Account != attrs.Account { t.Error("Unexpected account id received: ", acnt.Id) } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index b73c5eb27..b6dbe0b4f 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -804,16 +804,16 @@ type AttrDerivedChargers struct { Direction, Tenant, Category, Account, Subject string } -func NewDTAFromAccountKey(accountKey string) (*DirectionTenantAccount, error) { +func NewTAFromAccountKey(accountKey string) (*TenantAccount, error) { accountSplt := strings.Split(accountKey, CONCATENATED_KEY_SEP) - if len(accountSplt) != 3 { - return nil, fmt.Errorf("Unsupported format for DirectionTenantAccount: %s", accountKey) + if len(accountSplt) != 2 { + return nil, fmt.Errorf("Unsupported format for TenantAccount: %s", accountKey) } - return &DirectionTenantAccount{accountSplt[0], accountSplt[1], accountSplt[2]}, nil + return &TenantAccount{accountSplt[0], accountSplt[1]}, nil } -type DirectionTenantAccount struct { - Direction, Tenant, Account string +type TenantAccount struct { + Tenant, Account string } func NewDTCSFromRPKey(rpKey string) (*DirectionTenantCategorySubject, error) {