From 28e769cdb84d4b221cd46990020d85ba6ad91121 Mon Sep 17 00:00:00 2001 From: andronache Date: Fri, 15 Oct 2021 17:04:35 +0300 Subject: [PATCH] Added test for attributes for event ignore filter --- engine/attributes_test.go | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/engine/attributes_test.go b/engine/attributes_test.go index e45fdf2b2..123766a0c 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -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)) +// } +// }