From 3ae49719671d5e68478daba54f2648ddc6131cbc Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 28 Oct 2020 08:53:14 +0200 Subject: [PATCH] Added test for prefix filter --- .../samples/filters_internal/cgrates.json | 1 + data/conf/samples/filters_mongo/cgrates.json | 1 + data/conf/samples/filters_mysql/cgrates.json | 1 + data/tariffplans/testit/Filters.csv | 3 +- general_tests/filters_it_test.go | 64 +++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/data/conf/samples/filters_internal/cgrates.json b/data/conf/samples/filters_internal/cgrates.json index ec0333d56..93bf4af2c 100644 --- a/data/conf/samples/filters_internal/cgrates.json +++ b/data/conf/samples/filters_internal/cgrates.json @@ -65,6 +65,7 @@ "attributes": { "enabled": true, + "prefix_indexed_fields": ["*req.CustomField"], }, diff --git a/data/conf/samples/filters_mongo/cgrates.json b/data/conf/samples/filters_mongo/cgrates.json index 50046f0dd..68abdc9d6 100644 --- a/data/conf/samples/filters_mongo/cgrates.json +++ b/data/conf/samples/filters_mongo/cgrates.json @@ -70,6 +70,7 @@ "attributes": { "enabled": true, + "prefix_indexed_fields": ["*req.CustomField"], }, diff --git a/data/conf/samples/filters_mysql/cgrates.json b/data/conf/samples/filters_mysql/cgrates.json index 0ee3054d8..99cd75e3f 100644 --- a/data/conf/samples/filters_mysql/cgrates.json +++ b/data/conf/samples/filters_mysql/cgrates.json @@ -67,6 +67,7 @@ "attributes": { "enabled": true, + "prefix_indexed_fields": ["*req.CustomField"], }, diff --git a/data/tariffplans/testit/Filters.csv b/data/tariffplans/testit/Filters.csv index 32eda2514..28ecb9928 100644 --- a/data/tariffplans/testit/Filters.csv +++ b/data/tariffplans/testit/Filters.csv @@ -25,4 +25,5 @@ cgrates.org,FLTR_SPP_QOS_2,*string,~*req.DistinctMatch,*qos_filtred2,2014-07-29T cgrates.org,FLTR_QOS_SP1_2,*gte,~*vars.Cost,0.1,2014-07-29T15:00:00Z cgrates.org,FLTR_QOS_SP2_2,*gte,~*vars.Cost,0.2,2014-07-29T15:00:00Z cgrates.org,FLTR_TEST,*string,~*req.Subject,TEST,2014-07-29T15:00:00Z -cgrates.org,FLTR_SPP_LOAD_DIST,*string,~*req.DistinctMatch,LoadDistStrategy,2014-07-29T15:00:00Z \ No newline at end of file +cgrates.org,FLTR_SPP_LOAD_DIST,*string,~*req.DistinctMatch,LoadDistStrategy,2014-07-29T15:00:00Z +cgrates.new,FLTR_1,*prefix,~*req.Destination,207;1207;+1207, diff --git a/general_tests/filters_it_test.go b/general_tests/filters_it_test.go index 2e9487a77..88d4bee47 100644 --- a/general_tests/filters_it_test.go +++ b/general_tests/filters_it_test.go @@ -54,6 +54,7 @@ var ( testV1FltrPopulateResources, testV1FltrAccounts, testV1FltrAccountsExistsDynamicaly, + testV1FltrAttributesPrefix, testV1FltrInitDataDb, testV1FltrChargerSuffix, testV1FltrStopEngine, @@ -861,6 +862,69 @@ func testV1FltrChargerSuffix(t *testing.T) { } } +func testV1FltrAttributesPrefix(t *testing.T) { + chargerProfile := &v1.AttributeWithCache{ + AttributeProfile: &engine.AttributeProfile{ + Tenant: "cgrates.new", + ID: "ATTR_1001", + FilterIDs: []string{"*prefix:~*req.CustomField:2007;+2007", "*prefix:~*req.CustomField2:2007;+2007", "FLTR_1"}, + Contexts: []string{"prefix"}, + Attributes: []*engine.Attribute{ + { + FilterIDs: []string{}, + Path: utils.MetaReq + utils.NestingSep + "CustomField", + Type: utils.META_CONSTANT, + Value: config.NewRSRParsersMustCompile("2007", utils.INFIELD_SEP), + }, + }, + Weight: 20.0, + }, + } + var result string + if err := fltrRpc.Call(utils.APIerSv1SetAttributeProfile, chargerProfile, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + + processedEv := &engine.AttrSProcessEventReply{ + AlteredFields: []string{"*req.CustomField"}, + MatchedProfiles: []string{"ATTR_1001"}, + CGREventWithOpts: &utils.CGREventWithOpts{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.new", + ID: "event1", + Event: map[string]interface{}{ + "CustomField": "2007", + "CustomField2": "+2007", + utils.Destination: "+1207", + }, + }, + }, + } + cgrEv := &engine.AttrArgsProcessEvent{ + CGREventWithOpts: &utils.CGREventWithOpts{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.new", + ID: "event1", + Event: map[string]interface{}{ + "CustomField": "+2007", + "CustomField2": "+2007", + utils.Destination: "+1207", + }, + }, + }, + Context: utils.StringPointer("prefix"), + } + var result2 *engine.AttrSProcessEventReply + if err := fltrRpc.Call(utils.AttributeSv1ProcessEvent, cgrEv, &result2); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(result2, processedEv) { + t.Errorf("Expecting : %s, \n received: %s", utils.ToJSON(processedEv), utils.ToJSON(result2)) + } + +} + func testV1FltrStopEngine(t *testing.T) { if err := engine.KillEngine(accDelay); err != nil { t.Error(err)