mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Complete test for MatchingItemIDsForEvent with suffix case
This commit is contained in:
committed by
Dan Christian Bogos
parent
38e1e970ad
commit
2e5359f532
@@ -31,9 +31,10 @@ var (
|
||||
)
|
||||
|
||||
func TestFilterMatchingItemIDsForEvent(t *testing.T) {
|
||||
var stringFilter, prefixFilter, defaultFilter []*FilterRule
|
||||
var stringFilter, prefixFilter, suffixFilter, defaultFilter []*FilterRule
|
||||
stringFilterID := "stringFilterID"
|
||||
prefixFilterID := "prefixFilterID"
|
||||
suffixFilterID := "suffixFilterID"
|
||||
data := NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items)
|
||||
dmMatch = NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
|
||||
Cache.Clear(nil)
|
||||
@@ -69,6 +70,17 @@ func TestFilterMatchingItemIDsForEvent(t *testing.T) {
|
||||
Rules: defaultFilter}
|
||||
dmMatch.SetFilter(attribDefaultF, true)
|
||||
|
||||
x, err = NewFilterRule(utils.MetaSuffix, "~*req.Field", []string{"Prefix"})
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
suffixFilter = append(suffixFilter, x)
|
||||
attribSufF := &Filter{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: "sufFilter",
|
||||
Rules: suffixFilter}
|
||||
dmMatch.SetFilter(attribSufF, true)
|
||||
|
||||
tnt := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
if err = addItemToFilterIndex(dmMatch, utils.CacheAttributeFilterIndexes,
|
||||
tnt, context, stringFilterID, []string{"stringFilter"}); err != nil {
|
||||
@@ -78,6 +90,10 @@ func TestFilterMatchingItemIDsForEvent(t *testing.T) {
|
||||
tnt, context, prefixFilterID, []string{"prefFilter"}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = addItemToFilterIndex(dmMatch, utils.CacheAttributeFilterIndexes,
|
||||
tnt, context, suffixFilterID, []string{"sufFilter"}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tntCtx := utils.ConcatenatedKey(tnt, context)
|
||||
|
||||
matchEV = utils.MapStorage{utils.MetaReq: map[string]interface{}{
|
||||
@@ -93,6 +109,7 @@ func TestFilterMatchingItemIDsForEvent(t *testing.T) {
|
||||
if !has {
|
||||
t.Errorf("Expecting: %+v, received: %+v", stringFilterID, aPrflIDs)
|
||||
}
|
||||
|
||||
matchEV = utils.MapStorage{utils.MetaReq: map[string]interface{}{
|
||||
"Field": "profilePrefix",
|
||||
}}
|
||||
@@ -105,6 +122,19 @@ func TestFilterMatchingItemIDsForEvent(t *testing.T) {
|
||||
if !has {
|
||||
t.Errorf("Expecting: %+v, received: %+v", prefixFilterID, aPrflIDs)
|
||||
}
|
||||
|
||||
matchEV = utils.MapStorage{utils.MetaReq: map[string]interface{}{
|
||||
"Field": "profilePrefix",
|
||||
}}
|
||||
aPrflIDs, err = MatchingItemIDsForEvent(matchEV, nil, nil, nil,
|
||||
dmMatch, utils.CacheAttributeFilterIndexes, tntCtx, true, false)
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
_, has = aPrflIDs[suffixFilterID]
|
||||
if !has {
|
||||
t.Errorf("Expecting: %+v, received: %+v", suffixFilterID, aPrflIDs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterMatchingItemIDsForEvent2(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user