mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Improving unit tests at engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
abc1285262
commit
9e48ba08f9
@@ -439,7 +439,33 @@ func TestCacheDataFromDBFilterIndexes(t *testing.T) {
|
||||
if err := dm.CacheDataFromDB(utils.DispatcherFilterIndexes, nil, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
chgFlt := &Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLT_CPP",
|
||||
Rules: []*FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "Charger",
|
||||
Values: []string{"Charger1"},
|
||||
},
|
||||
},
|
||||
}
|
||||
dm.SetFilter(chgFlt)
|
||||
cpp := &ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Default",
|
||||
FilterIDs: []string{"*string:~*req.Destination:+1442",
|
||||
"*prefix:~*opts.Accounts:1002;1004"},
|
||||
RunID: utils.MetaDefault,
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
}
|
||||
if err := dm.SetChargerProfile(cpp, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := dm.CacheDataFromDB(utils.ChargerFilterIndexes, nil, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterIndexesRmtRpl(t *testing.T) {
|
||||
@@ -650,3 +676,60 @@ func TestDmRatingProfileCategory(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDmDispatcherHost(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
|
||||
dppH := &DispatcherHost{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ALL1",
|
||||
Conns: []*config.RemoteHost{
|
||||
{
|
||||
Address: "127.0.0.1:2012",
|
||||
Transport: utils.MetaJSON,
|
||||
TLS: true,
|
||||
},
|
||||
{
|
||||
Address: "127.0.0.1:3012",
|
||||
Transport: utils.MetaJSON,
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dm.SetDispatcherHost(dppH); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := dm.GetDispatcherHost("cgrates.org", "ALL1", false, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := dm.RemoveDispatcherHost("cgrates.org", "ALL1", utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDmRemoveThresholdProfile(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
|
||||
thP := &ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "THD_ACNT_1001",
|
||||
FilterIDs: []string{"*prefix:Destination:46"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
|
||||
},
|
||||
MaxHits: -1,
|
||||
MinSleep: time.Duration(0),
|
||||
Blocker: false,
|
||||
Weight: 10.0,
|
||||
ActionIDs: []string{"TOPUP_MONETARY_10"},
|
||||
Async: false,
|
||||
}
|
||||
dm.SetThresholdProfile(thP, true)
|
||||
|
||||
if err := dm.RemoveThresholdProfile("cgrates.org", "THD_ACNT_1001", utils.NonTransactional, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2059,3 +2059,62 @@ func TestUpdateFilterIndexes(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestFilterSPass11(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
acc := &Account{
|
||||
ID: "cgrates.org:1001",
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.VOICE: {
|
||||
&Balance{Value: 20 * float64(time.Second),
|
||||
DestinationIDs: utils.NewStringMap("DST1"),
|
||||
Weight: 10},
|
||||
&Balance{Value: 100 * float64(time.Second),
|
||||
DestinationIDs: utils.NewStringMap("DST2"), Weight: 20},
|
||||
}},
|
||||
}
|
||||
rsr := &Resource{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RL1",
|
||||
|
||||
Usages: map[string]*ResourceUsage{
|
||||
"RU1": {
|
||||
ID: "RU1",
|
||||
ExpiryTime: time.Date(2014, 7, 3, 13, 43, 0, 0, time.UTC),
|
||||
Units: 2,
|
||||
},
|
||||
},
|
||||
TTLIdx: []string{"RU1"},
|
||||
}
|
||||
dm.SetResource(rsr)
|
||||
dm.SetAccount(acc)
|
||||
fltrAcc := &Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_ACC",
|
||||
Rules: []*FilterRule{{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*accounts.1001.BalanceMap.*voice[0].Value",
|
||||
Values: []string{utils.IfaceAsString(20 * float64(time.Second))},
|
||||
}},
|
||||
}
|
||||
fltrRes := &Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_RES",
|
||||
Rules: []*FilterRule{
|
||||
{
|
||||
Type: "*lte",
|
||||
Element: "~*resources.RL1.Usage.RUI.Units",
|
||||
Values: []string{"2"},
|
||||
},
|
||||
},
|
||||
}
|
||||
dm.SetFilter(fltrRes)
|
||||
ev := &utils.MapStorage{}
|
||||
dm.SetFilter(fltrAcc)
|
||||
fS := NewFilterS(cfg, nil, dm)
|
||||
if _, err := fS.Pass("cgrates.org", []string{"FLTR_ACC", "FLTR_RES"}, ev); err == nil { //unfinished
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user