improving coverage test at engine

This commit is contained in:
gezimbll
2022-11-16 09:59:47 -05:00
committed by Dan Christian Bogos
parent a04925bf51
commit c51cc36d43
5 changed files with 238 additions and 19 deletions

View File

@@ -2818,6 +2818,11 @@ func BenchmarkUUID(b *testing.B) {
}
func TestResetAccountCDR(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
idb := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
dm := NewDataManager(idb, cfg.CacheCfg(), nil)
fltrs := NewFilterS(cfg, nil, dm)
SetCdrStorage(idb)
var extraData interface{}
acc := &Account{
ID: "cgrates.org:1001",
@@ -2857,9 +2862,9 @@ func TestResetAccountCDR(t *testing.T) {
balanceValue: 10,
},
}
if err := resetAccountCDR(nil, a, acs, nil, extraData); err == nil {
t.Error(err)
} else if err = resetAccountCDR(acc, a, acs, nil, extraData); err == nil {
if err := resetAccountCDR(nil, a, acs, fltrs, extraData); err == nil || err.Error() != "nil account" {
t.Errorf("expected <nil account> ,received <%+v>", err)
} else if err = resetAccountCDR(acc, a, acs, fltrs, extraData); err == nil {
t.Error(err)
}
}
@@ -2890,6 +2895,42 @@ func TestSetRecurrentAction(t *testing.T) {
}
func TestActionSetDDestinations(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
cfg.RalsCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg)}
cfg.GeneralCfg().DefaultTenant = "cgrates.org"
ccMock := &ccMock{
calls: map[string]func(args interface{}, reply interface{}) error{
utils.StatSv1GetStatQueue: func(args, reply interface{}) error {
rpl := &StatQueue{
Tenant: "cgrates",
ID: "id",
SQMetrics: map[string]StatMetric{
utils.MetaDDC: &StatDDC{
FilterIDs: []string{"filters"},
Count: 7,
},
},
SQItems: []SQItem{
{
EventID: "event1",
}, {
EventID: "event2",
},
},
}
*reply.(*StatQueue) = *rpl
return nil
},
},
}
clientconn := make(chan rpcclient.ClientConnector, 1)
clientconn <- ccMock
connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientconn,
})
SetConnManager(connMgr)
config.SetCgrConfig(cfg)
ub := &Account{
ID: "ACCID",
ActionTriggers: ActionTriggers{
@@ -2911,7 +2952,7 @@ func TestActionSetDDestinations(t *testing.T) {
DestinationIDs: utils.StringMap{
"*ddc_dest": true,
"*dest": false,
"*ddcdest": false,
}},
},
utils.MetaVoice: {
@@ -2932,7 +2973,7 @@ func TestActionSetDDestinations(t *testing.T) {
a := &Action{
Id: "CDRLog1",
ActionType: utils.CDRLog,
ExtraParameters: "{\"BalanceID\":\"~*acnt.BalanceID\",\"ActionID\":\"~*act.ActionID\",\"BalanceValue\":\"~*acnt.BalanceValue\"}",
ExtraParameters: "{\"BalanceID\";\"~*acnt.BalanceID\";\"ActionID\";\"~*act.ActionID\";\"BalanceValue\";\"~*acnt.BalanceValue\"}",
Weight: 50,
}
acs := Actions{
@@ -3019,12 +3060,31 @@ func TestActionPublishAccount(t *testing.T) {
},
}
if err := publishAccount(ub, a, acs, nil, nil); err != nil {
t.Error(err)
t.Errorf("received %v", err)
}
}
func TestExportAction(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
cfg.ApierCfg().EEsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.EEsConnsCfg)}
config.SetCgrConfig(cfg)
ccMock := &ccMock{
calls: map[string]func(args, reply interface{}) error{
utils.EeSv1ProcessEvent: func(args, reply interface{}) error {
rpl := &map[string]map[string]interface{}{}
*reply.(*map[string]map[string]interface{}) = *rpl
return nil
},
},
}
clientconn := make(chan rpcclient.ClientConnector, 1)
clientconn <- ccMock
connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
utils.ConcatenatedKey(utils.MetaInternal, utils.EEsConnsCfg): clientconn,
})
SetConnManager(connMgr)
ub := &Account{
ID: "ACCID",
ActionTriggers: ActionTriggers{
@@ -3085,7 +3145,67 @@ func TestExportAction(t *testing.T) {
balanceValue: 10,
},
}
if err := export(ub, a, acs, nil, utils.CGREvent{Tenant: "cgrates.org", ID: "id"}); err == nil {
t.Error(err)
if err := export(ub, a, acs, nil, utils.CGREvent{Tenant: "cgrates.org", ID: "id"}); err != nil {
t.Errorf("received %v", err)
}
}
func TestResetStatQueue(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
cfg.SchedulerCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg)}
ccMock := &ccMock{
calls: map[string]func(args interface{}, reply interface{}) error{
utils.StatSv1ResetStatQueue: func(args, reply interface{}) error {
rpl := "reset"
*reply.(*string) = rpl
return nil
},
},
}
clientconn := make(chan rpcclient.ClientConnector, 1)
clientconn <- ccMock
connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientconn,
})
SetConnManager(connMgr)
config.SetCgrConfig(cfg)
ub := &Account{}
a := &Action{
ExtraParameters: "cgrates.org:id",
}
acs := Actions{}
if err := resetStatQueue(ub, a, acs, nil, nil); err == nil {
t.Errorf("received <%+v>", err)
}
}
func TestResetTreshold(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
cfg.SchedulerCfg().ThreshSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ThreshSConnsCfg)}
ccMock := &ccMock{
calls: map[string]func(args interface{}, reply interface{}) error{
utils.ThresholdSv1ResetThreshold: func(args, reply interface{}) error {
rpl := "threshold_reset"
*reply.(*string) = rpl
return nil
},
},
}
clientconn := make(chan rpcclient.ClientConnector, 1)
clientconn <- ccMock
connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
utils.ConcatenatedKey(utils.MetaInternal, utils.ThreshSConnsCfg): clientconn,
})
SetConnManager(connMgr)
config.SetCgrConfig(cfg)
ub := &Account{}
a := &Action{
ExtraParameters: "cgrates.org:id",
}
acs := Actions{}
if err := resetThreshold(ub, a, acs, nil, nil); err != nil {
t.Errorf("received <%+v>", err)
}
}

