From 2af41dd937ebadfaea248267e173087f6398a6f5 Mon Sep 17 00:00:00 2001 From: andronache Date: Thu, 21 Oct 2021 17:31:52 +0300 Subject: [PATCH] Tests for ProfileIgnoreFilters in actions and engine for stats --- actions/actions_test.go | 113 ++++++++++++++++++++++++++++++++++++++++ engine/stats_test.go | 63 ++++++++++++++++++++++ 2 files changed, 176 insertions(+) diff --git a/actions/actions_test.go b/actions/actions_test.go index 13acbad95..090c6fdf8 100644 --- a/actions/actions_test.go +++ b/actions/actions_test.go @@ -1135,3 +1135,116 @@ func TestACScheduledActions(t *testing.T) { t.Errorf("Expected %+v, received %+v", expectedSChed, schedActs) } } + +func TestV1ScheduleActionsProfileIgnoreFilters(t *testing.T) { + defaultCfg := config.NewDefaultCGRConfig() + defaultCfg.ActionSCfg().Opts.ProfileIgnoreFilters = []*utils.DynamicBoolOpt{ + { + Value: true, + }, + } + data := engine.NewInternalDB(nil, nil, true) + dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil) + + filters := engine.NewFilterS(defaultCfg, nil, dm) + acts := NewActionS(defaultCfg, filters, dm, nil) + + var reply string + ev := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "test_id1", + Event: map[string]interface{}{ + utils.AccountField: "1001", + utils.Destination: 1002, + }, + APIOpts: map[string]interface{}{ + utils.OptsActionsProfileIDs: []string{"test_id1"}, + utils.MetaProfileIgnoreFilters: true, + "testFieldIgnore": "testValue", + }, + } + + actPrf := &engine.ActionProfile{ + Tenant: "cgrates.org", + ID: "test_id1", + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10", "*prefix:~*opts.testFieldIgnore:testValue1"}, + Schedule: utils.MetaASAP, + Actions: []*engine.APAction{ + { + ID: "TOPUP", + FilterIDs: []string{}, + Type: utils.MetaLog, + Diktats: []*engine.APDiktat{{ + Path: "~*balance.TestBalance.Value", + Value: "10", + }}, + }, + }, + } + + if err := acts.dm.SetActionProfile(context.Background(), actPrf, true); err != nil { + t.Error(err) + } + + if err := acts.V1ScheduleActions(context.Background(), ev, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Errorf("Unexpected reply %+v", reply) + } +} + +func TestV1ExecuteActionsProfileIgnoreFilters(t *testing.T) { + defaultCfg := config.NewDefaultCGRConfig() + defaultCfg.ActionSCfg().Opts.ProfileIgnoreFilters = []*utils.DynamicBoolOpt{ + { + Value: true, + }, + } + data := engine.NewInternalDB(nil, nil, true) + dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil) + filters := engine.NewFilterS(defaultCfg, nil, dm) + acts := NewActionS(defaultCfg, filters, dm, nil) + + var reply string + ev := &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "test_id1", + Event: map[string]interface{}{ + utils.AccountField: "1001", + utils.Destination: 1002, + }, + APIOpts: map[string]interface{}{ + utils.OptsActionsProfileIDs: []string{"test_id1"}, + utils.MetaProfileIgnoreFilters: true, + "testFieldIgnore": "testValue", + }, + } + + actPrf := &engine.ActionProfile{ + Tenant: "cgrates.org", + ID: "test_id1", + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10", "*prefix:~*opts.testFieldIgnore:testValue1"}, + Schedule: utils.MetaASAP, + Actions: []*engine.APAction{ + { + ID: "TOPUP", + FilterIDs: []string{}, + Type: utils.MetaLog, + Diktats: []*engine.APDiktat{{ + Path: "~*balance.TestBalance.Value", + Value: "10", + }}, + }, + }, + } + if err := acts.dm.SetActionProfile(context.Background(), actPrf, true); err != nil { + t.Error(err) + } + + if err := acts.V1ExecuteActions(context.Background(), ev, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Errorf("Unexpected reply %+v", reply) + } + +} diff --git a/engine/stats_test.go b/engine/stats_test.go index ac6d86ce3..fe0585db1 100644 --- a/engine/stats_test.go +++ b/engine/stats_test.go @@ -3644,3 +3644,66 @@ func TestStatQueueProcessEventProfileIgnoreFiltersError(t *testing.T) { } } + +func TestStatQueueV1GetStatQueuesForEventProfileIgnoreFilters(t *testing.T) { + tmp := Cache + tmpC := config.CgrConfig() + defer func() { + Cache = tmp + config.SetCgrConfig(tmpC) + }() + + cfg := config.NewDefaultCGRConfig() + cfg.StatSCfg().Opts.ProfileIgnoreFilters = []*utils.DynamicBoolOpt{ + { + Value: true, + }, + } + data := NewInternalDB(nil, nil, true) + dm := NewDataManager(data, cfg.CacheCfg(), nil) + Cache = NewCacheS(cfg, dm, nil) + filterS := NewFilterS(cfg, nil, dm) + sS := NewStatService(dm, cfg, filterS, nil) + + sqPrf1 := &StatQueueProfile{ + Tenant: "cgrates.org", + ID: "SQ1", + FilterIDs: []string{"*string:~*req.Account:1001"}, + Weight: 10, + Blocker: true, + QueueLength: 10, + ThresholdIDs: []string{"*none"}, + MinItems: 5, + Metrics: []*MetricWithFilters{ + { + MetricID: utils.MetaTCD, + }, + }, + } + + if err := dm.SetStatQueueProfile(context.Background(), sqPrf1, true); err != nil { + t.Error(err) + } + + args := &utils.CGREvent{ + ID: "TestGetStatQueuesForEvent", + Event: map[string]interface{}{ + utils.AccountField: "1002", + }, + APIOpts: map[string]interface{}{ + utils.OptsStatsProfileIDs: []string{"SQ1"}, + utils.MetaProfileIgnoreFilters: true, + }, + } + + exp := []string{"SQ1"} + var reply []string + if err := sS.V1GetStatQueuesForEvent(context.Background(), args, &reply); err != nil { + t.Error(err) + } else { + sort.Strings(reply) + if !reflect.DeepEqual(reply, exp) { + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, reply) + } + } +}