Added test for attributes for event ignore filter

This commit is contained in:
andronache
2021-10-15 17:04:35 +03:00
committed by Dan Christian Bogos
parent d1ef08cff1
commit 28e769cdb8

View File

@@ -1353,3 +1353,82 @@ func TestAttributesProcessEventProfileIgnoreFilters(t *testing.T) {
t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ToJSON(exp), utils.ToJSON(rcv))
}
}
// doesn't work as intended need to discuss with pufi
// 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,
// }
// 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))
// }
// }