mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Improving Unit Test Coverage for Engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
4673b0023f
commit
68b06d573a
@@ -368,3 +368,70 @@ func TestBalancesSaveDirtyBalances(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBalancePublish(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
tmpDm := dm
|
||||
tmpConn := connMgr
|
||||
defer func() {
|
||||
cfg2, _ := config.NewDefaultCGRConfig()
|
||||
config.SetCgrConfig(cfg2)
|
||||
SetDataStorage(tmpDm)
|
||||
SetConnManager(tmpConn)
|
||||
}()
|
||||
cfg.RalsCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)}
|
||||
cfg.RalsCfg().ThresholdSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)}
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
clientConn := make(chan rpcclient.ClientConnector, 1)
|
||||
clientConn <- clMock(func(serviceMethod string, _, _ interface{}) error {
|
||||
if serviceMethod == utils.StatSv1ProcessEvent {
|
||||
|
||||
return nil
|
||||
} else if serviceMethod == utils.ThresholdSv1ProcessEvent {
|
||||
|
||||
return nil
|
||||
}
|
||||
return utils.ErrNotImplemented
|
||||
})
|
||||
connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
|
||||
utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientConn,
|
||||
utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): clientConn,
|
||||
})
|
||||
SetConnManager(connMgr)
|
||||
at := &ActionTrigger{
|
||||
UniqueID: "TestTR5",
|
||||
ThresholdType: utils.TRIGGER_MAX_BALANCE,
|
||||
Balance: &BalanceFilter{
|
||||
Type: utils.StringPointer(utils.VOICE),
|
||||
Weight: utils.Float64Pointer(10),
|
||||
},
|
||||
ActionsID: "ACT_1",
|
||||
}
|
||||
ub := &Account{
|
||||
ID: "cgrates.org:1001",
|
||||
BalanceMap: map[string]Balances{
|
||||
utils.VOICE: {
|
||||
{
|
||||
Value: 10,
|
||||
DestinationIDs: utils.NewStringMap("DEST"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
dm.SetActions("ACT_1", Actions{
|
||||
&Action{
|
||||
ActionType: utils.MetaPublishBalance,
|
||||
Balance: &BalanceFilter{
|
||||
Type: utils.StringPointer(utils.VOICE),
|
||||
Value: &utils.ValueFormula{Static: 15},
|
||||
},
|
||||
},
|
||||
}, utils.NonTransactional)
|
||||
config.SetCgrConfig(cfg)
|
||||
SetDataStorage(dm)
|
||||
if err := at.Execute(ub); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -447,3 +447,105 @@ func TestCDRSRateCDRs(t *testing.T) {
|
||||
t.Errorf("Expected 1,Received %d", cnt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDRSRateCDRSucces(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
cfg.CdrsCfg().SMCostRetries = 0
|
||||
cfg.CdrsCfg().RaterConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)}
|
||||
clientConn := make(chan rpcclient.ClientConnector, 1)
|
||||
clientConn <- clMock(func(serviceMethod string, _, reply interface{}) error {
|
||||
if serviceMethod == utils.ResponderDebit {
|
||||
rpl := CallCost{
|
||||
Destination: "1002",
|
||||
Timespans: []*TimeSpan{
|
||||
{
|
||||
TimeStart: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
|
||||
TimeEnd: time.Date(2018, 8, 24, 16, 00, 36, 0, time.UTC),
|
||||
ratingInfo: &RatingInfo{},
|
||||
DurationIndex: 0,
|
||||
RateInterval: &RateInterval{
|
||||
Rating: &RIRate{
|
||||
Rates: RateGroups{
|
||||
&Rate{GroupIntervalStart: 0,
|
||||
Value: 100,
|
||||
RateIncrement: 1,
|
||||
RateUnit: time.Nanosecond}}}},
|
||||
},
|
||||
},
|
||||
ToR: utils.SMS,
|
||||
}
|
||||
*reply.(*CallCost) = rpl
|
||||
return nil
|
||||
}
|
||||
return utils.ErrNotImplemented
|
||||
})
|
||||
connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
|
||||
utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): clientConn,
|
||||
})
|
||||
cdrS := &CDRServer{
|
||||
cgrCfg: cfg,
|
||||
cdrDb: db,
|
||||
dm: dm,
|
||||
connMgr: connMgr,
|
||||
}
|
||||
cdr := &CDRWithArgDispatcher{
|
||||
CDR: &CDR{CGRID: "Cdr1",
|
||||
OrderID: 101,
|
||||
ToR: utils.VOICE,
|
||||
OriginID: "OriginCDR1",
|
||||
OriginHost: "192.168.1.1",
|
||||
Source: "test",
|
||||
RequestType: utils.META_PREPAID,
|
||||
Tenant: "cgrates.org",
|
||||
Category: "call",
|
||||
Account: "1001",
|
||||
Subject: "1001",
|
||||
Destination: "1002",
|
||||
SetupTime: time.Date(2018, 8, 24, 16, 00, 00, 0, time.UTC),
|
||||
AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
|
||||
RunID: utils.MetaDefault,
|
||||
Usage: time.Duration(10) * time.Second,
|
||||
ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"},
|
||||
Cost: 1.01},
|
||||
}
|
||||
if _, err := cdrS.rateCDR(cdr); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV2StoreSessionCost(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
cfg.CacheCfg()[utils.CacheRPCResponses].Limit = 1
|
||||
Cache.Clear(nil)
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
cdrS := &CDRServer{
|
||||
cgrCfg: cfg,
|
||||
dm: dm,
|
||||
cdrDb: db,
|
||||
guard: guardian.Guardian,
|
||||
}
|
||||
args := &ArgsV2CDRSStoreSMCost{
|
||||
CheckDuplicate: true,
|
||||
Cost: &V2SMCost{
|
||||
CGRID: "testRPCMethodsCdrsStoreSessionCost",
|
||||
RunID: utils.MetaDefault,
|
||||
OriginHost: "",
|
||||
OriginID: "testdatagrp_grp1",
|
||||
CostSource: "SMR",
|
||||
Usage: 1536,
|
||||
CostDetails: &EventCost{
|
||||
AccountSummary: &AccountSummary{},
|
||||
},
|
||||
},
|
||||
}
|
||||
Cache.Set(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.CDRsV1StoreSessionCost, args.Cost.CGRID, args.Cost.RunID),
|
||||
&utils.CachedRPCResponse{Result: utils.OK, Error: nil},
|
||||
nil, true, utils.NonTransactional)
|
||||
var reply string
|
||||
if err := cdrS.V2StoreSessionCost(args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -859,3 +859,32 @@ func TestActionTriggerRplRmt(t *testing.T) {
|
||||
t.Errorf("Expected %v,Receive %v", attrs, vals)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDMRemoveAttributeProfile(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
|
||||
dm := NewDataManager(db, cfg.CacheCfg(), nil)
|
||||
attrPrf := &AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ATTR_1",
|
||||
FilterIDs: []string{"*string:~*req.Account:1007"},
|
||||
Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)},
|
||||
Attributes: []*Attribute{
|
||||
{
|
||||
Path: utils.MetaReq + utils.NestingSep + utils.Account,
|
||||
Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP),
|
||||
},
|
||||
{
|
||||
Path: utils.MetaReq + utils.NestingSep + utils.Subject,
|
||||
Value: config.NewRSRParsersMustCompile("1001", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Weight: 10.0,
|
||||
}
|
||||
dm.SetAttributeProfile(attrPrf, true)
|
||||
if err := dm.RemoveAttributeProfile("cgrates.org", "ATTR_1", utils.NonTransactional, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1072,3 +1072,62 @@ func TestResponderRounding(t *testing.T) {
|
||||
t.Error(utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponderDebitCached(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
defer func() {
|
||||
cfg2, _ := config.NewDefaultCGRConfig()
|
||||
config.SetCgrConfig(cfg2)
|
||||
}()
|
||||
cfg.CacheCfg()[utils.CacheRPCResponses].Limit = 2
|
||||
Cache.Clear(nil)
|
||||
tStart, _ := utils.ParseTimeDetectLayout("2022-08-07T17:30:00Z", utils.EmptyString)
|
||||
tEnd, _ := utils.ParseTimeDetectLayout("2022-08-07T17:31:30Z", utils.EmptyString)
|
||||
cd := &CallDescriptorWithArgDispatcher{
|
||||
CallDescriptor: &CallDescriptor{
|
||||
CgrID: "test",
|
||||
Category: "call",
|
||||
Tenant: "cgrates.org",
|
||||
Subject: "1001",
|
||||
Account: "1001",
|
||||
ToR: utils.VOICE,
|
||||
Destination: "1002",
|
||||
TimeStart: tStart,
|
||||
DurationIndex: 10 * time.Second,
|
||||
TimeEnd: tEnd,
|
||||
},
|
||||
}
|
||||
cc := &CallCost{
|
||||
Cost: 1.23,
|
||||
Destination: "1002",
|
||||
Timespans: []*TimeSpan{
|
||||
{
|
||||
TimeStart: time.Date(2022, 8, 7, 17, 30, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2022, 8, 7, 17, 31, 30, 0, time.UTC),
|
||||
DurationIndex: 0,
|
||||
RateInterval: &RateInterval{
|
||||
Rating: &RIRate{
|
||||
Rates: RateGroups{
|
||||
&Rate{
|
||||
GroupIntervalStart: 0,
|
||||
Value: 100,
|
||||
RateIncrement: 10 * time.Second,
|
||||
RateUnit: time.Second,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ToR: utils.VOICE,
|
||||
}
|
||||
Cache.Set(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.ResponderDebit, cd.CgrID),
|
||||
&utils.CachedRPCResponse{Result: cc, Error: nil},
|
||||
nil, true, utils.NonTransactional)
|
||||
config.SetCgrConfig(cfg)
|
||||
var reply CallCost
|
||||
if err := rsponder.Debit(cd, &reply); err == nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1039,15 +1039,16 @@ func TestTprReloadCache(t *testing.T) {
|
||||
}
|
||||
return utils.ErrNotImplemented
|
||||
})
|
||||
connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
|
||||
connMgr2 := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
|
||||
utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn,
|
||||
})
|
||||
|
||||
SetConnManager(connMgr)
|
||||
SetConnManager(connMgr2)
|
||||
tpr, err := NewTpReader(dataDb, storDb, "TEST_TP", "UTC", []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpr.dm.SetLoadIDs(map[string]int64{utils.CacheChargerProfiles: time.Now().UnixNano(), utils.CacheDispatcherProfiles: time.Now().UnixNano()})
|
||||
dests := []*utils.TPDestination{
|
||||
{
|
||||
TPid: "TEST_TP",
|
||||
@@ -1128,7 +1129,7 @@ func TestTpRLoadAll(t *testing.T) {
|
||||
},
|
||||
}
|
||||
rates := []*utils.TPRate{
|
||||
&utils.TPRate{
|
||||
{
|
||||
TPid: tpId,
|
||||
ID: "RATE1",
|
||||
RateSlots: []*utils.RateSlot{
|
||||
|
||||
Reference in New Issue
Block a user