Fixed test for attributes with opt MetaProfileIgnoreFilters

This commit is contained in:
andronache
2021-10-19 17:00:42 +03:00
committed by Dan Christian Bogos
parent 03f9c0f4b5
commit 27ea25a838

View File

@@ -4358,81 +4358,83 @@ func TestAttributesProcessEventProfileIgnoreFilters(t *testing.T) {
}
}
// doesn't work as intended need to discuss
// func TestAttributesV1GetAttributeForEventProfileIgnoreOpts(t *testing.T) {
// cfg := config.NewDefaultCGRConfig()
// cfg.FilterSCfg().ResourceSConns = []string{}
// conMng := &ConnManager{}
// db := NewInternalDB(nil, nil, true)
// dm := NewDataManager(db, nil, conMng)
// filterS := NewFilterS(cfg, conMng, dm)
// aA := NewAttributeService(dm, filterS, cfg)
// cfg.AttributeSCfg().Opts.ProfileIgnoreFilters = []*utils.DynamicBoolOpt{
// {
// Value: true,
// },
// }
// acPrf := &AttributeProfile{
// Tenant: "cgrates.org",
// ID: "AC1",
// FilterIDs: []string{"*string:~*req.Attribute:testAttrValue"},
// }
// if err := dm.SetAttributeProfile(context.Background(), acPrf, true); err != nil {
// t.Error(err)
// }
// ev := &utils.CGREvent{
// Tenant: "cgrates.org",
// ID: "AcProcessEvent2",
// Event: map[string]interface{}{
// "Attribute": "testAttrValue",
// },
// APIOpts: map[string]interface{}{
// utils.OptsAttributesProcessRuns: 2,
// utils.MetaProfileIgnoreFilters: false,
// },
// }
// rply := &APIAttributeProfile{}
// expected := &APIAttributeProfile{
// Tenant: "cgrates.org",
// ID: "AC1",
// FilterIDs: []string{"*string:~*req.Attribute:testAttrValue"},
// Attributes: []*ExternalAttribute{},
// Weight: 0,
// }
//doesn't work as intended need to discuss
func TestAttributesV1GetAttributeForEventProfileIgnoreOpts(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
cfg.FilterSCfg().ResourceSConns = []string{}
conMng := &ConnManager{}
db := NewInternalDB(nil, nil, true)
dm := NewDataManager(db, nil, conMng)
filterS := NewFilterS(cfg, conMng, dm)
aA := NewAttributeService(dm, filterS, cfg)
cfg.AttributeSCfg().Opts.ProfileIgnoreFilters = []*utils.DynamicBoolOpt{
{
Value: true,
},
}
acPrf := &AttributeProfile{
Tenant: "cgrates.org",
ID: "AC1",
FilterIDs: []string{"*string:~*req.Attribute:testAttrValue"},
}
if err := dm.SetAttributeProfile(context.Background(), acPrf, true); err != nil {
t.Error(err)
}
ev := &utils.CGREvent{
Tenant: "cgrates.org",
ID: "AcProcessEvent1",
Event: map[string]interface{}{
"Attribute": "testAttrValue",
},
APIOpts: map[string]interface{}{
utils.OptsAttributesProcessRuns: 2,
utils.OptsAttributesProfileIDs: []string{"AC1"},
utils.MetaProfileIgnoreFilters: false,
},
}
rply := &APIAttributeProfile{}
expected := &APIAttributeProfile{
Tenant: "cgrates.org",
ID: "AC1",
FilterIDs: []string{"*string:~*req.Attribute:testAttrValue"},
Attributes: []*ExternalAttribute{},
Weight: 0,
}
// err = aA.V1GetAttributeForEvent(context.Background(), ev, rply)
// if err != nil {
// t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
// }
// if !reflect.DeepEqual(expected, rply) {
// t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expected), utils.ToJSON(rply))
// }
// // correct filter but ignore filters opt on false
// ev2 := &utils.CGREvent{
// Tenant: "cgrates.org",
// ID: "AcProcessEvent2",
// Event: map[string]interface{}{
// "Attribute": "testAttrValue2",
// },
// APIOpts: map[string]interface{}{
// utils.OptsAttributesProcessRuns: 2,
// utils.MetaProfileIgnoreFilters: true,
// },
// }
// rply2 := &APIAttributeProfile{}
// expected2 := &APIAttributeProfile{
// Tenant: "cgrates.org",
// ID: "AC1",
// FilterIDs: []string{"*string:~*req.Attribute:testAttrValue2"},
// Attributes: []*ExternalAttribute{},
// Weight: 0,
// }
// // with ignore filters on true and with bad filter
// err = aA.V1GetAttributeForEvent(context.Background(), ev2, rply2)
// if err != nil {
// t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
// }
// if !reflect.DeepEqual(expected2, rply2) {
// t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expected2), utils.ToJSON(rply2))
// }
// }
err = aA.V1GetAttributeForEvent(context.Background(), ev, rply)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
if !reflect.DeepEqual(expected, rply) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expected), utils.ToJSON(rply))
}
// correct filter but ignore filters opt on false
ev2 := &utils.CGREvent{
Tenant: "cgrates.org",
ID: "AcProcessEvent2",
Event: map[string]interface{}{
"Attribute": "testAttrValue2",
},
APIOpts: map[string]interface{}{
utils.OptsAttributesProcessRuns: 2,
utils.OptsAttributesProfileIDs: []string{"AC1"},
utils.MetaProfileIgnoreFilters: true,
},
}
rply2 := &APIAttributeProfile{}
expected2 := &APIAttributeProfile{
Tenant: "cgrates.org",
ID: "AC1",
FilterIDs: []string{"*string:~*req.Attribute:testAttrValue"},
Attributes: []*ExternalAttribute{},
Weight: 0,
}
// with ignore filters on true and with bad filter
err = aA.V1GetAttributeForEvent(context.Background(), ev2, rply2)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
if !reflect.DeepEqual(expected2, rply2) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expected2), utils.ToJSON(rply2))
}
}