From acd9b527bdc6c060dea66867e972d4ebeb493085 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Tue, 27 Jul 2021 10:56:53 +0300 Subject: [PATCH] Test for not indexing *libphnumber --- engine/z_filterindexer_test.go | 37 ++++++++++++++++++++++++++++++++ engine/z_libindex_health_test.go | 16 +++++++------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/engine/z_filterindexer_test.go b/engine/z_filterindexer_test.go index 4a8ee13db..af01d811e 100644 --- a/engine/z_filterindexer_test.go +++ b/engine/z_filterindexer_test.go @@ -127,3 +127,40 @@ func TestFilterIndexesCheckingDynamicPathToNotIndex(t *testing.T) { t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIDx), utils.ToJSON(fltrIDx)) } } + +func TestFilterIndexesCheckingDynamicPathToNotIndexLibphNmbr(t *testing.T) { + Cache.Clear(nil) + cfg := config.NewDefaultCGRConfig() + db := NewInternalDB(nil, nil, true) + dm := NewDataManager(db, cfg.CacheCfg(), nil) + + // set 1 charger profile with different *libphonenumber filter to index + cghPfr := &ChargerProfile{ + Tenant: "cgrates.org", + ID: "CHARGER_2", + FilterIDs: []string{ + "*prefix:~*req.CGRID:TEST_ID", + "*string:~*opts.TotalCost:~*stats.STS_PRF1.*tcc", + "*string:~*libphonenumber.<~*req.Destination>:1233", + }, + RunID: "RAW", + AttributeIDs: []string{"attr_1"}, + Weight: 10, + } + + if err := dm.SetChargerProfile(context.Background(), cghPfr, true); err != nil { + t.Error(err) + } + + expIDx := map[string]utils.StringSet{ + "*prefix:*req.CGRID:TEST_ID": { + "CHARGER_2": {}, + }, + } + if fltrIDx, err := dm.GetIndexes(context.Background(), utils.CacheChargerFilterIndexes, + "cgrates.org", utils.EmptyString, true, true); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expIDx, fltrIDx) { + t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIDx), utils.ToJSON(fltrIDx)) + } +} diff --git a/engine/z_libindex_health_test.go b/engine/z_libindex_health_test.go index a1d852f0c..226fc6dcd 100644 --- a/engine/z_libindex_health_test.go +++ b/engine/z_libindex_health_test.go @@ -159,7 +159,7 @@ func TestHealthIndexThreshold(t *testing.T) { Tenant: "cgrates.org", ID: "TestHealthIndexThreshold", FilterIDs: []string{"*string:~*opts.*eventType:AccountUpdate", - "*string:~*asm.ID:1002", + "*string:~*opts.ID:1002", "*suffix:BrokenFilter:Invalid"}, MaxHits: 1, }, @@ -170,7 +170,7 @@ func TestHealthIndexThreshold(t *testing.T) { exp := &FilterIHReply{ MissingIndexes: map[string][]string{ - "cgrates.org:*string:*asm.ID:1002": {"TestHealthIndexThreshold"}, + "cgrates.org:*string:*opts.ID:1002": {"TestHealthIndexThreshold"}, "cgrates.org:*string:*opts.*eventType:AccountUpdate": {"TestHealthIndexThreshold"}, }, BrokenIndexes: map[string][]string{}, @@ -193,7 +193,7 @@ func TestHealthIndexThreshold(t *testing.T) { "*string:*req.Destination:123": { // index is valid but the obj does not exist "InexistingThreshold": {}, }, - } + } // we will set manually some indexes that points to an nil object or index is valid but the obj is missing if err := dm.SetIndexes(context.Background(), utils.CacheThresholdFilterIndexes, "cgrates.org", @@ -203,10 +203,10 @@ func TestHealthIndexThreshold(t *testing.T) { exp = &FilterIHReply{ MissingObjects: []string{"cgrates.org:InexistingThreshold"}, MissingIndexes: map[string][]string{ - "cgrates.org:*string:*asm.ID:1002": {"TestHealthIndexThreshold"}, + "cgrates.org:*string:*opts.ID:1002": {"TestHealthIndexThreshold"}, "cgrates.org:*string:*opts.*eventType:AccountUpdate": {"TestHealthIndexThreshold"}, }, - BrokenIndexes: map[string][]string{ + BrokenIndexes: map[string][]string{ "cgrates.org:*prefix:req.InvalidIdx:10": {"TestHealthIndexThreshold"}, }, MissingFilters: map[string][]string{}, @@ -227,7 +227,7 @@ func TestHealthIndexThreshold(t *testing.T) { Tenant: "cgrates.org", ID: "TestHealthIndexThreshold", FilterIDs: []string{"*string:~*opts.*eventType:AccountUpdate", - "*string:~*asm.ID:1002", + "*string:~*opts.ID:1002", "FLTR_1_DOES_NOT_EXIST"}, MaxHits: 1, }, @@ -238,10 +238,10 @@ func TestHealthIndexThreshold(t *testing.T) { exp = &FilterIHReply{ MissingObjects: []string{"cgrates.org:InexistingThreshold"}, MissingIndexes: map[string][]string{ - "cgrates.org:*string:*asm.ID:1002": {"TestHealthIndexThreshold"}, + "cgrates.org:*string:*opts.ID:1002": {"TestHealthIndexThreshold"}, "cgrates.org:*string:*opts.*eventType:AccountUpdate": {"TestHealthIndexThreshold"}, }, - BrokenIndexes: map[string][]string{ + BrokenIndexes: map[string][]string{ "cgrates.org:*prefix:req.InvalidIdx:10": {"TestHealthIndexThreshold"}, }, MissingFilters: map[string][]string{