mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 08:38:45 +05:00
Improving coverage tests at engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
68b06d573a
commit
ae037931d0
@@ -2405,6 +2405,49 @@ func TestAccExecuteAT(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountSetRrecurrentAction(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
tmpDm := dm
|
||||
defer func() {
|
||||
cfg2, _ := config.NewDefaultCGRConfig()
|
||||
config.SetCgrConfig(cfg2)
|
||||
SetDataStorage(tmpDm)
|
||||
}()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
|
||||
ub := &Account{
|
||||
ID: "cgrates.org:1001",
|
||||
ActionTriggers: ActionTriggers{
|
||||
&ActionTrigger{Balance: &BalanceFilter{Type: utils.StringPointer(utils.MONETARY)},
|
||||
ThresholdValue: 2, ActionsID: "ACT_1", Executed: true},
|
||||
&ActionTrigger{Balance: &BalanceFilter{Type: utils.StringPointer(utils.MONETARY)},
|
||||
ThresholdValue: 2, ActionsID: "TEST_ACTIONS", Executed: true}},
|
||||
}
|
||||
aT := ActionTrigger{
|
||||
UniqueID: "TestTR3",
|
||||
ActionsID: "ACT_1",
|
||||
Balance: &BalanceFilter{
|
||||
Type: utils.StringPointer(utils.VOICE),
|
||||
Weight: utils.Float64Pointer(10),
|
||||
},
|
||||
}
|
||||
dm.SetActions("ACT_1", Actions{
|
||||
{ActionType: utils.SET_RECURRENT,
|
||||
Balance: &BalanceFilter{Type: utils.StringPointer(utils.MONETARY),
|
||||
Value: &utils.ValueFormula{Static: 25},
|
||||
DestinationIDs: utils.StringMapPointer(utils.NewStringMap("RET")),
|
||||
Weight: utils.Float64Pointer(20)}},
|
||||
}, utils.NonTransactional)
|
||||
|
||||
config.SetCgrConfig(cfg)
|
||||
SetDataStorage(dm)
|
||||
if err := aT.Execute(ub); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*********************************** Benchmarks *******************************/
|
||||
|
||||
func BenchmarkGetSecondForPrefix(b *testing.B) {
|
||||
|
||||
@@ -549,3 +549,74 @@ func TestV2StoreSessionCost(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
// func TestCRDSRefundEventCost(t *testing.T) {
|
||||
// cfg, _ := config.NewDefaultCGRConfig()
|
||||
// db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
// dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
// cfg.CdrsCfg().RaterConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)}
|
||||
// cdrS := &CDRServer{cgrCfg: cfg, dm: dm, cdrDb: db}
|
||||
|
||||
// clientConn := make(chan rpcclient.ClientConnector, 1)
|
||||
// clientConn <- clMock(func(serviceMethod string, _, _ interface{}) error {
|
||||
|
||||
// if serviceMethod == utils.ResponderRefundIncrements {
|
||||
|
||||
// return nil
|
||||
// }
|
||||
// return utils.ErrNotImplemented
|
||||
// })
|
||||
|
||||
// ec := &EventCost{
|
||||
// Cost: utils.Float64Pointer(10),
|
||||
// Accounting: map[string]*BalanceCharge{
|
||||
// "3463957": &BalanceCharge{
|
||||
// Units: 0.002623,
|
||||
// RatingID: "",
|
||||
// AccountID: "cgrates.org:1001",
|
||||
// BalanceUUID: "154419f2-45e0-4629-a203-06034ccb493f",
|
||||
// ExtraChargeID: "",
|
||||
// },
|
||||
// "fee8a3a": &BalanceCharge{
|
||||
// Units: 0.0787,
|
||||
// RatingID: "",
|
||||
// AccountID: "cgrates.org:1001",
|
||||
// BalanceUUID: "154419f2-45e0-4629-a203-06034ccb493f",
|
||||
// ExtraChargeID: "",
|
||||
// },
|
||||
// },
|
||||
// AccountSummary: &AccountSummary{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "1001",
|
||||
|
||||
// BalanceSummaries: []*BalanceSummary{
|
||||
// {ID: "voice2", Type: utils.VOICE, Value: 10, Disabled: false},
|
||||
// },
|
||||
// AllowNegative: true,
|
||||
// Disabled: false,
|
||||
// },
|
||||
// Charges: []*ChargingInterval{
|
||||
// {
|
||||
// RatingID: "c1a5ab9",
|
||||
// Increments: []*ChargingIncrement{
|
||||
// {
|
||||
// Usage: time.Duration(0),
|
||||
// Cost: 0.1,
|
||||
// AccountingID: "3463957",
|
||||
// CompressFactor: 1,
|
||||
// },
|
||||
// {
|
||||
// Usage: time.Duration(1 * time.Second),
|
||||
// Cost: 0,
|
||||
// AccountingID: "fee8a3a",
|
||||
// CompressFactor: 10,
|
||||
// },
|
||||
// },
|
||||
// CompressFactor: 1,
|
||||
// },
|
||||
// }}
|
||||
|
||||
// if err := cdrS.refundEventCost(ec, "*prepaid", "*monetary"); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -888,3 +888,62 @@ func TestDMRemoveAttributeProfile(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestThresholdProfileSetWithIndex(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
fltr1 := &Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_TH_2",
|
||||
Rules: []*FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Threshold",
|
||||
Values: []string{"TH_2"},
|
||||
},
|
||||
{
|
||||
Type: utils.MetaGreaterOrEqual,
|
||||
Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Weight,
|
||||
Values: []string{"15.0"},
|
||||
},
|
||||
},
|
||||
}
|
||||
dm.SetFilter(fltr1)
|
||||
thp := &ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "THD_AccDisableAndLog",
|
||||
FilterIDs: []string{"FLTR_TH_2"},
|
||||
MaxHits: -1,
|
||||
MinSleep: time.Duration(1 * time.Second),
|
||||
Weight: 20.0,
|
||||
Async: true,
|
||||
ActionIDs: []string{"DISABLE_LOG"},
|
||||
}
|
||||
dm.SetThresholdProfile(thp, true)
|
||||
fltr2 := &Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_TH_3",
|
||||
Rules: []*FilterRule{
|
||||
{
|
||||
Type: utils.MetaPrefix,
|
||||
Element: "~*req.Threshold",
|
||||
Values: []string{"THD"},
|
||||
},
|
||||
},
|
||||
}
|
||||
dm.SetFilter(fltr2)
|
||||
thp = &ThresholdProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "THD_AccDisableAndLog",
|
||||
FilterIDs: []string{"FLTR_TH_3"},
|
||||
MaxHits: -1,
|
||||
MinSleep: time.Duration(1 * time.Second),
|
||||
Weight: 20.0,
|
||||
Async: true,
|
||||
ActionIDs: []string{"DISABLE_LOG"},
|
||||
}
|
||||
if err := dm.SetThresholdProfile(thp, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2084,7 +2084,6 @@ func TestFilterSPass11(t *testing.T) {
|
||||
rsr := &Resource{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RL1",
|
||||
|
||||
Usages: map[string]*ResourceUsage{
|
||||
"RU1": {
|
||||
ID: "RU1",
|
||||
@@ -2134,14 +2133,13 @@ func TestFilterSPass11(t *testing.T) {
|
||||
})
|
||||
|
||||
fltrs := []*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))},
|
||||
Values: []string{"~*accounts.1001.BalanceMap.*voice[0].Value" + utils.IfaceAsString(20*float64(time.Second))},
|
||||
}},
|
||||
},
|
||||
{
|
||||
@@ -2151,7 +2149,7 @@ func TestFilterSPass11(t *testing.T) {
|
||||
{
|
||||
Type: "*lte",
|
||||
Element: "~*resources.RL1.Usage.RUI.Units",
|
||||
Values: []string{"2"},
|
||||
Values: []string{"~*resources.RL1.Usage.RUI.Units.2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2162,7 +2160,7 @@ func TestFilterSPass11(t *testing.T) {
|
||||
{
|
||||
Type: "*gt",
|
||||
Element: "~*stats.SQ_1.*asr",
|
||||
Values: []string{"10.0"},
|
||||
Values: []string{"~*stats.SQ_1.*asr.10.0"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1443,3 +1443,48 @@ func TestResourceService(t *testing.T) {
|
||||
|
||||
rS.Reload()
|
||||
}
|
||||
|
||||
func TestRSProcessThreshold(t *testing.T) {
|
||||
Cache.Clear(nil)
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, config.CgrConfig().CacheCfg(), nil)
|
||||
clientConn := make(chan rpcclient.ClientConnector, 1)
|
||||
clientConn <- clMock(func(serviceMethod string, _, _ interface{}) error {
|
||||
if serviceMethod == utils.ThresholdSv1ProcessEvent {
|
||||
return nil
|
||||
}
|
||||
return utils.ErrNotImplemented
|
||||
})
|
||||
connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
|
||||
utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): clientConn})
|
||||
rS, _ := NewResourceService(dm, cfg,
|
||||
NewFilterS(cfg, nil, dm), connMgr)
|
||||
cfg.ResourceSCfg().ThresholdSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)}
|
||||
rs := Resources{
|
||||
{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: "ResourceProfile1",
|
||||
Usages: map[string]*ResourceUsage{},
|
||||
TTLIdx: []string{},
|
||||
rPrf: resprf[0],
|
||||
},
|
||||
{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: "ResourceProfile2",
|
||||
Usages: map[string]*ResourceUsage{},
|
||||
TTLIdx: []string{},
|
||||
rPrf: resprf[1],
|
||||
},
|
||||
{
|
||||
Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
|
||||
ID: "ResourceProfile3",
|
||||
Usages: map[string]*ResourceUsage{},
|
||||
TTLIdx: []string{},
|
||||
rPrf: resprf[2],
|
||||
},
|
||||
}
|
||||
if err := rS.processThresholds(rs, nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user