mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Tests for ProfileIgnoreFilters in actions and engine for stats
This commit is contained in:
committed by
Dan Christian Bogos
parent
6b3c2235d1
commit
2af41dd937
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user