diff --git a/apier/v1/accounts_it_test.go b/apier/v1/accounts_it_test.go index 90ec122a3..66a711d59 100644 --- a/apier/v1/accounts_it_test.go +++ b/apier/v1/accounts_it_test.go @@ -1166,10 +1166,10 @@ func testAccITAccountMonthlyEstimated(t *testing.T) { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } - atms1 := &AttrSetActionPlan{ + atms1 := &engine.AttrSetActionPlan{ Id: "ATMS_1", ReloadScheduler: true, - ActionPlan: []*AttrActionPlan{{ + ActionPlan: []*engine.AttrActionPlan{{ ActionsId: "TOPUP_ACTION", MonthDays: "31", Time: "23:59:59", diff --git a/apier/v1/analyzer_test.go b/apier/v1/analyzer_test.go index 3c036bcd8..08401563f 100644 --- a/apier/v1/analyzer_test.go +++ b/apier/v1/analyzer_test.go @@ -34,35 +34,3 @@ func TestNewAnalyzerSv1(t *testing.T) { t.Errorf("expected AnalyzerService to be %v, got %v", analyzerService, analyzerSv1.aS) } } - -func TestVerifyFormat(t *testing.T) { - tests := []struct { - tStr string - expectedBool bool - }{ - - {"12:34:56", true}, - {"23:59:59", true}, - {"12:34", false}, - {"12:34:56:78", false}, - {"12:abc:56", false}, - {"123:456:789", false}, - {"00:00:00", true}, - {"12:34:56", true}, - {"t:01:t", false}, - {"1,1,1", false}, - {"0:0:0", true}, - {"119911", false}, - {"00/01/03", false}, - {"t1:t2:t3", false}, - } - - for _, tt := range tests { - t.Run(tt.tStr, func(t *testing.T) { - result := verifyFormat(tt.tStr) - if result != tt.expectedBool { - t.Errorf("verifyFormat(%q) = %v; want %v", tt.tStr, result, tt.expectedBool) - } - }) - } -} diff --git a/apier/v1/apier2_it_test.go b/apier/v1/apier2_it_test.go index 928abab12..0d294de0c 100644 --- a/apier/v1/apier2_it_test.go +++ b/apier/v1/apier2_it_test.go @@ -340,9 +340,9 @@ func testAPIerGetRatingPlanIDs(t *testing.T) { func testAPIerSetActionPlanDfltTime(t *testing.T) { var reply1 string - hourlyAP := &AttrSetActionPlan{ + hourlyAP := &engine.AttrSetActionPlan{ Id: "AP_HOURLY", - ActionPlan: []*AttrActionPlan{ + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "ACT_TOPUP_RST_10", Time: utils.MetaHourly, @@ -356,9 +356,9 @@ func testAPIerSetActionPlanDfltTime(t *testing.T) { } else if reply1 != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1) } - dailyAP := &AttrSetActionPlan{ + dailyAP := &engine.AttrSetActionPlan{ Id: "AP_DAILY", - ActionPlan: []*AttrActionPlan{ + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "ACT_TOPUP_RST_10", Time: utils.MetaDaily, @@ -372,9 +372,9 @@ func testAPIerSetActionPlanDfltTime(t *testing.T) { } else if reply1 != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1) } - weeklyAP := &AttrSetActionPlan{ + weeklyAP := &engine.AttrSetActionPlan{ Id: "AP_WEEKLY", - ActionPlan: []*AttrActionPlan{ + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "ACT_TOPUP_RST_10", Time: utils.MetaWeekly, @@ -388,9 +388,9 @@ func testAPIerSetActionPlanDfltTime(t *testing.T) { } else if reply1 != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1) } - monthlyAP := &AttrSetActionPlan{ + monthlyAP := &engine.AttrSetActionPlan{ Id: "AP_MONTHLY", - ActionPlan: []*AttrActionPlan{ + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "ACT_TOPUP_RST_10", Time: utils.MetaMonthly, diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index e70fbdbd4..3ed8c540f 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -1295,8 +1295,8 @@ func testApierGetActions(t *testing.T) { } func testApierSetActionPlan(t *testing.T) { - atm1 := &AttrActionPlan{ActionsId: "ACTS_1", MonthDays: "1", Time: "00:00:00", Weight: 20.0} - atms1 := &AttrSetActionPlan{Id: "ATMS_1", ActionPlan: []*AttrActionPlan{atm1}} + atm1 := &engine.AttrActionPlan{ActionsId: "ACTS_1", MonthDays: "1", Time: "00:00:00", Weight: 20.0} + atms1 := &engine.AttrSetActionPlan{Id: "ATMS_1", ActionPlan: []*engine.AttrActionPlan{atm1}} reply1 := utils.EmptyString if err := rater.Call(context.Background(), utils.APIerSv1SetActionPlan, &atms1, &reply1); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) diff --git a/apier/v1/apier_test.go b/apier/v1/apier_test.go index ee727c601..2eb959f16 100644 --- a/apier/v1/apier_test.go +++ b/apier/v1/apier_test.go @@ -26,40 +26,6 @@ import ( "github.com/cgrates/cgrates/utils" ) -func TestCheckDefaultTiming(t *testing.T) { - tests := []struct { - name string - tStr string - wantID string - wantIsDef bool - }{ - {"Every Minute", utils.MetaEveryMinute, utils.MetaEveryMinute, true}, - {"Hourly", utils.MetaHourly, utils.MetaHourly, true}, - {"Daily", utils.MetaDaily, utils.MetaDaily, true}, - {"Weekly", utils.MetaWeekly, utils.MetaWeekly, true}, - {"Monthly", utils.MetaMonthly, utils.MetaMonthly, true}, - {"Monthly Estimated", utils.MetaMonthlyEstimated, utils.MetaMonthlyEstimated, true}, - {"Month End", utils.MetaMonthEnd, utils.MetaMonthEnd, true}, - {"Yearly", utils.MetaYearly, utils.MetaYearly, true}, - {"Unknown", "unknown", "", false}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, isDef := checkDefaultTiming(tt.tStr) - if isDef != tt.wantIsDef { - t.Errorf("checkDefaultTiming(%q) isDefault = %v, want %v", tt.tStr, isDef, tt.wantIsDef) - } - if isDef && got.ID != tt.wantID { - t.Errorf("checkDefaultTiming(%q) got.ID = %v, want %v", tt.tStr, got.ID, tt.wantID) - } - if !isDef && got != nil { - t.Errorf("checkDefaultTiming(%q) expected nil, got non-nil", tt.tStr) - } - }) - } -} - func TestGetId(t *testing.T) { tests := []struct { name string diff --git a/apier/v1/replicate_it_test.go b/apier/v1/replicate_it_test.go index 1fe350fc9..79cde19c4 100644 --- a/apier/v1/replicate_it_test.go +++ b/apier/v1/replicate_it_test.go @@ -911,9 +911,9 @@ func testInternalReplicateITActionPlan(t *testing.T) { t.Errorf("Error at APIerSv1.GetActionPlan: %+v", err) } // set - atms1 := &AttrSetActionPlan{ + atms1 := &engine.AttrSetActionPlan{ Id: "ATMS_1", - ActionPlan: []*AttrActionPlan{ + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "ACTS_1", Time: utils.MetaASAP, diff --git a/apier/v1/schedulers_it_test.go b/apier/v1/schedulers_it_test.go index 047d2dbe2..bd0ca03a4 100644 --- a/apier/v1/schedulers_it_test.go +++ b/apier/v1/schedulers_it_test.go @@ -280,9 +280,9 @@ func testSchedExecuteAction(t *testing.T) { } // set a new ActionPlan var reply1 string - if err := schedRpc.Call(context.Background(), utils.APIerSv1SetActionPlan, &AttrSetActionPlan{ + if err := schedRpc.Call(context.Background(), utils.APIerSv1SetActionPlan, &engine.AttrSetActionPlan{ Id: "CustomAP", - ActionPlan: []*AttrActionPlan{ + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "ACT_TOPUP_RST_10", Time: utils.MetaHourly, diff --git a/apier/v2/accounts_it_test.go b/apier/v2/accounts_it_test.go index 474c43296..290f3174b 100644 --- a/apier/v2/accounts_it_test.go +++ b/apier/v2/accounts_it_test.go @@ -141,9 +141,9 @@ func testApierSetActions(t *testing.T) { func testAccountsSetActPlans(t *testing.T) { var reply string - if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &v1.AttrSetActionPlan{ + if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &engine.AttrSetActionPlan{ Id: "TestAccountAP1", - ActionPlan: []*v1.AttrActionPlan{{ + ActionPlan: []*engine.AttrActionPlan{{ ActionsId: "TestAccountAction", MonthDays: "1", Time: "00:00:00", @@ -154,9 +154,9 @@ func testAccountsSetActPlans(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply) } - if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &v1.AttrSetActionPlan{ + if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &engine.AttrSetActionPlan{ Id: "TestAccountAP2", - ActionPlan: []*v1.AttrActionPlan{{ + ActionPlan: []*engine.AttrActionPlan{{ ActionsId: "TestAccountAction", MonthDays: "2", Time: "00:00:00", @@ -167,9 +167,9 @@ func testAccountsSetActPlans(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply) } - if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &v1.AttrSetActionPlan{ + if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &engine.AttrSetActionPlan{ Id: "TestAccountAP3", - ActionPlan: []*v1.AttrActionPlan{{ + ActionPlan: []*engine.AttrActionPlan{{ ActionsId: "TestAccountAction", MonthDays: "2", Time: "00:00:00", @@ -184,7 +184,7 @@ func testAccountsSetActPlans(t *testing.T) { func testAccountsSet1(t *testing.T) { var reply string - if err := accRPC.Call(context.Background(), utils.APIerSv2SetAccount, AttrSetAccount{ + if err := accRPC.Call(context.Background(), utils.APIerSv2SetAccount, engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "dan", ReloadScheduler: true, @@ -195,7 +195,7 @@ func testAccountsSet1(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetAccount received: %s", reply) } - if err := accRPC.Call(context.Background(), utils.APIerSv2SetAccount, AttrSetAccount{ + if err := accRPC.Call(context.Background(), utils.APIerSv2SetAccount, engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "dan2", ReloadScheduler: true, @@ -228,7 +228,7 @@ func testAccountsGetActionPlan1(t *testing.T) { func testAccountsSet2(t *testing.T) { var reply string - if err := accRPC.Call(context.Background(), utils.APIerSv2SetAccount, AttrSetAccount{ + if err := accRPC.Call(context.Background(), utils.APIerSv2SetAccount, engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "dan", ReloadScheduler: true, diff --git a/apier/v2/apierv2_it_test.go b/apier/v2/apierv2_it_test.go index fa25b9141..439353743 100644 --- a/apier/v2/apierv2_it_test.go +++ b/apier/v2/apierv2_it_test.go @@ -228,7 +228,7 @@ func testAPIerSv2itFraudMitigation(t *testing.T) { } else if !acnt.Disabled { t.Fatalf("Received account: %+v", acnt) } - attrSetAcnt := &AttrSetAccount{ + attrSetAcnt := &engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "dan", ExtraOptions: map[string]bool{ @@ -259,8 +259,8 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { t.Error(err) } tNow := time.Now().Add(time.Minute) - argAP1 := &v1.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAP_AP_1", - ActionPlan: []*v1.AttrActionPlan{ + argAP1 := &engine.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAP_AP_1", + ActionPlan: []*engine.AttrActionPlan{ {ActionsId: argActs1.ActionsId, Time: fmt.Sprintf("%v:%v:%v", tNow.Hour(), tNow.Minute(), tNow.Second()), // 10:4:12 Weight: 20.0}}} @@ -272,7 +272,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply) } - argSetAcnt1 := AttrSetAccount{ + argSetAcnt1 := engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "TestAPIerSv2itSetAccountWithAP1", ActionPlanIDs: []string{argAP1.Id}, @@ -296,8 +296,8 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", eAAPids, aapIDs) } // Set second AP so we can see the proper indexing done - argAP2 := &v1.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAP_AP_2", - ActionPlan: []*v1.AttrActionPlan{ + argAP2 := &engine.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAP_AP_2", + ActionPlan: []*engine.AttrActionPlan{ {ActionsId: argActs1.ActionsId, MonthDays: "1", Time: "00:00:00", Weight: 20.0}}} if _, err := dm.GetActionPlan(argAP2.Id, false, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound { t.Error(err) @@ -308,7 +308,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { t.Errorf("Calling APIerSv2.SetActionPlan received: %s", reply) } // Test adding new AP - argSetAcnt2 := AttrSetAccount{ + argSetAcnt2 := engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "TestAPIerSv2itSetAccountWithAP1", ActionPlanIDs: []string{argAP2.Id}, @@ -333,7 +333,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", eAAPids, aapIDs) } // test remove and overwrite - argSetAcnt2 = AttrSetAccount{ + argSetAcnt2 = engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "TestAPIerSv2itSetAccountWithAP1", ActionPlanIDs: []string{argAP2.Id}, @@ -401,8 +401,8 @@ func testAPIerSv2itSetActionWithCategory(t *testing.T) { func testAPIerSv2itSetActionPlanWithWrongTiming(t *testing.T) { var reply string tNow := time.Now().Add(time.Minute).String() - argAP1 := &v1.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAPWithWrongTiming", - ActionPlan: []*v1.AttrActionPlan{ + argAP1 := &engine.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAPWithWrongTiming", + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "TestAPIerSv2itSetAccountWithAP_ACT_1", Time: tNow, @@ -419,8 +419,8 @@ func testAPIerSv2itSetActionPlanWithWrongTiming(t *testing.T) { func testAPIerSv2itSetActionPlanWithWrongTiming2(t *testing.T) { var reply string - argAP1 := &v1.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAPWithWrongTiming", - ActionPlan: []*v1.AttrActionPlan{ + argAP1 := &engine.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAPWithWrongTiming", + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "TestAPIerSv2itSetAccountWithAP_ACT_1", Time: "aa:bb:cc", @@ -469,7 +469,7 @@ func testAPIerSv2itGetAccountsCount(t *testing.T) { Tenant: "cgrates.org"}, &reply1); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting %+v, received: %+v", utils.ErrNotFound, err) } - argSetAccount := AttrSetAccount{ + argSetAccount := engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "TestAPIerSv2CountAccounts", } @@ -486,7 +486,7 @@ func testAPIerSv2itGetAccountsCount(t *testing.T) { } else if reply1 != 1 { t.Errorf("Expecting: 1, received: %+v", reply1) } - argSetAccount = AttrSetAccount{ + argSetAccount = engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "TestAPIerSv2CountAccounts2", } diff --git a/apier/v2/cdrs_it_test.go b/apier/v2/cdrs_it_test.go index be6d826ee..25f99aa20 100644 --- a/apier/v2/cdrs_it_test.go +++ b/apier/v2/cdrs_it_test.go @@ -750,7 +750,7 @@ func testV2CDRsSetThreshold(t *testing.T) { } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } - attrSetAcnt := AttrSetAccount{ + attrSetAcnt := engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "1005", ExtraOptions: map[string]bool{ @@ -883,7 +883,7 @@ func testV2CDRsRerate(t *testing.T) { t.Error("Unexpected reply returned", reply) } - attrSetAcnt := AttrSetAccount{ + attrSetAcnt := engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "voiceAccount", } @@ -1049,7 +1049,7 @@ func testV2CDRsDuplicateCDRs(t *testing.T) { t.Error("Unexpected reply returned", reply) } - attrSetAcnt := AttrSetAccount{ + attrSetAcnt := engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "testV2CDRsDuplicateCDRs", } diff --git a/apier/v2/cdrs_offline_it_test.go b/apier/v2/cdrs_offline_it_test.go index 7ee426b19..8d7b760c7 100644 --- a/apier/v2/cdrs_offline_it_test.go +++ b/apier/v2/cdrs_offline_it_test.go @@ -29,7 +29,6 @@ import ( "github.com/cgrates/birpc/context" "github.com/cgrates/birpc" - v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -232,8 +231,8 @@ func testV2CDRsOfflineExpiryBalance(t *testing.T) { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } - atm1 := &v1.AttrActionPlan{ActionsId: "ACT_TOPUP_TEST2", Time: "*asap", Weight: 20.0} - atms1 := &v1.AttrSetActionPlan{Id: "AP_TEST2", ActionPlan: []*v1.AttrActionPlan{atm1}} + atm1 := &engine.AttrActionPlan{ActionsId: "ACT_TOPUP_TEST2", Time: "*asap", Weight: 20.0} + atms1 := &engine.AttrSetActionPlan{Id: "AP_TEST2", ActionPlan: []*engine.AttrActionPlan{atm1}} if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv1SetActionPlan, &atms1, &reply); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply != utils.OK { @@ -241,7 +240,7 @@ func testV2CDRsOfflineExpiryBalance(t *testing.T) { } if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2SetAccount, - &AttrSetAccount{Tenant: "cgrates.org", Account: "test2", + &engine.AttrSetAccount{Tenant: "cgrates.org", Account: "test2", ActionPlanIDs: []string{"AP_TEST2"}, ReloadScheduler: true}, &reply); err != nil { t.Error(err) diff --git a/engine/action_plan_test.go b/engine/action_plan_test.go index cfee9a110..569205f64 100644 --- a/engine/action_plan_test.go +++ b/engine/action_plan_test.go @@ -702,3 +702,69 @@ func TestActionTimingGetNextStartTimesMonthlyEstimated(t *testing.T) { }) } } + +func TestVerifyFormat(t *testing.T) { + tests := []struct { + tStr string + expectedBool bool + }{ + + {"12:34:56", true}, + {"23:59:59", true}, + {"12:34", false}, + {"12:34:56:78", false}, + {"12:abc:56", false}, + {"123:456:789", false}, + {"00:00:00", true}, + {"12:34:56", true}, + {"t:01:t", false}, + {"1,1,1", false}, + {"0:0:0", true}, + {"119911", false}, + {"00/01/03", false}, + {"t1:t2:t3", false}, + } + + for _, tt := range tests { + t.Run(tt.tStr, func(t *testing.T) { + result := verifyFormat(tt.tStr) + if result != tt.expectedBool { + t.Errorf("verifyFormat(%q) = %v; want %v", tt.tStr, result, tt.expectedBool) + } + }) + } +} + +func TestCheckDefaultTiming(t *testing.T) { + tests := []struct { + name string + tStr string + wantID string + wantIsDef bool + }{ + {"Every Minute", utils.MetaEveryMinute, utils.MetaEveryMinute, true}, + {"Hourly", utils.MetaHourly, utils.MetaHourly, true}, + {"Daily", utils.MetaDaily, utils.MetaDaily, true}, + {"Weekly", utils.MetaWeekly, utils.MetaWeekly, true}, + {"Monthly", utils.MetaMonthly, utils.MetaMonthly, true}, + {"Monthly Estimated", utils.MetaMonthlyEstimated, utils.MetaMonthlyEstimated, true}, + {"Month End", utils.MetaMonthEnd, utils.MetaMonthEnd, true}, + {"Yearly", utils.MetaYearly, utils.MetaYearly, true}, + {"Unknown", "unknown", "", false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, isDef := checkDefaultTiming(tt.tStr) + if isDef != tt.wantIsDef { + t.Errorf("checkDefaultTiming(%q) isDefault = %v, want %v", tt.tStr, isDef, tt.wantIsDef) + } + if isDef && got.ID != tt.wantID { + t.Errorf("checkDefaultTiming(%q) got.ID = %v, want %v", tt.tStr, got.ID, tt.wantID) + } + if !isDef && got != nil { + t.Errorf("checkDefaultTiming(%q) expected nil, got non-nil", tt.tStr) + } + }) + } +} diff --git a/engine/actions_test.go b/engine/actions_test.go index a171da6dc..12e47aaf3 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -4843,7 +4843,7 @@ func TestActionsAlterAndDisconnectSessions(t *testing.T) { { name: "WrongNumberOfParams", extraParams: "tenant;;1;", - expectedErr: "invalid number of parameters; expected 5", + expectedErr: "invalid number of parameters <4> expected 5", }, { name: "InvalidEventMap", @@ -5044,7 +5044,7 @@ func TestDynamicThreshold(t *testing.T) { { name: "WrongNumberOfParams", extraParams: "tenant;;1;", - expectedErr: "invalid number of parameters; expected 12", + expectedErr: "invalid number of parameters <4> expected 12", }, { name: "ActivationIntervalLengthFail", @@ -5291,7 +5291,7 @@ func TestDynamicStats(t *testing.T) { { name: "WrongNumberOfParams", extraParams: "tenant;;1;", - expectedErr: "invalid number of parameters; expected 14", + expectedErr: "invalid number of parameters <4> expected 14", }, { name: "ActivationIntervalLengthFail", @@ -5514,7 +5514,7 @@ func TestDynamicAttribute(t *testing.T) { { name: "WrongNumberOfParams", extraParams: "tenant;;1;", - expectedErr: "invalid number of parameters; expected 12", + expectedErr: "invalid number of parameters <4> expected 12", }, { name: "ActivationIntervalLengthFail", @@ -5600,3 +5600,463 @@ func TestDynamicAttribute(t *testing.T) { }) } } + +func TestDynamicActionPlan(t *testing.T) { + tempConn := connMgr + tmpDm := dm + tmpCache := Cache + defer func() { + config.SetCgrConfig(config.NewDefaultCGRConfig()) + SetConnManager(tempConn) + dm = tmpDm + Cache = tmpCache + }() + Cache.Clear(nil) + var ap *AttrSetActionPlan + ccMock := &ccMock{ + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.APIerSv1SetActionPlan: func(ctx *context.Context, args, reply any) error { + var canCast bool + if ap, canCast = args.(*AttrSetActionPlan); !canCast { + return fmt.Errorf("couldnt cast AttrSetActionPlan") + } + return nil + }, + utils.APIerSv1GetActions: func(ctx *context.Context, args2, reply any) error { + return nil + }, + utils.APIerSv1GetTiming: func(ctx *context.Context, args3, reply any) error { + var canCast bool + if args3, canCast = args3.(*utils.ArgsGetTimingID); !canCast { + return fmt.Errorf("couldnt cast ArgsGetTimingID") + } + var exp *utils.TPTiming + if utils.ToJSON(args3) == utils.ToJSON(&utils.ArgsGetTimingID{ID: "Timing_1"}) { + exp = &utils.TPTiming{ + ID: "Timing_1", + Years: utils.Years{2025}, + Months: utils.Months{2}, + MonthDays: utils.MonthDays{3}, + WeekDays: utils.WeekDays{1, 2, 3}, + StartTime: "00:12:12", + EndTime: "12:12:12", + } + } + if utils.ToJSON(args3) == utils.ToJSON(&utils.ArgsGetTimingID{ID: "*asap"}) { + exp = &utils.TPTiming{ + ID: "*asap", + Years: utils.Years{2025}, + Months: utils.Months{}, + MonthDays: utils.MonthDays{}, + WeekDays: utils.WeekDays{}, + StartTime: "*asap", + } + } + if exp == nil { + return utils.ErrNotFound + } + *reply.(*utils.TPTiming) = *exp + return nil + }, + }, + } + connID := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier) + clientconn := make(chan birpc.ClientConnector, 1) + clientconn <- ccMock + NewConnManager(config.NewDefaultCGRConfig(), map[string]chan birpc.ClientConnector{ + connID: clientconn, + }) + testcases := []struct { + name string + extraParams string + connIDs []string + expAp *AttrSetActionPlan + expectedErr string + }{ + { + name: "SuccessfulRequest", + connIDs: []string{connID}, + expAp: &AttrSetActionPlan{ + Id: "ActPl_1", + ActionPlan: []*AttrActionPlan{ + { + ActionsId: "Action_1", + TimingID: "Timing_1", + Years: "2025", + Months: "2", + MonthDays: "3", + WeekDays: "1;2;3", + Time: "00:12:12;12:12:12", + Weight: 10, + }, + }, + Overwrite: true, + ReloadScheduler: true, + }, + extraParams: "ActPl_1;Action_1;Timing_1;10;true", + }, + { + name: "SuccessfulRequestWithDynamicPaths", + connIDs: []string{connID}, + expAp: &AttrSetActionPlan{ + Id: "ActPl_1", + ActionPlan: []*AttrActionPlan{ + { + ActionsId: "Action_1001", + TimingID: "*asap", + Years: "2025", + Months: "*any", + MonthDays: "*any", + WeekDays: "*any", + Time: "*asap", + Weight: 10, + }, + }, + Overwrite: false, + ReloadScheduler: true, + }, + extraParams: "ActPl_1;Action_<~*req.Account>;*asap;10;", + }, + { + name: "SuccessfulRequestEmptyFields", + connIDs: []string{connID}, + expAp: &AttrSetActionPlan{ + Id: "ActPl_1", + ActionPlan: []*AttrActionPlan{ + { + ActionsId: "Action_1", + TimingID: "", + Weight: 0, + }, + }, + Overwrite: false, + ReloadScheduler: true, + }, + extraParams: "ActPl_1;Action_1;;;", + }, + { + name: "MissingConns", + extraParams: "ActPl_1;Action_1;*asap;10;", + expectedErr: "MANDATORY_IE_MISSING: [connIDs]", + }, + { + name: "WrongNumberOfParams", + extraParams: "ActPl_1;Action_1;*asap;10;;;", + expectedErr: "invalid number of parameters <7> expected 5", + }, + { + name: "ActionIdEmptyFail", + extraParams: "ActPl_1;;*asap;10;", + expectedErr: `empty ActionsId for dynamic_action_plan`, + }, + { + name: "WeightFail", + connIDs: []string{connID}, + extraParams: "ActPl_1;Action_1;*asap;BadString;", + expectedErr: `strconv.ParseFloat: parsing "BadString": invalid syntax`, + }, + } + + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + action := &Action{ExtraParameters: tc.extraParams} + ev := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "evID", + Time: &time.Time{}, + Event: map[string]any{ + utils.AccountField: "1001", + }, + } + t.Cleanup(func() { + ap = nil + }) + err := dynamicActionPlan(nil, action, nil, nil, ev, + SharedActionsData{}, ActionConnCfg{ + ConnIDs: tc.connIDs, + }) + if tc.expectedErr != "" { + if err == nil || err.Error() != tc.expectedErr { + t.Errorf("expected error <%v>, received <%v>", tc.expectedErr, err) + } + } else if err != nil { + t.Error(err) + } else if utils.ToJSON(ap) != utils.ToJSON(tc.expAp) { + t.Errorf("Expected <%v>\nReceived\n<%v>", utils.ToJSON(tc.expAp), utils.ToJSON(ap)) + } + }) + } +} + +func TestDynamicActionAll(t *testing.T) { + tempConn := connMgr + tmpDm := dm + tmpCache := Cache + defer func() { + config.SetCgrConfig(config.NewDefaultCGRConfig()) + SetConnManager(tempConn) + dm = tmpDm + Cache = tmpCache + }() + Cache.Clear(nil) + var a *utils.AttrSetActions + ccMock := &ccMock{ + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.APIerSv2SetActions: func(ctx *context.Context, args, reply any) error { + var canCast bool + if a, canCast = args.(*utils.AttrSetActions); !canCast { + return fmt.Errorf("couldnt cast") + } + return nil + }, + }, + } + connID := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier) + clientconn := make(chan birpc.ClientConnector, 1) + clientconn <- ccMock + NewConnManager(config.NewDefaultCGRConfig(), map[string]chan birpc.ClientConnector{ + connID: clientconn, + }) + testcases := []struct { + name string + extraParams string + connIDs []string + expA *utils.AttrSetActions + expectedErr string + }{ + { + name: "SuccessfulRequest", + connIDs: []string{connID}, + expA: &utils.AttrSetActions{ + ActionsId: "Alter_Session_10", + Actions: []*utils.TPAction{ + { + Identifier: utils.MetaAlterSessions, + ExtraParameters: "cgrates.org;*string:~*req.Account:1001;1;*radCoATemplate:mycoa;CustomFilter:mycustomvalue", + Filters: "*string:~*req.Account:1001;filter2", + BalanceId: "badID", + BalanceType: utils.MetaMonetary, + Categories: "call;data", + DestinationIds: "1002;1003", + RatingSubject: "SPECIAL_1002", + SharedGroups: "SHARED_A;SHARED_B", + ExpiryTime: "*unlimited", + TimingTags: "weekdays;offpeak", + Units: "10", + BalanceWeight: "10", + BalanceBlocker: "true", + BalanceDisabled: "true", + Weight: 10, + }, + }, + Overwrite: false, + }, + extraParams: "Alter_Session_10;*alter_sessions;\fcgrates.org;*string:~*req.Account:1001;1;*radCoATemplate:mycoa;CustomFilter:mycustomvalue\f;*string:~*req.Account:1001&filter2;badID;*monetary;call&data;1002&1003;SPECIAL_1002;SHARED_A&SHARED_B;*unlimited;weekdays&offpeak;10;10;true;true;10", + }, + { + name: "SuccessfulRequestWithDynamicPaths", + connIDs: []string{connID}, + expA: &utils.AttrSetActions{ + ActionsId: "CDR_Log_1001", + Actions: []*utils.TPAction{ + { + Identifier: utils.CDRLog, + ExtraParameters: "{\"Account\":\"1001\",\"RequestType\":\"*pseudoprepaid\",\"Subject\":\"DifferentThanAccount\", \"ToR\":\"~ActionType:s/^\\*(.*)$/did_$1/\"}", + Filters: "*string:~*req.Account:1001;filter2", + BalanceId: "badID", + BalanceType: utils.MetaMonetary, + Categories: "call;data", + DestinationIds: "1002;1003", + RatingSubject: "SPECIAL_1002", + SharedGroups: "SHARED_A;SHARED_B", + ExpiryTime: "*unlimited", + TimingTags: "weekdays;offpeak", + Units: "10", + BalanceWeight: "10", + BalanceBlocker: "true", + BalanceDisabled: "true", + Weight: 10, + }, + }, + Overwrite: false, + }, + extraParams: "CDR_Log_<~*req.Account>;*cdrlog;\f{\"Account\":\"<~*req.Account>\",\"RequestType\":\"*pseudoprepaid\",\"Subject\":\"DifferentThanAccount\", \"ToR\":\"~ActionType:s/^\\*(.*)$/did_$1/\"}\f;*string:~*req.Account:<~*req.Account>&filter2;badID;*monetary;call&data;1002&1003;SPECIAL_1002;SHARED_A&SHARED_B;*unlimited;weekdays&offpeak;10;10;true;true;10", + }, + { + name: "SuccessfulRequestEmptyFields", + connIDs: []string{connID}, + expA: &utils.AttrSetActions{ + ActionsId: "DISABLE_ACC", + Actions: []*utils.TPAction{ + { + Identifier: utils.MetaDisableAccount, + }, + }, + }, + extraParams: "DISABLE_ACC;*disable_account;;;;;;;;;;;;;;;", + }, + { + name: "MissingConns", + extraParams: "TOPUP_MONETARY_10;*topup;;*string:~*req.Account:1001&filter2;badID;*monetary;call&data;1002&1003;SPECIAL_1002;SHARED_A&SHARED_B;*unlimited;weekdays&offpeak;10;10;true;true;10", + expectedErr: "MANDATORY_IE_MISSING: [connIDs]", + }, + { + name: "WrongNumberOfParams", + extraParams: "TOPUP_MONETARY_10;*topup;;*string:~*req.Account:1001&filter2;badID;*monetary;call&data;1002&1003;SPECIAL_1002;SHARED_A&SHARED_B;*unlimited;weekdays&offpeak;10;10;true;true;10;;;", + expectedErr: "invalid number of parameters <20> expected 17", + }, + { + name: "ActionIdEmptyFail", + extraParams: "DISABLE_ACC;;;;;;;;;;;;;;;;", + expectedErr: `empty Action for dynamic_action`, + }, + { + name: "ActionIdEmptyFail", + extraParams: ";;;;;;;;;;;;;;;;", + expectedErr: `empty ActionsId for dynamic_action`, + }, + { + name: "WeightFail", + extraParams: "TOPUP_MONETARY_10;*topup;;*string:~*req.Account:1001&filter2;badID;*monetary;call&data;1002&1003;SPECIAL_1002;SHARED_A&SHARED_B;*unlimited;weekdays&offpeak;10;10;true;true;BadString", + expectedErr: `strconv.ParseFloat: parsing "BadString": invalid syntax`, + }, + } + + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + action := &Action{ExtraParameters: tc.extraParams} + ev := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "evID", + Time: &time.Time{}, + Event: map[string]any{ + utils.AccountField: "1001", + }, + } + t.Cleanup(func() { + a = nil + }) + err := dynamicAction(nil, action, nil, nil, ev, + SharedActionsData{}, ActionConnCfg{ + ConnIDs: tc.connIDs, + }) + if tc.expectedErr != "" { + if err == nil || err.Error() != tc.expectedErr { + t.Errorf("expected error <%v>, received <%v>", tc.expectedErr, err) + } + } else if err != nil { + t.Error(err) + } else if utils.ToJSON(a) != utils.ToJSON(tc.expA) { + t.Errorf("Expected <%v>\nReceived\n<%v>", utils.ToJSON(tc.expA), utils.ToJSON(a)) + } + }) + } +} + +func TestDynamicDestination(t *testing.T) { + tempConn := connMgr + tmpDm := dm + tmpCache := Cache + defer func() { + config.SetCgrConfig(config.NewDefaultCGRConfig()) + SetConnManager(tempConn) + dm = tmpDm + Cache = tmpCache + }() + Cache.Clear(nil) + var dest *utils.AttrSetDestination + ccMock := &ccMock{ + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.APIerSv1SetDestination: func(ctx *context.Context, args, reply any) error { + var canCast bool + if dest, canCast = args.(*utils.AttrSetDestination); !canCast { + return fmt.Errorf("couldnt cast") + } + return nil + }, + }, + } + connID := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier) + clientconn := make(chan birpc.ClientConnector, 1) + clientconn <- ccMock + NewConnManager(config.NewDefaultCGRConfig(), map[string]chan birpc.ClientConnector{ + connID: clientconn, + }) + testcases := []struct { + name string + extraParams string + connIDs []string + expDest *utils.AttrSetDestination + expectedErr string + }{ + { + name: "SuccessfulRequest", + connIDs: []string{connID}, + expDest: &utils.AttrSetDestination{ + Id: "DST_1002&1003", + Prefixes: []string{"1002", "1003"}, + Overwrite: false, + }, + extraParams: "DST_1002&1003;1002&1003", + }, + { + name: "SuccessfulRequestWithDynamicPaths", + connIDs: []string{connID}, + expDest: &utils.AttrSetDestination{ + Id: "DST_1001&1003", + Prefixes: []string{"1001", "1003"}, + Overwrite: false, + }, + extraParams: "DST_1001&1003;<~*req.Account>&1003", + }, + { + name: "SuccessfulRequestEmptyFields", + connIDs: []string{connID}, + expDest: &utils.AttrSetDestination{ + Id: "DST_Any", + Overwrite: false, + }, + extraParams: "DST_Any;", + }, + { + name: "MissingConns", + extraParams: "DST_1002&1003;1002&1003", + expectedErr: "MANDATORY_IE_MISSING: [connIDs]", + }, + { + name: "WrongNumberOfParams", + extraParams: "DST_1002&1003;1002&1003;;;", + expectedErr: "invalid number of parameters <5> expected 2", + }, + } + + for _, tc := range testcases { + t.Run(tc.name, func(t *testing.T) { + action := &Action{ExtraParameters: tc.extraParams} + ev := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "evID", + Time: &time.Time{}, + Event: map[string]any{ + utils.AccountField: "1001", + }, + } + t.Cleanup(func() { + dest = nil + }) + err := dynamicDestination(nil, action, nil, nil, ev, + SharedActionsData{}, ActionConnCfg{ + ConnIDs: tc.connIDs, + }) + if tc.expectedErr != "" { + if err == nil || err.Error() != tc.expectedErr { + t.Errorf("expected error <%v>, received <%v>", tc.expectedErr, err) + } + } else if err != nil { + t.Error(err) + } else if utils.ToJSON(dest) != utils.ToJSON(tc.expDest) { + t.Errorf("Expected <%v>\nReceived\n<%v>", utils.ToJSON(tc.expDest), utils.ToJSON(dest)) + } + }) + } +} diff --git a/general_tests/a1_it_test.go b/general_tests/a1_it_test.go index b000a0c69..3a49b9e50 100644 --- a/general_tests/a1_it_test.go +++ b/general_tests/a1_it_test.go @@ -31,7 +31,6 @@ import ( "github.com/cgrates/birpc" "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" - v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -338,7 +337,7 @@ func testA1itConcurrentAPs(t *testing.T) { for _, acnt := range acnts { wg.Add(1) go func(acnt string) { - attrSetAcnt := v2.AttrSetAccount{ + attrSetAcnt := engine.AttrSetAccount{ Tenant: "cgrates.org", Account: acnt, ActionPlanIDs: []string{"PACKAGE_1"}, @@ -380,7 +379,7 @@ func testA1itConcurrentAPs(t *testing.T) { wg.Done() }(acnt) go func(acnt string) { - attrSetAcnt := v2.AttrSetAccount{ + attrSetAcnt := engine.AttrSetAccount{ Tenant: "cgrates.org", Account: acnt, ActionPlanIDs: []string{"PACKAGE_2"}, diff --git a/general_tests/at_topup_it_test.go b/general_tests/at_topup_it_test.go index b7f76213f..17cd41352 100644 --- a/general_tests/at_topup_it_test.go +++ b/general_tests/at_topup_it_test.go @@ -296,9 +296,9 @@ Alternative setup by API: } if err := client.Call(context.Background(), utils.APIerSv1SetActionPlan, - &v1.AttrSetActionPlan{ + &engine.AttrSetActionPlan{ Id: "PACKAGE_1001", - ActionPlan: []*v1.AttrActionPlan{{ + ActionPlan: []*engine.AttrActionPlan{{ ActionsId: "ACT_TOPUP_INITIAL", TimingID: "*asap", Time: "*asap", diff --git a/general_tests/cdrs_processevent_it_test.go b/general_tests/cdrs_processevent_it_test.go index 39d3fabbc..cd1c5bf9c 100644 --- a/general_tests/cdrs_processevent_it_test.go +++ b/general_tests/cdrs_processevent_it_test.go @@ -32,7 +32,6 @@ import ( "github.com/cgrates/birpc" "github.com/cgrates/birpc/context" - v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/ees" "github.com/cgrates/cgrates/engine" @@ -475,7 +474,7 @@ func testV1CDRsProcessEventThreshold(t *testing.T) { } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } - attrSetAcnt := v2.AttrSetAccount{ + attrSetAcnt := engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "1005", ExtraOptions: map[string]bool{ diff --git a/general_tests/doubleremove_it_test.go b/general_tests/doubleremove_it_test.go index 892dd15c3..6fd0d5deb 100644 --- a/general_tests/doubleremove_it_test.go +++ b/general_tests/doubleremove_it_test.go @@ -276,9 +276,9 @@ func testdoubleRemoveActionPlan(t *testing.T) { } */ // set ActionPlan - atms1 := &v1.AttrSetActionPlan{ + atms1 := &engine.AttrSetActionPlan{ Id: "ATMS_1", - ActionPlan: []*v1.AttrActionPlan{ + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "ACTS_2", Time: utils.MetaASAP, diff --git a/general_tests/dynamic_acc_sts_thld_it_test.go b/general_tests/dynamic_acc_sts_thld_it_test.go index 2361643e0..968739502 100644 --- a/general_tests/dynamic_acc_sts_thld_it_test.go +++ b/general_tests/dynamic_acc_sts_thld_it_test.go @@ -21,9 +21,12 @@ along with this program. If not, see package general_tests import ( + "bytes" + "fmt" "path" "path/filepath" "reflect" + "slices" "strconv" "testing" "time" @@ -47,7 +50,9 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) { ng := engine.TestEngine{ ConfigPath: filepath.Join(*utils.DataDir, "conf", "samples", "dynamic_account_threshold"), TpPath: path.Join(*utils.DataDir, "tariffplans", "testit"), + LogBuffer: &bytes.Buffer{}, } + t.Cleanup(func() { fmt.Println(ng.LogBuffer) }) client, _ := ng.Run(t) t.Run("SetInitiativeThresholdProfile", func(t *testing.T) { @@ -89,6 +94,62 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) { } }) + t.Run("SetAccountEnableAction", func(t *testing.T) { + attrs1 := &utils.AttrSetActions{ + ActionsId: "ACT_ENABLE_ACC", + Actions: []*utils.TPAction{ + { + Identifier: utils.MetaEnableAccount, + }, + }, + } + var reply string + if err := client.Call(context.Background(), utils.APIerSv2SetActions, &attrs1, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Errorf("Unexpected reply returned: %s", reply) + } + }) + + t.Run("SetAfter5sTiming", func(t *testing.T) { + timing := &utils.TPTimingWithAPIOpts{ + TPTiming: &utils.TPTiming{ + ID: "TM_AFTER_5S", + StartTime: "+5s", + }, + } + var reply string + if err := client.Call(context.Background(), utils.APIerSv1SetTiming, timing, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Error("Unexpected reply returned", reply) + } + }) + + t.Run("SetDynamicActionPlanAction", func(t *testing.T) { + attrs1 := &utils.AttrSetActions{ + ActionsId: "ACT_DYN_ACT_PLAN_ACC_ENABLE", + Actions: []*utils.TPAction{ + { + Identifier: utils.MetaDynamicActionPlan, + ExtraParameters: "ACT_PLAN_5S_ACC_ENABLE;ACT_ENABLE_ACC;TM_AFTER_5S;10;true", + Weight: 5, + }, + // { + // Identifier: utils.MetaDynamicAccountAction, + // ExtraParameters: "cgrates.org;<~*opts.*accountID>;ACT_PLAN_5S_ACC_ENABLE;;;", + // Weight: 2, + // }, + }, + } + var reply string + if err := client.Call(context.Background(), utils.APIerSv2SetActions, &attrs1, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Errorf("Unexpected reply returned: %s", reply) + } + }) + t.Run("SetDynamicThresholdAndStatsAction", func(t *testing.T) { attrs1 := &utils.AttrSetActions{ ActionsId: "ACT_DYN_THRESHOLD_AND_STATS_CREATION", @@ -101,8 +162,8 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) { }, { Identifier: utils.MetaDynamicThreshold, - // get tenant and accountID from event, threshold triggers when sum of statID hits 100, after triggers the action, the threshold will be disabled for 24 hours, make sure dynamic thresholds weight is higher than the initiative threshold THD_DYNAMIC_STATS_AND_THRESHOLD_INIT and blocker threshold THD_BLOCKER_ACNT_<~*req.Account> - ExtraParameters: "*tenant;THD_ACNT_<~*req.Account>;*string:~*req.StatID:Stat_<~*req.Account>&*string:~*req.*sum#1:100;*now;-1;1;24h;true;4;ACT_BLOCK_ACC;true;", + // get tenant and accountID from event, threshold triggers when sum of statID hits 100, after triggers the action, the threshold will be disabled for 5 seconds, make sure dynamic thresholds weight is higher than the initiative threshold THD_DYNAMIC_STATS_AND_THRESHOLD_INIT and blocker threshold THD_BLOCKER_ACNT_<~*req.Account> + ExtraParameters: "*tenant;THD_ACNT_<~*req.Account>;*string:~*req.StatID:Stat_<~*req.Account>&*string:~*req.*sum#1:100;*now;-1;1;5s;true;4;ACT_BLOCK_ACC&ACT_DYN_ACT_PLAN_ACC_ENABLE;true;", }, { Identifier: utils.MetaDynamicStats, @@ -121,12 +182,12 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) { t.Run("SetActionPlanOfDynaPrepaidAccounts", func(t *testing.T) { var reply string - atms1 := &v1.AttrSetActionPlan{ + atms1 := &engine.AttrSetActionPlan{ Id: "DYNA_ACC", - ActionPlan: []*v1.AttrActionPlan{ + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "TOPUP_RST_DATA_100", - Time: "00:00:00", + Time: utils.MetaMonthlyEstimated, TimingID: utils.MetaMonthlyEstimated, Weight: 20, }, @@ -233,4 +294,94 @@ func TestDynamicAccountWithStatsAndThreshold(t *testing.T) { } }) + t.Run("CheckCreatedDynamicActionPlan", func(t *testing.T) { + var reply []string + if err := client.Call(context.Background(), utils.APIerSv1GetActionPlanIDs, + &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, + &reply); err != nil { + t.Error(err) + } else if len(reply) != 4 { + t.Errorf("Expected: 4 , received: <%+v>", reply) + } + slices.Sort(reply) + if reply[0] != "ACT_PLAN_5S_ACC_ENABLE" { + t.Errorf("Expected: ACT_PLAN_5S_ACC_ENABLE , received: <%v>", reply[0]) + } else if reply[1] != "DYNA_ACC" { + t.Errorf("Expected: DYNA_ACC , received: <%v>", reply[1]) + } else if reply[2] != "PACKAGE_1001" { + t.Errorf("Expected: PACKAGE_1001 , received: <%v>", reply[2]) + } else if reply[3] != "PACKAGE_1002" { + t.Errorf("Expected: PACKAGE_1002 , received: <%v>", reply[3]) + } + + var rcv []*engine.ActionPlan + if err := client.Call(context.Background(), utils.APIerSv1GetActionPlan, + &v1.AttrGetActionPlan{ID: "ACT_PLAN_5S_ACC_ENABLE"}, &rcv); err != nil { + t.Error(err) + } + exp := []*engine.ActionPlan{ + { + Id: "ACT_PLAN_5S_ACC_ENABLE", + ActionTimings: []*engine.ActionTiming{ + { + Uuid: rcv[0].ActionTimings[0].Uuid, + ActionsID: "ACT_ENABLE_ACC", + ExtraData: nil, + Weight: 10, + Timing: &engine.RateInterval{ + Timing: &engine.RITiming{ + ID: "TM_AFTER_5S", + Years: utils.Years{}, + Months: utils.Months{}, + MonthDays: utils.MonthDays{}, + WeekDays: utils.WeekDays{}, + StartTime: "+5s", + }, + Rating: nil, + Weight: 0, + }, + }, + }, + }, + } + if len(exp) != 1 || len(rcv) != 1 { + t.Fatalf("expected exp len 1, got <%v>, expected rcv len 1, got <%v>", len(exp), len(rcv)) + } + if !reflect.DeepEqual(exp, rcv) { + t.Errorf("expected <%v>, \nreceived <%v>", utils.ToJSON(exp), utils.ToJSON(rcv)) + } + }) + + // t.Run("CheckAccountReEnabled", func(t *testing.T) { + // time.Sleep(6 * time.Second) + // var acnt engine.Account + // if err := client.Call(context.Background(), utils.APIerSv2GetAccount, + // &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "CreatedAccount"}, &acnt); err != nil { + // t.Error(err) + // } + // expAcc := &engine.Account{ + // ID: "cgrates.org:CreatedAccount", + // BalanceMap: map[string]engine.Balances{ + // utils.MetaData: { + // &engine.Balance{ + // Uuid: acnt.BalanceMap[utils.MetaData][0].Uuid, + // ID: "", + // Categories: utils.StringMap{}, + // SharedGroups: utils.StringMap{}, + // TimingIDs: utils.StringMap{}, + // Value: 4096, + // ExpirationDate: acnt.BalanceMap[utils.MetaData][0].ExpirationDate, + // Weight: 10, + // DestinationIDs: utils.StringMap{}, + // }, + // }, + // }, + // UpdateTime: acnt.UpdateTime, + // Disabled: false, + // } + // if !reflect.DeepEqual(utils.ToJSON(expAcc), utils.ToJSON(acnt)) { + // t.Errorf("Expected <%v>, \nreceived <%v>", utils.ToJSON(expAcc), utils.ToJSON(acnt)) + // } + // }) + } diff --git a/general_tests/filtered_replication_it_test.go b/general_tests/filtered_replication_it_test.go index 458d5d2b8..734ab6b52 100644 --- a/general_tests/filtered_replication_it_test.go +++ b/general_tests/filtered_replication_it_test.go @@ -29,7 +29,6 @@ import ( "github.com/cgrates/birpc" "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" - v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -1330,7 +1329,7 @@ func testFltrRplDispatcherHost(t *testing.T) { func testFltrRplAccount(t *testing.T) { acID := "ATTR1" - attrPrf := &v2.AttrSetAccount{Tenant: "cgrates.org", Account: acID, ExtraOptions: map[string]bool{utils.Disabled: true}} + attrPrf := &engine.AttrSetAccount{Tenant: "cgrates.org", Account: acID, ExtraOptions: map[string]bool{utils.Disabled: true}} attrAC := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: acID} expPrf := &engine.Account{ ID: "cgrates.org:" + acID, diff --git a/general_tests/offline_internal_it_test.go b/general_tests/offline_internal_it_test.go index 1bc1749a9..b85ab8042 100644 --- a/general_tests/offline_internal_it_test.go +++ b/general_tests/offline_internal_it_test.go @@ -253,9 +253,9 @@ func TestOfflineInternal(t *testing.T) { // run with sudo var aps []*engine.ActionPlan t.Run("GetActionPlan", func(t *testing.T) { var reply string - atms1 := &v1.AttrSetActionPlan{ + atms1 := &engine.AttrSetActionPlan{ Id: "ATMS_1", - ActionPlan: []*v1.AttrActionPlan{ + ActionPlan: []*engine.AttrActionPlan{ { ActionsId: "ACTION_TOPUP_RESET_SMS", MonthDays: "1", diff --git a/general_tests/tutorial2_it_test.go b/general_tests/tutorial2_it_test.go index a126ccd08..5150a07bd 100644 --- a/general_tests/tutorial2_it_test.go +++ b/general_tests/tutorial2_it_test.go @@ -29,7 +29,6 @@ import ( "github.com/cgrates/birpc" "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" - v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -358,7 +357,7 @@ func testTutAccounts(t *testing.T) { // enable the account again var rplySetAcnt string if err := tutRpc.Call(context.Background(), utils.APIerSv2SetAccount, - &v2.AttrSetAccount{ + &engine.AttrSetAccount{ Tenant: "cgrates.org", Account: "1001", ExtraOptions: map[string]bool{ diff --git a/services/apiers_it_test.go b/services/apiers_it_test.go index 06b3cdd35..e447fd6d8 100644 --- a/services/apiers_it_test.go +++ b/services/apiers_it_test.go @@ -63,7 +63,7 @@ func TestApiersReload(t *testing.T) { stordb := NewStorDBService(cfg, false, srvDep) anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) rspd := NewResponderService(cfg, server, make(chan birpc.ClientConnector, 1), shdChan, anz, srvDep, filterSChan) apiSv1 := NewAPIerSv1Service(cfg, db, stordb, filterSChan, server, schS, rspd, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) diff --git a/services/rals_it_test.go b/services/rals_it_test.go index caec6915f..de7a73699 100644 --- a/services/rals_it_test.go +++ b/services/rals_it_test.go @@ -69,7 +69,7 @@ func TestRalsReload(t *testing.T) { anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) stordb := NewStorDBService(cfg, false, srvDep) schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) ralS := NewRalService(cfg, chS, server, make(chan birpc.ClientConnector, 1), make(chan birpc.ClientConnector, 1), diff --git a/services/resources_it_test.go b/services/resources_it_test.go index 526d2aea9..08f2692be 100644 --- a/services/resources_it_test.go +++ b/services/resources_it_test.go @@ -58,7 +58,7 @@ func TestResourceSReload(t *testing.T) { srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, false, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) reS := NewResourceService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(tS, reS, diff --git a/services/stats_it_test.go b/services/stats_it_test.go index cff262e7d..85df0c4e1 100644 --- a/services/stats_it_test.go +++ b/services/stats_it_test.go @@ -58,7 +58,7 @@ func TestStatSReload(t *testing.T) { srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, false, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) sS := NewStatService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(tS, sS, diff --git a/services/thresholds_it_test.go b/services/thresholds_it_test.go index ac5c9b812..c09961bf0 100644 --- a/services/thresholds_it_test.go +++ b/services/thresholds_it_test.go @@ -55,7 +55,7 @@ func TestThresholdSReload(t *testing.T) { srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, false, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(tS, NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) @@ -125,7 +125,7 @@ func TestThresholdSReload2(t *testing.T) { srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, false, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(tS, NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db)