View File

@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"reflect"
"testing"
"time"
@@ -595,12 +596,46 @@ func TestBalanceDebitUnits(t *testing.T) {
Value: 12.22,
ExpirationDate: time.Date(2022, 11, 1, 20, 0, 0, 0, time.UTC),
Blocker: true,
Disabled: true,
Disabled: false,
precision: 2,
RatingSubject: "*zero34",
}
fltrs := FilterS{cfg, dm, nil}
config.SetCgrConfig(cfg)
exp := &CallCost{Category: "postpaid",
Tenant: "foehn",
Subject: "foehn", Account: "foehn",
Destination: "0034678096720", ToR: "*voice",
Cost: 0,
Timespans: TimeSpans{
{TimeStart: time.Date(2015, 4, 24, 7, 59, 4, 0, time.UTC),
TimeEnd: time.Date(2015, 4, 24, 8, 2, 0, 0, time.UTC),
Cost: 0,
RateInterval: &RateInterval{
Rating: &RIRate{
ConnectFee: 0,
RoundingDecimals: 0,
MaxCost: 0,
Rates: RateGroups{
{
GroupIntervalStart: 0,
Value: 0,
RateIncrement: 34,
RateUnit: 34},
}},
Weight: 0},
DurationIndex: 26,
MatchedSubject: "uuid",
MatchedPrefix: "0034678096720",
MatchedDestId: "*any",
RatingPlanId: "*none",
CompressFactor: 0}},
RatedUsage: 0,
}
if _, err := b.debitUnits(cd, ub, moneyBalances, true, false, true, &fltrs); err != nil {
t.Error(err)
if val, err := b.debitUnits(cd, ub, moneyBalances, true, false, true, &fltrs); err != nil {
t.Errorf("received %v", err)
} else if reflect.DeepEqual(val, exp) {
t.Errorf("expected %+v ,received %+v", utils.ToJSON(exp), utils.ToJSON(val))
}
}

