mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Revise && add new unit tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
3c57a8ddca
commit
8921bf8b99
@@ -84,7 +84,7 @@ func TestAccountSCfgLoadFromJSONCfgOptsErr(t *testing.T) {
|
||||
accOpts := &AccountsOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{"1001", "1002"},
|
||||
Values: []string{"1001", "1002"},
|
||||
},
|
||||
},
|
||||
Usage: []*utils.DynamicDecimalBigOpt{
|
||||
@@ -245,7 +245,7 @@ func TestDiffAccountSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"ACC1"},
|
||||
Values: []string{"ACC1"},
|
||||
},
|
||||
},
|
||||
Usage: []*utils.DynamicDecimalBigOpt{
|
||||
@@ -279,7 +279,7 @@ func TestDiffAccountSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"ACC2"},
|
||||
Values: []string{"ACC2"},
|
||||
},
|
||||
},
|
||||
Usage: []*utils.DynamicDecimalBigOpt{
|
||||
@@ -313,7 +313,7 @@ func TestDiffAccountSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"ACC2"},
|
||||
Values: []string{"ACC2"},
|
||||
},
|
||||
},
|
||||
Usage: []*utils.DynamicStringOpt{
|
||||
@@ -376,7 +376,7 @@ func TestAccountSCloneSection(t *testing.T) {
|
||||
Opts: &AccountsOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{"ACC1"},
|
||||
Values: []string{"ACC1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -82,7 +82,7 @@ func TestActionoSLoadConfigFromJSONOpts(t *testing.T) {
|
||||
actOpts := &ActionsOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{},
|
||||
Values: []string{},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -94,7 +94,7 @@ func TestActionoSLoadConfigFromJSONOpts(t *testing.T) {
|
||||
exp := &ActionsOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{},
|
||||
Values: []string{},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -233,7 +233,7 @@ func TestDiffActionSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"prf1"},
|
||||
Values: []string{"prf1"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -263,7 +263,7 @@ func TestDiffActionSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"prf2"},
|
||||
Values: []string{"prf2"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -293,7 +293,7 @@ func TestDiffActionSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"prf2"},
|
||||
Values: []string{"prf2"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -339,7 +339,7 @@ func TestActionSCloneSection(t *testing.T) {
|
||||
Opts: &ActionsOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{},
|
||||
Values: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -361,7 +361,7 @@ func TestActionSCloneSection(t *testing.T) {
|
||||
Opts: &ActionsOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{},
|
||||
Values: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestAttributeSLoadFromJsonCfgOpts(t *testing.T) {
|
||||
attrOpt := &AttributesOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{},
|
||||
Values: []string{},
|
||||
},
|
||||
},
|
||||
ProcessRuns: []*utils.DynamicIntOpt{
|
||||
@@ -98,7 +98,7 @@ func TestAttributeSLoadFromJsonCfgOpts(t *testing.T) {
|
||||
exp := &AttributesOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{},
|
||||
Values: []string{},
|
||||
},
|
||||
},
|
||||
ProcessRuns: []*utils.DynamicIntOpt{
|
||||
@@ -304,7 +304,7 @@ func TestDiffAttributeSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"prf1"},
|
||||
Values: []string{"prf1"},
|
||||
},
|
||||
},
|
||||
ProcessRuns: []*utils.DynamicIntOpt{
|
||||
@@ -342,7 +342,7 @@ func TestDiffAttributeSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"prf2"},
|
||||
Values: []string{"prf2"},
|
||||
},
|
||||
},
|
||||
ProcessRuns: []*utils.DynamicIntOpt{
|
||||
@@ -380,7 +380,7 @@ func TestDiffAttributeSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"prf2"},
|
||||
Values: []string{"prf2"},
|
||||
},
|
||||
},
|
||||
ProcessRuns: []*utils.DynamicIntOpt{
|
||||
|
||||
@@ -235,7 +235,7 @@ func TestGeneralCfgClone(t *testing.T) {
|
||||
Opts: &GeneralOpts{
|
||||
ExporterIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{"*ees"},
|
||||
Values: []string{"*ees"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -273,7 +273,7 @@ func TestDiffGeneralJsonCfg(t *testing.T) {
|
||||
Opts: &GeneralOpts{
|
||||
ExporterIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{"*ees"},
|
||||
Values: []string{"*ees"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -306,7 +306,7 @@ func TestDiffGeneralJsonCfg(t *testing.T) {
|
||||
Opts: &GeneralOpts{
|
||||
ExporterIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{"*syslog"},
|
||||
Values: []string{"*syslog"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -339,7 +339,7 @@ func TestDiffGeneralJsonCfg(t *testing.T) {
|
||||
Opts: &GeneralOptsJson{
|
||||
ExporterIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{"*syslog"},
|
||||
Values: []string{"*syslog"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -235,7 +235,7 @@ func TestDiffRateSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"RP1"},
|
||||
Values: []string{"RP1"},
|
||||
},
|
||||
},
|
||||
StartTime: []*utils.DynamicStringOpt{
|
||||
@@ -282,7 +282,7 @@ func TestDiffRateSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"RP2"},
|
||||
Values: []string{"RP2"},
|
||||
},
|
||||
},
|
||||
StartTime: []*utils.DynamicStringOpt{
|
||||
@@ -329,7 +329,7 @@ func TestDiffRateSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"RP2"},
|
||||
Values: []string{"RP2"},
|
||||
},
|
||||
},
|
||||
StartTime: []*utils.DynamicStringOpt{
|
||||
@@ -391,7 +391,7 @@ func TestRateSCloneSection(t *testing.T) {
|
||||
Opts: &RatesOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{"RP1"},
|
||||
Values: []string{"RP1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -413,7 +413,7 @@ func TestRateSCloneSection(t *testing.T) {
|
||||
Opts: &RatesOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{"RP1"},
|
||||
Values: []string{"RP1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -429,7 +429,7 @@ func TestRatesOptsLoadFromJSON(t *testing.T) {
|
||||
rateOpts := &RatesOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{},
|
||||
Values: []string{},
|
||||
},
|
||||
},
|
||||
StartTime: []*utils.DynamicStringOpt{
|
||||
@@ -463,7 +463,7 @@ func TestRatesOptsLoadFromJSON(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"RP2"},
|
||||
Values: []string{"RP2"},
|
||||
},
|
||||
},
|
||||
Usage: []*utils.DynamicStringOpt{
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestStatSCfgloadFromJsonCfgOptsNil(t *testing.T) {
|
||||
statsOpt := &StatsOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{},
|
||||
Values: []string{},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -88,7 +88,7 @@ func TestStatSCfgloadFromJsonCfgOptsNil(t *testing.T) {
|
||||
exp := &StatsOpts{
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{},
|
||||
Values: []string{},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -237,7 +237,7 @@ func TestDiffStatServJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"statsid1"},
|
||||
Values: []string{"statsid1"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -255,7 +255,7 @@ func TestDiffStatServJsonCfg(t *testing.T) {
|
||||
PrometheusStatIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"statsid1"},
|
||||
Values: []string{"statsid1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -275,7 +275,7 @@ func TestDiffStatServJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"statsid2"},
|
||||
Values: []string{"statsid2"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -293,7 +293,7 @@ func TestDiffStatServJsonCfg(t *testing.T) {
|
||||
PrometheusStatIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"statsid2"},
|
||||
Values: []string{"statsid2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -313,7 +313,7 @@ func TestDiffStatServJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"statsid2"},
|
||||
Values: []string{"statsid2"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -331,7 +331,7 @@ func TestDiffStatServJsonCfg(t *testing.T) {
|
||||
PrometheusStatIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"statsid2"},
|
||||
Values: []string{"statsid2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -73,7 +73,7 @@ func TestThresholdSLoadFromJsonOpts(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"thsd_p1"},
|
||||
Values: []string{"thsd_p1"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -87,7 +87,7 @@ func TestThresholdSLoadFromJsonOpts(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"thsd_p1"},
|
||||
Values: []string{"thsd_p1"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -219,7 +219,7 @@ func TestDiffThresholdSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"thsr_p1"},
|
||||
Values: []string{"thsr_p1"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -244,7 +244,7 @@ func TestDiffThresholdSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"thsr_p2"},
|
||||
Values: []string{"thsr_p2"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
@@ -269,7 +269,7 @@ func TestDiffThresholdSJsonCfg(t *testing.T) {
|
||||
ProfileIDs: []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"thsr_p2"},
|
||||
Values: []string{"thsr_p2"},
|
||||
},
|
||||
},
|
||||
ProfileIgnoreFilters: []*utils.DynamicBoolOpt{
|
||||
|
||||
@@ -1041,18 +1041,18 @@ func TestLibFiltersGetStringSliceOptsReturnConfigOpt(t *testing.T) {
|
||||
{
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Tenant: "cgrates.net",
|
||||
Value: []string{"value1"},
|
||||
Values: []string{"value1"},
|
||||
},
|
||||
// filter will not pass, will ignore this opt
|
||||
{
|
||||
FilterIDs: []string{"*string:~*req.Account:1002"},
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"value2"},
|
||||
Values: []string{"value2"},
|
||||
},
|
||||
{
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"value3"},
|
||||
Values: []string{"value3"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1083,7 +1083,7 @@ func TestLibFiltersGetStringSliceOptsFilterCheckErr(t *testing.T) {
|
||||
{
|
||||
FilterIDs: []string{"*string.invalid:filter"},
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"value2"},
|
||||
Values: []string{"value2"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1113,7 +1113,7 @@ func TestLibFiltersGetStringSliceOptsReturnDefaultOpt(t *testing.T) {
|
||||
{
|
||||
FilterIDs: []string{"*string:~*req.Account:1002"},
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"value2"},
|
||||
Values: []string{"value2"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1146,7 +1146,7 @@ func TestLibFiltersGetStringSliceOptsReturnOptFromAPIOpts(t *testing.T) {
|
||||
{
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"value3"},
|
||||
Values: []string{"value3"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -3524,7 +3524,7 @@ func TestStatSV1GetStatQueuesForEventsqIDsErr(t *testing.T) {
|
||||
{
|
||||
FilterIDs: []string{"*string.invalid:filter"},
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"value2"},
|
||||
Values: []string{"value2"},
|
||||
},
|
||||
}
|
||||
data := NewInternalDB(nil, nil, cfg.DataDbCfg().Items)
|
||||
@@ -3792,7 +3792,7 @@ func TestStatQueueProcessEventProfileIDsErr(t *testing.T) {
|
||||
{
|
||||
FilterIDs: []string{"*string.invalid:filter"},
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"value2"},
|
||||
Values: []string{"value2"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3877,7 +3877,7 @@ func TestStatQueueProcessEventPrometheusStatIDsErr(t *testing.T) {
|
||||
{
|
||||
FilterIDs: []string{"*string.invalid:filter"},
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"value2"},
|
||||
Values: []string{"value2"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -3349,7 +3349,7 @@ func TestThresholdSmatchingThresholdsForEventGetOptsErr(t *testing.T) {
|
||||
{
|
||||
FilterIDs: []string{"*string"},
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"ProfIdVal"},
|
||||
Values: []string{"ProfIdVal"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3391,7 +3391,7 @@ func TestThresholdSmatchingThresholdsForEventWeightErr(t *testing.T) {
|
||||
cfg.ThresholdSCfg().Opts.ProfileIDs = []*utils.DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"ACC1"},
|
||||
Values: []string{"ACC1"},
|
||||
},
|
||||
}
|
||||
cfg.ThresholdSCfg().Opts.ProfileIgnoreFilters = []*utils.DynamicBoolOpt{
|
||||
|
||||
@@ -303,6 +303,7 @@ func TestMatchingRateProfileEvent(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
var ignoredRPIDs utils.StringSet
|
||||
if rtPRf, err := rate.matchingRateProfileForEvent(context.TODO(), "cgrates.org", []string{},
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -312,7 +313,7 @@ func TestMatchingRateProfileEvent(t *testing.T) {
|
||||
utils.Destination: 1002,
|
||||
utils.AnswerTime: t1.Add(-10 * time.Second),
|
||||
},
|
||||
}, false); err != nil {
|
||||
}, false, ignoredRPIDs); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rtPRf, rpp) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(rpp), utils.ToJSON(rtPRf))
|
||||
@@ -327,7 +328,7 @@ func TestMatchingRateProfileEvent(t *testing.T) {
|
||||
utils.Destination: 2002,
|
||||
utils.AnswerTime: t1.Add(-10 * time.Second),
|
||||
},
|
||||
}, false); err != utils.ErrNotFound {
|
||||
}, false, ignoredRPIDs); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := rate.matchingRateProfileForEvent(context.TODO(), "cgrates.org", []string{},
|
||||
@@ -339,7 +340,7 @@ func TestMatchingRateProfileEvent(t *testing.T) {
|
||||
utils.Destination: 2002,
|
||||
utils.AnswerTime: t1.Add(10 * time.Second),
|
||||
},
|
||||
}, false); err != utils.ErrNotFound {
|
||||
}, false, ignoredRPIDs); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := rate.matchingRateProfileForEvent(context.TODO(), "cgrates.org", []string{},
|
||||
@@ -351,7 +352,7 @@ func TestMatchingRateProfileEvent(t *testing.T) {
|
||||
utils.Destination: 1002,
|
||||
utils.AnswerTime: t1.Add(-10 * time.Second),
|
||||
},
|
||||
}, false); err != utils.ErrNotFound {
|
||||
}, false, ignoredRPIDs); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -364,7 +365,7 @@ func TestMatchingRateProfileEvent(t *testing.T) {
|
||||
utils.Destination: 1002,
|
||||
utils.AnswerTime: t1.Add(-10 * time.Second),
|
||||
},
|
||||
}, false); err != utils.ErrNotFound {
|
||||
}, false, ignoredRPIDs); err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
rpp.FilterIDs = []string{"*string:~*req.Account:1001|1002|1003", "*gt:~*req.Cost{*:10"}
|
||||
@@ -377,7 +378,7 @@ func TestMatchingRateProfileEvent(t *testing.T) {
|
||||
utils.Cost: 1002,
|
||||
utils.AnswerTime: t1.Add(-10 * time.Second),
|
||||
},
|
||||
}, false); err.Error() != "invalid converter terminator in rule: <~*req.Cost{*>" {
|
||||
}, false, ignoredRPIDs); err.Error() != "invalid converter terminator in rule: <~*req.Cost{*>" {
|
||||
t.Error(err)
|
||||
}
|
||||
rpp.FilterIDs = []string{"*string:~*req.Account:1001|1002|1003"}
|
||||
@@ -392,7 +393,7 @@ func TestMatchingRateProfileEvent(t *testing.T) {
|
||||
utils.Destination: 1002,
|
||||
utils.AnswerTime: t1.Add(-10 * time.Second),
|
||||
},
|
||||
}, false); err != utils.ErrNoDatabaseConn {
|
||||
}, false, ignoredRPIDs); err != utils.ErrNoDatabaseConn {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -680,13 +681,6 @@ func BenchmarkRateS_V1CostForEventSingleRate(b *testing.B) {
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
func TestRatesShutDown(t *testing.T) {
|
||||
rateS := new(RateS)
|
||||
if err := rateS.Shutdown(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRateProfileCostForEventInvalidUsage(t *testing.T) {
|
||||
engine.Cache.Clear(nil)
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
@@ -914,6 +908,7 @@ func TestRateSMatchingRateProfileForEventErrFltr(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
var ignoredRPfIDs utils.StringSet
|
||||
_, err = rateS.matchingRateProfileForEvent(context.TODO(), "cgrates.org", []string{},
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -923,7 +918,7 @@ func TestRateSMatchingRateProfileForEventErrFltr(t *testing.T) {
|
||||
utils.Destination: 1002,
|
||||
utils.AnswerTime: time.Date(9999, 7, 21, 10, 0, 0, 0, time.UTC).Add(-10 * time.Second),
|
||||
},
|
||||
}, false)
|
||||
}, false, ignoredRPfIDs)
|
||||
expectedErr := "NOT_FOUND"
|
||||
if err == nil || err.Error() != expectedErr {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expectedErr, err)
|
||||
@@ -1320,3 +1315,109 @@ func TestRateProfileCostForEventProfileIgnoreFilters(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMatchingRateProfileFallbacks(t *testing.T) {
|
||||
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := engine.NewInternalDB(nil, nil, cfg.DataDbCfg().Items)
|
||||
dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil)
|
||||
filters := engine.NewFilterS(cfg, nil, dm)
|
||||
rate := RateS{
|
||||
cfg: cfg,
|
||||
fltrS: filters,
|
||||
dm: dm,
|
||||
}
|
||||
t1 := time.Date(2020, 7, 21, 10, 0, 0, 0, time.UTC)
|
||||
|
||||
rpp1 := &utils.RateProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RP1",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"},
|
||||
}
|
||||
|
||||
rpp2 := &utils.RateProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RP2",
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 5,
|
||||
},
|
||||
},
|
||||
FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"},
|
||||
}
|
||||
|
||||
// Set both rate profiles
|
||||
err := dm.SetRateProfile(context.Background(), rpp1, false, true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = dm.SetRateProfile(context.Background(), rpp2, false, true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// Initialize ignoredRPIDs as a new empty map
|
||||
ignoredRPIDs := make(utils.StringSet)
|
||||
|
||||
// 1. Test without any ignored profiles (should match RP1 with higher weight)
|
||||
if rtPRf, err := rate.matchingRateProfileForEvent(context.TODO(), "cgrates.org", []string{},
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ID",
|
||||
Event: map[string]any{
|
||||
utils.AccountField: "1001",
|
||||
utils.Destination: 1002,
|
||||
utils.AnswerTime: t1.Add(-10 * time.Second),
|
||||
},
|
||||
}, false, ignoredRPIDs); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rtPRf, rpp1) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(rpp1), utils.ToJSON(rtPRf))
|
||||
}
|
||||
|
||||
// 2. Test with ignoredRPIDs containing RP1 (should match RP2 )
|
||||
ignoredRPIDs.Add(rpp1.ID)
|
||||
if rtPRf, err := rate.matchingRateProfileForEvent(context.TODO(), "cgrates.org", []string{},
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ID",
|
||||
Event: map[string]any{
|
||||
utils.AccountField: "1001",
|
||||
utils.Destination: 1002,
|
||||
utils.AnswerTime: t1.Add(-10 * time.Second),
|
||||
},
|
||||
}, false, ignoredRPIDs); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(rtPRf, rpp2) {
|
||||
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(rpp2), utils.ToJSON(rtPRf))
|
||||
}
|
||||
|
||||
// 3. Test with both RP1 and RP2 in ignoredRPIDs (should return ErrNotFound)
|
||||
ignoredRPIDs.Add(rpp2.ID)
|
||||
if _, err := rate.matchingRateProfileForEvent(context.TODO(), "cgrates.org", []string{},
|
||||
&utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ID",
|
||||
Event: map[string]any{
|
||||
utils.AccountField: "1001",
|
||||
utils.Destination: 1002,
|
||||
utils.AnswerTime: t1.Add(-10 * time.Second),
|
||||
},
|
||||
}, false, ignoredRPIDs); err != utils.ErrNotFound {
|
||||
t.Errorf("Expected error %v, got %v", utils.ErrNotFound, err)
|
||||
}
|
||||
|
||||
err = dm.RemoveRateProfile(context.Background(), rpp1.Tenant, rpp1.ID, true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = dm.RemoveRateProfile(context.Background(), rpp2.Tenant, rpp2.ID, true)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ import (
|
||||
func TestCloneDynamicStringsSliceOpt(t *testing.T) {
|
||||
in := []*DynamicStringSliceOpt{
|
||||
{
|
||||
Value: []string{"VAL_1", "VAL_2"},
|
||||
Values: []string{"VAL_1", "VAL_2"},
|
||||
FilterIDs: []string{"fltr1"},
|
||||
},
|
||||
{
|
||||
Value: []string{"VAL_3", "VAL_4"},
|
||||
Values: []string{"VAL_3", "VAL_4"},
|
||||
FilterIDs: []string{"fltr2"},
|
||||
},
|
||||
}
|
||||
@@ -168,12 +168,12 @@ func TestDynamicStringSliceOptEqual(t *testing.T) {
|
||||
v1 := []*DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"VAL_1", "VAL_2"},
|
||||
Values: []string{"VAL_1", "VAL_2"},
|
||||
FilterIDs: []string{"fltr1"},
|
||||
},
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"VAL_3", "VAL_4"},
|
||||
Values: []string{"VAL_3", "VAL_4"},
|
||||
FilterIDs: []string{"fltr2"},
|
||||
},
|
||||
}
|
||||
@@ -181,12 +181,12 @@ func TestDynamicStringSliceOptEqual(t *testing.T) {
|
||||
v2 := []*DynamicStringSliceOpt{
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"VAL_1", "VAL_2"},
|
||||
Values: []string{"VAL_1", "VAL_2"},
|
||||
FilterIDs: []string{"fltr1"},
|
||||
},
|
||||
{
|
||||
Tenant: "cgrates.org",
|
||||
Value: []string{"VAL_3", "VAL_4"},
|
||||
Values: []string{"VAL_3", "VAL_4"},
|
||||
FilterIDs: []string{"fltr2"},
|
||||
},
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func TestDynamicStringSliceOptEqual(t *testing.T) {
|
||||
}
|
||||
|
||||
//Test if different
|
||||
v1[0].Value = append(v1[0].Value, "VAL_3")
|
||||
v1[0].Values = append(v1[0].Values, "VAL_3")
|
||||
if DynamicStringSliceOptEqual(v1, v2) {
|
||||
t.Error("Expected slices to differ")
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func TestDynamicStringSliceOptEqual(t *testing.T) {
|
||||
|
||||
//Test if different lengths
|
||||
v1 = append(v1, &DynamicStringSliceOpt{
|
||||
Value: []string{"VAL_1", "VAL_2"},
|
||||
Values: []string{"VAL_1", "VAL_2"},
|
||||
FilterIDs: []string{"fltr1"},
|
||||
})
|
||||
if DynamicStringSliceOptEqual(v1, v2) {
|
||||
|
||||
Reference in New Issue
Block a user