From 6f242b025de78d18147c46367539433dee0461e0 Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 29 Jul 2020 10:27:08 +0300 Subject: [PATCH] Add test for *suffix with charger --- data/conf/samples/filters/cgrates.json | 12 ++ data/conf/samples/filters_gob/cgrates.json | 13 ++ .../samples/filters_internal/cgrates.json | 13 ++ data/conf/samples/filters_mongo/cgrates.json | 13 ++ data/conf/samples/filters_mysql/cgrates.json | 13 ++ general_tests/filters_it_test.go | 120 ++++++++++++++++++ 6 files changed, 184 insertions(+) diff --git a/data/conf/samples/filters/cgrates.json b/data/conf/samples/filters/cgrates.json index 09bf6574b..e8b6965a3 100644 --- a/data/conf/samples/filters/cgrates.json +++ b/data/conf/samples/filters/cgrates.json @@ -64,6 +64,18 @@ "store_interval": "1s", }, + +"attributes": { + "enabled": true, +}, + + +"chargers": { + "enabled": true, + "suffix_indexed_fields": ["*req.Subject"], + "attributes_conns": ["*internal"], +}, + "apiers": { "enabled": true, "caches_conns":["*localhost"], diff --git a/data/conf/samples/filters_gob/cgrates.json b/data/conf/samples/filters_gob/cgrates.json index 4c39131ad..e0ea7b459 100644 --- a/data/conf/samples/filters_gob/cgrates.json +++ b/data/conf/samples/filters_gob/cgrates.json @@ -71,6 +71,19 @@ "store_interval": "1s", }, + +"attributes": { + "enabled": true, +}, + + +"chargers": { + "enabled": true, + "suffix_indexed_fields": ["*req.Subject"], + "attributes_conns": ["*internal"], +}, + + "apiers": { "enabled": true, "caches_conns":["conn1"], diff --git a/data/conf/samples/filters_internal/cgrates.json b/data/conf/samples/filters_internal/cgrates.json index 7e5295eeb..ec0333d56 100644 --- a/data/conf/samples/filters_internal/cgrates.json +++ b/data/conf/samples/filters_internal/cgrates.json @@ -62,6 +62,19 @@ "store_interval": "-1", }, + +"attributes": { + "enabled": true, +}, + + +"chargers": { + "enabled": true, + "suffix_indexed_fields": ["*req.Subject"], + "attributes_conns": ["*internal"], +}, + + "apiers": { "enabled": true, "caches_conns":["*localhost"], diff --git a/data/conf/samples/filters_mongo/cgrates.json b/data/conf/samples/filters_mongo/cgrates.json index 6c55ec8d3..50046f0dd 100644 --- a/data/conf/samples/filters_mongo/cgrates.json +++ b/data/conf/samples/filters_mongo/cgrates.json @@ -67,6 +67,19 @@ "store_interval": "1s", }, + +"attributes": { + "enabled": true, +}, + + +"chargers": { + "enabled": true, + "suffix_indexed_fields": ["*req.Subject"], + "attributes_conns": ["*internal"], +}, + + "apiers": { "enabled": true, "caches_conns":["*localhost"], diff --git a/data/conf/samples/filters_mysql/cgrates.json b/data/conf/samples/filters_mysql/cgrates.json index 09bf6574b..0ee3054d8 100644 --- a/data/conf/samples/filters_mysql/cgrates.json +++ b/data/conf/samples/filters_mysql/cgrates.json @@ -64,6 +64,19 @@ "store_interval": "1s", }, + +"attributes": { + "enabled": true, +}, + + +"chargers": { + "enabled": true, + "suffix_indexed_fields": ["*req.Subject"], + "attributes_conns": ["*internal"], +}, + + "apiers": { "enabled": true, "caches_conns":["*localhost"], diff --git a/general_tests/filters_it_test.go b/general_tests/filters_it_test.go index e6cf12f6d..4f654cef8 100644 --- a/general_tests/filters_it_test.go +++ b/general_tests/filters_it_test.go @@ -54,6 +54,8 @@ var ( testV1FltrPopulateResources, testV1FltrAccounts, testV1FltrAccountsExistsDynamicaly, + testV1FltrInitDataDb, + testV1FltrChargerSuffix, testV1FltrStopEngine, } ) @@ -725,6 +727,124 @@ func testV1FltrAccountsExistsDynamicaly(t *testing.T) { } } +func testV1FltrChargerSuffix(t *testing.T) { + var reply string + if err := fltrRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithArgDispatcher{ + CacheIDs: nil, + }, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Error("Reply: ", reply) + } + chargerProfile := &v1.ChargerWithCache{ + ChargerProfile: &engine.ChargerProfile{ + Tenant: "cgrates.org", + ID: "IntraCharger", + FilterIDs: []string{"*suffix:~*req.Subject:intra"}, + RunID: "Intra", + AttributeIDs: []string{"*constant:*req.Subject:intraState"}, + Weight: 20, + }, + } + var result string + if err := fltrRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + + chargerProfile2 := &v1.ChargerWithCache{ + ChargerProfile: &engine.ChargerProfile{ + Tenant: "cgrates.org", + ID: "InterCharger", + FilterIDs: []string{"*suffix:~*req.Subject:inter"}, + RunID: "Inter", + AttributeIDs: []string{"*constant:*req.Subject:interState"}, + Weight: 20, + }, + } + if err := fltrRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile2, &result); err != nil { + t.Error(err) + } else if result != utils.OK { + t.Error("Unexpected reply returned", result) + } + + processedEv := []*engine.ChrgSProcessEventReply{ + { + ChargerSProfile: "IntraCharger", + AttributeSProfiles: []string{"*constant:*req.Subject:intraState"}, + AlteredFields: []string{utils.MetaReqRunID, "*req.Subject"}, + Opts: map[string]interface{}{ + utils.Subsys: utils.MetaChargers, + }, + CGREvent: &utils.CGREvent{ // matching Charger1 + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.Account: "1010", + utils.Subject: "intraState", + utils.RunID: "Intra", + utils.Destination: "999", + }, + }, + }, + } + cgrEv := &utils.CGREventWithOpts{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.Account: "1010", + utils.Subject: "Something_intra", + utils.Destination: "999", + }, + }, + } + var result2 []*engine.ChrgSProcessEventReply + if err := fltrRpc.Call(utils.ChargerSv1ProcessEvent, 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)) + } + + processedEv = []*engine.ChrgSProcessEventReply{ + { + ChargerSProfile: "InterCharger", + AttributeSProfiles: []string{"*constant:*req.Subject:interState"}, + AlteredFields: []string{utils.MetaReqRunID, "*req.Subject"}, + Opts: map[string]interface{}{ + utils.Subsys: utils.MetaChargers, + }, + CGREvent: &utils.CGREvent{ // matching Charger1 + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.Account: "1010", + utils.Subject: "interState", + utils.RunID: "Inter", + utils.Destination: "999", + }, + }, + }, + } + cgrEv = &utils.CGREventWithOpts{ + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "event1", + Event: map[string]interface{}{ + utils.Account: "1010", + utils.Subject: "Something_inter", + utils.Destination: "999", + }, + }, + } + if err := fltrRpc.Call(utils.ChargerSv1ProcessEvent, 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)