From 83c71bb9568d0447bbaf2c5ef86c783f2cb28c85 Mon Sep 17 00:00:00 2001 From: andronache98 Date: Fri, 14 Jan 2022 15:58:30 +0200 Subject: [PATCH] Integration tests for stats and thresholds --- apis/stats_it_test.go | 116 +++++++++++++++++++++++++++++++++++++ apis/thresholds_it_test.go | 68 ++++++++++++++++++++++ utils/consts.go | 2 + 3 files changed, 186 insertions(+) diff --git a/apis/stats_it_test.go b/apis/stats_it_test.go index 00c95b629..3503816a6 100644 --- a/apis/stats_it_test.go +++ b/apis/stats_it_test.go @@ -53,10 +53,13 @@ var ( testStatsStartEngine, testStatsRPCConn, testStatsGetStatQueueBeforeSet, + testStatsGetStatQueueProfilesBeforeSet, testStatsSetStatQueueProfiles, testStatsGetStatQueueAfterSet, testStatsGetStatQueueIDs, testStatsGetStatQueueProfileIDs, + testStatsGetStatQueueProfiles1, + testStatsGetStatQueueProfilesWithPrefix, testStatsGetStatQueueProfileCount, testStatsRemoveStatQueueProfiles, testStatsGetStatQueuesAfterRemove, @@ -164,6 +167,15 @@ func testStatsGetStatQueueBeforeSet(t *testing.T) { } } +func testStatsGetStatQueueProfilesBeforeSet(t *testing.T) { + var reply []*engine.StatQueueProfile + var args *utils.ArgsItemIDs + if err := sqRPC.Call(context.Background(), utils.AdminSv1GetStatQueueProfiles, + args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) + } +} + func testStatsSetStatQueueProfiles(t *testing.T) { sqPrf1 := &engine.StatQueueProfileWithAPIOpts{ StatQueueProfile: &engine.StatQueueProfile{ @@ -426,6 +438,110 @@ func testStatsGetStatQueueProfileIDs(t *testing.T) { } } +func testStatsGetStatQueueProfiles1(t *testing.T) { + var reply []*engine.StatQueueProfile + var args *utils.ArgsItemIDs + exp := []*engine.StatQueueProfile{ + { + Tenant: "cgrates.org", + ID: "SQ_1", + Weight: 10, + QueueLength: 100, + TTL: time.Duration(1 * time.Minute), + MinItems: 5, + Metrics: []*engine.MetricWithFilters{ + { + MetricID: utils.MetaACC, + }, + { + MetricID: utils.MetaACD, + }, + { + MetricID: utils.MetaASR, + }, + { + MetricID: utils.MetaDDC, + }, + { + MetricID: utils.MetaTCD, + }, + }, + ThresholdIDs: []string{utils.MetaNone}, + }, + { + Tenant: "cgrates.org", + ID: "SQ_2", + Weight: 20, + Metrics: []*engine.MetricWithFilters{ + { + MetricID: utils.MetaASR, + }, + { + MetricID: utils.MetaTCD, + }, + { + MetricID: utils.MetaPDD, + }, + { + MetricID: utils.MetaTCC, + }, + { + MetricID: utils.MetaTCD, + }, + }, + ThresholdIDs: []string{utils.MetaNone}, + }, + } + if err := sqRPC.Call(context.Background(), utils.AdminSv1GetStatQueueProfiles, + args, &reply); err != nil { + t.Error(err) + } + sort.Slice(reply, func(i int, j int) bool { + return (reply)[i].ID < (reply)[j].ID + }) + if !reflect.DeepEqual(reply, exp) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, reply) + } +} + +func testStatsGetStatQueueProfilesWithPrefix(t *testing.T) { + var reply []*engine.StatQueueProfile + args := &utils.ArgsItemIDs{ + ItemsPrefix: "SQ_2", + } + exp := []*engine.StatQueueProfile{ + { + Tenant: "cgrates.org", + ID: "SQ_2", + Weight: 20, + Metrics: []*engine.MetricWithFilters{ + { + MetricID: utils.MetaASR, + }, + { + MetricID: utils.MetaTCD, + }, + { + MetricID: utils.MetaPDD, + }, + { + MetricID: utils.MetaTCC, + }, + { + MetricID: utils.MetaTCD, + }, + }, + ThresholdIDs: []string{utils.MetaNone}, + }, + } + if err := sqRPC.Call(context.Background(), utils.AdminSv1GetStatQueueProfiles, + args, &reply); err != nil { + t.Error(err) + } + if !reflect.DeepEqual(reply, exp) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, reply) + } +} func testStatsGetStatQueueProfileCount(t *testing.T) { var reply int if err := sqRPC.Call(context.Background(), utils.AdminSv1GetStatQueueProfileCount, diff --git a/apis/thresholds_it_test.go b/apis/thresholds_it_test.go index f7eaa24de..ffe53b715 100644 --- a/apis/thresholds_it_test.go +++ b/apis/thresholds_it_test.go @@ -53,6 +53,8 @@ var ( testThresholdsGetThresholdAfterSet, testThresholdsGetThresholdIDs, testThresholdsGetThresholdProfileIDs, + testThresholdsGetThresholdProfiles, + testThresholdsGetThresholdProfilesWithPrefix, testThresholdsGetThresholdProfileCount, testThresholdsGetThresholdsForEvent, testThresholdsRemoveThresholdProfiles, @@ -324,6 +326,72 @@ func testThresholdsGetThresholdProfileIDs(t *testing.T) { } } +func testThresholdsGetThresholdProfiles(t *testing.T) { + exp := []*engine.ThresholdProfile{ + { + Tenant: "cgrates.org", + ID: "THD_1", + FilterIDs: []string{"*string:~*req.Account:1001"}, + ActionProfileIDs: []string{"actPrfID"}, + MaxHits: 5, + MinHits: 1, + Weight: 10, + }, + { + Tenant: "cgrates.org", + ID: "THD_2", + FilterIDs: []string{"*string:~*req.Account:1001"}, + ActionProfileIDs: []string{"actPrfID"}, + MaxHits: 7, + MinHits: 0, + Weight: 20, + }, + } + var ths []*engine.ThresholdProfile + if err := thRPC.Call(context.Background(), utils.AdminSv1GetThresholdProfiles, + &utils.ArgsItemIDs{ + Tenant: "cgrates.org", + }, &ths); err != nil { + t.Error(err) + } else { + sort.Slice(ths, func(i int, j int) bool { + return (ths)[i].ID < (ths)[j].ID + }) + if !reflect.DeepEqual(ths, exp) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, ths) + } + } +} + +func testThresholdsGetThresholdProfilesWithPrefix(t *testing.T) { + exp := []*engine.ThresholdProfile{ + { + Tenant: "cgrates.org", + ID: "THD_2", + FilterIDs: []string{"*string:~*req.Account:1001"}, + ActionProfileIDs: []string{"actPrfID"}, + MaxHits: 7, + MinHits: 0, + Weight: 20, + }, + } + var ths []*engine.ThresholdProfile + if err := thRPC.Call(context.Background(), utils.AdminSv1GetThresholdProfiles, + &utils.ArgsItemIDs{ + Tenant: "cgrates.org", + ItemsPrefix: "THD_2", + }, &ths); err != nil { + t.Error(err) + } else { + sort.Slice(ths, func(i int, j int) bool { + return (ths)[i].ID < (ths)[j].ID + }) + if !reflect.DeepEqual(ths, exp) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, ths) + } + } +} + func testThresholdsGetThresholdProfileCount(t *testing.T) { var reply int if err := thRPC.Call(context.Background(), utils.AdminSv1GetThresholdProfileCount, diff --git a/utils/consts.go b/utils/consts.go index 91f6e5d94..95a07d396 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -1372,6 +1372,7 @@ const ( AdminSv1GetThresholdProfileIDs = "AdminSv1.GetThresholdProfileIDs" AdminSv1GetThresholdProfileCount = "AdminSv1.GetThresholdProfileCount" AdminSv1GetThresholdProfile = "AdminSv1.GetThresholdProfile" + AdminSv1GetThresholdProfiles = "AdminSv1.GetThresholdProfiles" AdminSv1RemoveThresholdProfile = "AdminSv1.RemoveThresholdProfile" AdminSv1SetThresholdProfile = "AdminSv1.SetThresholdProfile" ) @@ -1390,6 +1391,7 @@ const ( AdminSv1GetStatQueueProfile = "AdminSv1.GetStatQueueProfile" AdminSv1RemoveStatQueueProfile = "AdminSv1.RemoveStatQueueProfile" AdminSv1SetStatQueueProfile = "AdminSv1.SetStatQueueProfile" + AdminSv1GetStatQueueProfiles = "AdminSv1.GetStatQueueProfiles" AdminSv1GetStatQueueProfileIDs = "AdminSv1.GetStatQueueProfileIDs" AdminSv1GetStatQueueProfileCount = "AdminSv1.GetStatQueueProfileCount" )