mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 14:48:43 +05:00
Add/Improve coverage tests in engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
1b111b2492
commit
75f698db33
@@ -8884,3 +8884,182 @@ func TestDMSetRateProfileRatesSetRateProfileDrvErr(t *testing.T) {
|
||||
t.Errorf("Expected error <%v>, received error <%v>", utils.ErrNotImplemented, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDMSetRateProfileReplicate(t *testing.T) {
|
||||
|
||||
cfgtmp := config.CgrConfig()
|
||||
defer func() {
|
||||
config.SetCgrConfig(cfgtmp)
|
||||
}()
|
||||
Cache.Clear(nil)
|
||||
|
||||
rpp := &utils.RateProfile{
|
||||
ID: "test_ID1",
|
||||
Tenant: "cgrates.org",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Rates: map[string]*utils.Rate{},
|
||||
}
|
||||
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
cfg.DataDbCfg().Items[utils.MetaRateProfiles].Replicate = true
|
||||
cfg.DataDbCfg().RplConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)}
|
||||
config.SetCgrConfig(cfg)
|
||||
|
||||
cc := make(chan birpc.ClientConnector, 1)
|
||||
cc <- &ccMock{
|
||||
|
||||
calls: map[string]func(ctx *context.Context, args interface{}, reply interface{}) error{
|
||||
utils.ReplicatorSv1SetRateProfile: func(ctx *context.Context, args, reply interface{}) error { return utils.ErrNotImplemented },
|
||||
},
|
||||
}
|
||||
|
||||
cM := NewConnManager(cfg)
|
||||
cM.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator), utils.ReplicatorSv1, cc)
|
||||
data := &DataDBMock{
|
||||
GetRateProfileDrvF: func(ctx *context.Context, s1, s2 string) (*utils.RateProfile, error) {
|
||||
return rpp, nil
|
||||
},
|
||||
SetRateProfileDrvF: func(ctx *context.Context, rp *utils.RateProfile, b bool) error { return nil },
|
||||
}
|
||||
dm := NewDataManager(data, cfg.CacheCfg(), cM)
|
||||
|
||||
// tests replicate
|
||||
if err := dm.SetRateProfile(context.Background(), rpp, false, false); err != utils.ErrNotImplemented {
|
||||
t.Errorf("Expected error <%v>, received error <%v>", utils.ErrNotImplemented, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDMGetActionProfileCacheGetErr(t *testing.T) {
|
||||
|
||||
Cache.Clear(nil)
|
||||
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := NewInternalDB(nil, nil, cfg.DataDbCfg().Items)
|
||||
cM := NewConnManager(cfg)
|
||||
dm := NewDataManager(data, cfg.CacheCfg(), cM)
|
||||
|
||||
if err := Cache.Set(context.Background(), utils.CacheActionProfiles, utils.ConcatenatedKey(utils.CGRateSorg, "ap1"), nil, []string{}, true, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err := dm.GetActionProfile(context.Background(), utils.CGRateSorg, "ap1", true, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Errorf("Expected error <%v>, received error <%v>", utils.ErrNotFound, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDMGetActionProfileNilDmErr(t *testing.T) {
|
||||
|
||||
var dm *DataManager
|
||||
|
||||
_, err := dm.GetActionProfile(context.Background(), utils.CGRateSorg, "ap1", false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNoDatabaseConn {
|
||||
t.Errorf("Expected error <%v>, received error <%v>", utils.ErrNoDatabaseConn, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDMGetActionProfileSetActionProfileDrvErr(t *testing.T) {
|
||||
|
||||
cfgtmp := config.CgrConfig()
|
||||
defer func() {
|
||||
Cache = NewCacheS(config.CgrConfig(), nil, nil, nil)
|
||||
config.SetCgrConfig(cfgtmp)
|
||||
}()
|
||||
|
||||
ap := &ActionProfile{
|
||||
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AP1",
|
||||
FilterIDs: []string{"*string*req.Account1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 65,
|
||||
},
|
||||
},
|
||||
Schedule: "* * * * *",
|
||||
Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}},
|
||||
Actions: []*APAction{{}},
|
||||
}
|
||||
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
cfg.DataDbCfg().Items[utils.MetaActionProfiles].Remote = true
|
||||
cfg.DataDbCfg().RmtConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.RemoteConnsCfg)}
|
||||
config.SetCgrConfig(cfg)
|
||||
|
||||
cc := make(chan birpc.ClientConnector, 1)
|
||||
cc <- &ccMock{
|
||||
|
||||
calls: map[string]func(ctx *context.Context, args interface{}, reply interface{}) error{
|
||||
utils.ReplicatorSv1GetActionProfile: func(ctx *context.Context, args, reply interface{}) error { return nil },
|
||||
},
|
||||
}
|
||||
|
||||
cM := NewConnManager(cfg)
|
||||
cM.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal, utils.RemoteConnsCfg), utils.ReplicatorSv1, cc)
|
||||
data := &DataDBMock{
|
||||
GetActionProfileDrvF: func(ctx *context.Context, tenant, ID string) (*ActionProfile, error) { return ap, utils.ErrNotFound },
|
||||
SetActionProfileDrvF: func(ctx *context.Context, ap *ActionProfile) error { return utils.ErrNotImplemented },
|
||||
}
|
||||
dm := NewDataManager(data, cfg.CacheCfg(), cM)
|
||||
|
||||
_, err := dm.GetActionProfile(context.Background(), utils.CGRateSorg, ap.ID, false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotImplemented {
|
||||
t.Errorf("Expected error <%v>, received error <%v>", utils.ErrNotImplemented, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDMGetActionProfileCacheWriteErr1(t *testing.T) {
|
||||
|
||||
ap := &ActionProfile{
|
||||
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AP1",
|
||||
FilterIDs: []string{"*string*req.Account1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
Weight: 65,
|
||||
},
|
||||
},
|
||||
Schedule: "* * * * *",
|
||||
Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}},
|
||||
Actions: []*APAction{{}},
|
||||
}
|
||||
|
||||
cfgtmp := config.CgrConfig()
|
||||
defer func() {
|
||||
Cache = NewCacheS(config.CgrConfig(), nil, nil, nil)
|
||||
config.SetCgrConfig(cfgtmp)
|
||||
}()
|
||||
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
cfg.CacheCfg().ReplicationConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)}
|
||||
cfg.CacheCfg().Partitions[utils.CacheActionProfiles].Replicate = true
|
||||
config.SetCgrConfig(cfg)
|
||||
|
||||
cc := make(chan birpc.ClientConnector, 1)
|
||||
cc <- &ccMock{
|
||||
|
||||
calls: map[string]func(ctx *context.Context, args interface{}, reply interface{}) error{
|
||||
utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply interface{}) error {
|
||||
|
||||
return utils.ErrNotImplemented
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
cM := NewConnManager(cfg)
|
||||
cM.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator), utils.CacheSv1, cc)
|
||||
|
||||
data := &DataDBMock{
|
||||
GetActionProfileDrvF: func(ctx *context.Context, tenant, ID string) (*ActionProfile, error) { return ap, utils.ErrNotFound },
|
||||
}
|
||||
dm := NewDataManager(data, cfg.CacheCfg(), cM)
|
||||
|
||||
Cache = NewCacheS(cfg, dm, cM, nil)
|
||||
|
||||
_, err := dm.GetActionProfile(context.Background(), utils.CGRateSorg, ap.ID, false, true, utils.NonTransactional)
|
||||
if err != utils.ErrNotImplemented {
|
||||
t.Errorf("Expected error <%v>, received error <%v>", utils.ErrNotImplemented, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3804,9 +3804,12 @@ func TestStatQueueProcessEventProfileIDsErr(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
// unfinished should be unlocked from the main func
|
||||
func TestStatQueueProcessEventPrometheusStatIDsErr(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
Cache = NewCacheS(config.CgrConfig(), nil, nil, nil)
|
||||
}()
|
||||
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := NewInternalDB(nil, nil, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
@@ -3815,7 +3818,7 @@ func TestStatQueueProcessEventPrometheusStatIDsErr(t *testing.T) {
|
||||
|
||||
sqPrf := &StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SQ2",
|
||||
ID: "SQ1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
@@ -3839,7 +3842,7 @@ func TestStatQueueProcessEventPrometheusStatIDsErr(t *testing.T) {
|
||||
stq := &StatQueue{
|
||||
sqPrfl: sqPrf,
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SQ2",
|
||||
ID: "SQ1",
|
||||
SQItems: []SQItem{
|
||||
{
|
||||
EventID: "SqProcessEvent",
|
||||
@@ -3865,7 +3868,7 @@ func TestStatQueueProcessEventPrometheusStatIDsErr(t *testing.T) {
|
||||
},
|
||||
APIOpts: map[string]interface{}{
|
||||
utils.MetaUsage: "10s",
|
||||
utils.OptsStatsProfileIDs: []string{"SQ2"},
|
||||
utils.OptsStatsProfileIDs: []string{"SQ1"},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3887,12 +3890,15 @@ func TestStatQueueProcessEventPrometheusStatIDsErr(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
// unfinished should be unlocked from the main func
|
||||
func TestStatQueueProcessEventExpiredErr(t *testing.T) {
|
||||
|
||||
tmp := utils.Logger
|
||||
defer func() {
|
||||
utils.Logger = tmp
|
||||
Cache = NewCacheS(config.CgrConfig(), nil, nil, nil)
|
||||
}()
|
||||
|
||||
tmpl := utils.Logger
|
||||
defer func() {
|
||||
utils.Logger = tmpl
|
||||
}()
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
@@ -3961,7 +3967,7 @@ func TestStatQueueProcessEventExpiredErr(t *testing.T) {
|
||||
|
||||
if rcv, err := sS.processEvent(context.Background(), args.Tenant, args); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv != nil {
|
||||
} else if !reflect.DeepEqual([]string{"SQ1"}, rcv) {
|
||||
t.Errorf("expected: <%+v>, \nreceived: <%+v>", nil, rcv)
|
||||
|
||||
}
|
||||
@@ -3974,8 +3980,12 @@ func TestStatQueueProcessEventExpiredErr(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
// unfinished should be unlocked from the main func
|
||||
func TestStatQueueProcessEventBlockerErr(t *testing.T) {
|
||||
|
||||
defer func() {
|
||||
Cache = NewCacheS(config.CgrConfig(), nil, nil, nil)
|
||||
}()
|
||||
|
||||
cfg := config.NewDefaultCGRConfig()
|
||||
data := NewInternalDB(nil, nil, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(data, cfg.CacheCfg(), nil)
|
||||
@@ -3984,7 +3994,7 @@ func TestStatQueueProcessEventBlockerErr(t *testing.T) {
|
||||
|
||||
sqPrf := &StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SQ3",
|
||||
ID: "SQ1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Weights: utils.DynamicWeights{
|
||||
{
|
||||
@@ -4013,7 +4023,7 @@ func TestStatQueueProcessEventBlockerErr(t *testing.T) {
|
||||
stq := &StatQueue{
|
||||
sqPrfl: sqPrf,
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SQ3",
|
||||
ID: "SQ1",
|
||||
SQItems: []SQItem{
|
||||
{
|
||||
EventID: "SqProcessEvent",
|
||||
@@ -4039,7 +4049,7 @@ func TestStatQueueProcessEventBlockerErr(t *testing.T) {
|
||||
},
|
||||
APIOpts: map[string]interface{}{
|
||||
utils.MetaUsage: "10s",
|
||||
utils.OptsStatsProfileIDs: []string{"SQ3"},
|
||||
utils.OptsStatsProfileIDs: []string{"SQ1"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user