mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Improving coverage tests at engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
569c59af53
commit
a86d01be6b
@@ -265,3 +265,58 @@ func TestCacheSPreCache(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheV1HasItem(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
Cache.Clear(nil)
|
||||
chS := NewCacheS(cfg, dm)
|
||||
args := &utils.ArgsGetCacheItemWithArgDispatcher{
|
||||
ArgDispatcher: &utils.ArgDispatcher{},
|
||||
ArgsGetCacheItem: utils.ArgsGetCacheItem{
|
||||
CacheID: utils.CacheThresholds,
|
||||
ItemID: "cgrates.org:TH1",
|
||||
},
|
||||
}
|
||||
thd := &Threshold{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TH1",
|
||||
Hits: 2,
|
||||
}
|
||||
Cache.Set(utils.CacheThresholds, utils.ConcatenatedKey(thd.Tenant, thd.ID), thd, []string{}, true, utils.NonTransactional)
|
||||
var reply bool
|
||||
if err := chS.V1HasItem(args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheV1GetItemExpiryTime(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
cfg.CacheCfg()[utils.CacheThresholds].TTL = 24 * time.Hour
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
Cache.Clear(nil)
|
||||
chS := NewCacheS(cfg, dm)
|
||||
args := &utils.ArgsGetCacheItemWithArgDispatcher{
|
||||
ArgDispatcher: &utils.ArgDispatcher{},
|
||||
ArgsGetCacheItem: utils.ArgsGetCacheItem{
|
||||
CacheID: utils.CacheThresholds,
|
||||
ItemID: "cgrates.org:TH1",
|
||||
},
|
||||
}
|
||||
thd := &Threshold{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TH1",
|
||||
Hits: 2,
|
||||
}
|
||||
Cache.Set(utils.CacheThresholds, utils.ConcatenatedKey(thd.Tenant, thd.ID), thd, []string{}, true, utils.NonTransactional)
|
||||
var reply time.Time
|
||||
|
||||
if err := chS.V1GetItemExpiryTime(args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply.Day() != time.Now().Add(24*time.Hour).Day() {
|
||||
t.Error("Expected 1 Day ttl")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1617,3 +1617,79 @@ func TestDMRemSQPRepl(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDmRemoveFilter(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
cfg.DataDbCfg().Items[utils.MetaFilters].Replicate = true
|
||||
cfg.DataDbCfg().RplConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1)}
|
||||
defer func() {
|
||||
cfg2, _ := config.NewDefaultCGRConfig()
|
||||
config.SetCgrConfig(cfg2)
|
||||
}()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
clientConn := make(chan rpcclient.ClientConnector, 1)
|
||||
clientConn <- clMock(func(serviceMethod string, _, _ interface{}) error {
|
||||
if serviceMethod == utils.ReplicatorSv1RemoveFilter {
|
||||
|
||||
return nil
|
||||
}
|
||||
return utils.ErrNotImplemented
|
||||
})
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn}))
|
||||
dm.SetFilter(&Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_CP",
|
||||
Rules: []*FilterRule{
|
||||
{
|
||||
Type: utils.MetaString,
|
||||
Element: "~*req.Charger",
|
||||
Values: []string{"ChargerProfile2"},
|
||||
},
|
||||
},
|
||||
})
|
||||
dm.SetChargerProfile(&ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Ch1",
|
||||
FilterIDs: []string{"FLTR_CP"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 29, 15, 00, 0, 0, time.UTC),
|
||||
},
|
||||
RunID: "*rated",
|
||||
AttributeIDs: []string{"ATTR_1001_SIMPLEAUTH"},
|
||||
Weight: 20,
|
||||
}, true)
|
||||
config.SetCgrConfig(cfg)
|
||||
if err := dm.RemoveFilter("cgrates.org", "FLTR_CP", utils.NonTransactional); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
dm.RemoveChargerProfile("cgrates.org", "Ch1", "", true)
|
||||
if err := dm.RemoveFilter("cgrates.org", "FLTR_CP", utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
// func TestDMGetSupplierProfile(t *testing.T) {
|
||||
// cfg, _ := config.NewDefaultCGRConfig()
|
||||
// cfg.DataDbCfg().Items[utils.MetaSupplierProfiles].Remote = true
|
||||
// cfg.DataDbCfg().RmtConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1)}
|
||||
// defer func() {
|
||||
// cfg2, _ := config.NewDefaultCGRConfig()
|
||||
// config.SetCgrConfig(cfg2)
|
||||
// }()
|
||||
// clientConn := make(chan rpcclient.ClientConnector, 1)
|
||||
// clientConn <- clMock(func(serviceMethod string, _, _ interface{}) error {
|
||||
// if serviceMethod == utils.ReplicatorSv1GetSupplierProfile {
|
||||
// return nil
|
||||
// }
|
||||
// return utils.ErrNotFound
|
||||
// })
|
||||
// db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
// dm := NewDataManager(db, cfg.CacheCfg(), NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
|
||||
// utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn,
|
||||
// }))
|
||||
// config.SetCgrConfig(cfg)
|
||||
// if _, err := dm.GetSupplierProfile("cgrates.org", "SPL1", false, false, ""); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user