mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 06:38:45 +05:00
Improving coverage test at engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
a3a8c5a4a4
commit
a2633a7fd7
@@ -2303,3 +2303,75 @@ func TestDmRemAccountActionPlans(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDMSetActionPlanRpl(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
clientConn := make(chan birpc.ClientConnector, 1)
|
||||
clientConn <- clMock(func(_ *context.Context, serviceMethod string, _, _ interface{}) error {
|
||||
if serviceMethod == utils.ReplicatorSv1SetActionPlan {
|
||||
return nil
|
||||
}
|
||||
return utils.ErrNotImplemented
|
||||
})
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), NewConnManager(cfg, map[string]chan birpc.ClientConnector{
|
||||
utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn,
|
||||
}))
|
||||
defer func() {
|
||||
cfg2, _ := config.NewDefaultCGRConfig()
|
||||
config.SetCgrConfig(cfg2)
|
||||
}()
|
||||
cfg.DataDbCfg().Items[utils.MetaAccountActionPlans].Replicate = true
|
||||
cfg.DataDbCfg().RplConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1)}
|
||||
testCases := []struct {
|
||||
name string
|
||||
key string
|
||||
ats *ActionPlan
|
||||
overwrite bool
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
name: "Remove Action",
|
||||
key: "Actions1",
|
||||
ats: &ActionPlan{
|
||||
Id: "Actions1",
|
||||
AccountIDs: utils.StringMap{"cgrates.org: 1001": true},
|
||||
ActionTimings: []*ActionTiming{},
|
||||
},
|
||||
expErr: false,
|
||||
overwrite: true,
|
||||
},
|
||||
{
|
||||
name: "Sett ActionPlans Replication",
|
||||
key: "MORE_MINUTES",
|
||||
ats: &ActionPlan{
|
||||
Id: "MORE_MINUTES",
|
||||
ActionTimings: []*ActionTiming{
|
||||
{
|
||||
Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Years: utils.Years{2022},
|
||||
Months: utils.Months{},
|
||||
MonthDays: utils.MonthDays{},
|
||||
WeekDays: utils.WeekDays{},
|
||||
StartTime: utils.ASAP,
|
||||
},
|
||||
},
|
||||
Weight: 10,
|
||||
ActionsID: "MINI",
|
||||
},
|
||||
},
|
||||
},
|
||||
overwrite: false,
|
||||
expErr: false,
|
||||
},
|
||||
}
|
||||
config.SetCgrConfig(cfg)
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if err := dm.SetActionPlan(tc.key, tc.ats, tc.overwrite, utils.NonTransactional); (err != nil) != tc.expErr {
|
||||
t.Errorf("Expected error:%v ,received %v", tc.expErr, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2492,5 +2492,90 @@ func TestComputeAttributeIndexesErr(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestComputeDispatcherIndexesErrs(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
testCases := []struct {
|
||||
name string
|
||||
dm *DataManager
|
||||
tenant string
|
||||
dspIDs *[]string
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
name: "DispatcherProfile Not Found",
|
||||
dm: dm,
|
||||
tenant: "cgrates.org",
|
||||
dspIDs: &[]string{"DISP_1"},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "Without Filter",
|
||||
dm: dm,
|
||||
tenant: "cgrates.org",
|
||||
dspIDs: &[]string{"DISP_2"},
|
||||
expErr: false,
|
||||
},
|
||||
}
|
||||
dm.SetDispatcherProfile(&DispatcherProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "DISP_2",
|
||||
Subsystems: []string{utils.MetaSessionS},
|
||||
}, true)
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if _, err := ComputeDispatcherIndexes(tc.dm, "cgrates.org", utils.MetaSessionS, tc.dspIDs, ""); (err != nil) != tc.expErr {
|
||||
t.Errorf("expected error: %v, received: %v", tc.expErr, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeResourceIndexesErrs(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
testCases := []struct {
|
||||
name string
|
||||
dm *DataManager
|
||||
tenant string
|
||||
resIDs *[]string
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
name: "ResourceProfile Not Found",
|
||||
dm: dm,
|
||||
tenant: "cgrates.org",
|
||||
resIDs: &[]string{"RES_1"},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "Without Filter",
|
||||
dm: dm,
|
||||
tenant: "cgrates.org",
|
||||
resIDs: &[]string{"RES_2"},
|
||||
expErr: true,
|
||||
},
|
||||
}
|
||||
dm.SetResourceProfile(&ResourceProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RES_2",
|
||||
FilterIDs: []string{"FLTR_RES"},
|
||||
UsageTTL: time.Duration(-1),
|
||||
Limit: 2,
|
||||
AllocationMessage: "Account1Channels",
|
||||
Weight: 20,
|
||||
ThresholdIDs: []string{utils.META_NONE},
|
||||
}, true)
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if _, err := ComputeResourceIndexes(tc.dm, "cgrates.org", tc.resIDs, ""); (err != nil) != tc.expErr {
|
||||
t.Errorf("expected error: %v, received: %v", tc.expErr, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user