View File

@@ -1196,8 +1196,8 @@ func TestMaxDebitWithAccountShared(t *testing.T) {
t.Errorf("Error debiting shared balance: %+v", other.BalanceMap[utils.MetaMonetary][0])
}
cd.account.Disabled = true
if _, err := cd.getAccount(); err == nil {
t.Error("expected nil")
if _, err := cd.getAccount(); err == nil || err != utils.ErrAccountDisabled {
t.Errorf("expected %v,received %v", utils.ErrAccountDisabled, err)
}
}
@@ -2552,19 +2552,42 @@ func TestValidateCallData(t *testing.T) {
}
func TestCDRefundRounding(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
cfg.GeneralCfg().LockingTimeout = 4 * time.Second
config.SetCgrConfig(cfg)
cd := &CallDescriptor{
Category: "call",
Tenant: "cgrates.org",
Subject: "1001",
Account: "1001",
Destination: "1002",
Increments: Increments{
&Increment{
BalanceInfo: &DebitInfo{
AccountID: "acc_id",
Unit: &UnitInfo{},
},
Duration: 1 * time.Minute,
Cost: 21,
},
&Increment{
BalanceInfo: &DebitInfo{
AccountID: "acc_id2",
Unit: &UnitInfo{},
},
Duration: 1 * time.Minute,
Cost: 21,
},
},
}
cfg := config.NewDefaultCGRConfig()
dataDB := NewInternalDB(nil, nil, true, nil)
dataDB := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
dm := NewDataManager(dataDB, cfg.CacheCfg(), nil)
fltrs := NewFilterS(cfg, nil, dm)
if _, err := cd.RefundRounding(fltrs); err != nil {
t.Error(err)
if val, err := cd.RefundRounding(fltrs); err != nil {
t.Errorf("received <%v>", err)
} else if reflect.DeepEqual(val, nil) {
t.Errorf("received %v", val)
}
}

View File

@@ -476,3 +476,40 @@ func TestCDRefundEventCost(t *testing.T) {
t.Error(err)
}
}
/*
func TestV2ProcessEvent(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
ccMock := &ccMock{
calls: map[string]func(args interface{}, reply interface{}) error{
utils.ResponderRefundIncrements: func(args, reply interface{}) error {
return nil
},
},
}
clientconn := make(chan rpcclient.ClientConnector, 1)
clientconn <- ccMock
connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{
utils.ConcatenatedKey(utils.MetaInternal, utils.ResponderRefundIncrements): clientconn,
})
cfg.CdrsCfg().RaterConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ResponderRefundIncrements)}
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
dm := NewDataManager(db, cfg.CacheCfg(), nil)
cdrS := &CDRServer{
cgrCfg: cfg,
cdrDb: db,
dm: dm,
connMgr: connMgr,
}
arg:=&ArgV1ProcessEvent{
Flags: []string{},
}
evs:=&[]*utils.EventWithFlags{
}
if err:=cdrS.V2ProcessEvent()
}
*/

View File

@@ -19,6 +19,7 @@ package engine
import (
"encoding/json"
"reflect"
"testing"
"github.com/cgrates/cgrates/utils"
@@ -171,10 +172,13 @@ func TestDynamicDPFieldAsInterface(t *testing.T) {
}
func TestDPNewLibNumber(t *testing.T) {
if _, err := newLibPhoneNumberDP("+3554735474"); err != nil {
exp := &libphonenumberDP{}
if val, err := newLibPhoneNumberDP("+3554735474"); err != nil {
t.Errorf("received <%v>", err)
} else if reflect.DeepEqual(val, exp) {
t.Errorf("expected %v,received %v", utils.ToJSON(exp), utils.ToJSON(val))
} else if _, err = newLibPhoneNumberDP("some"); err == nil {
t.Error("expected error")
t.Error("expected error ,received nil")
}
}