mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 15:18:44 +05:00
Add coverage tests for engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
4c544f427c
commit
7b016eef3b
@@ -3602,7 +3602,7 @@ func TestEventCostString(t *testing.T) {
|
||||
e := EventCost{
|
||||
CGRID: "test",
|
||||
RunID: "test",
|
||||
StartTime: time.Date(2021, 8, 15, 14, 30, 45, 100, time.Local),
|
||||
StartTime: time.Date(2021, 8, 15, 14, 30, 45, 100, time.UTC),
|
||||
Usage: &tm,
|
||||
Cost: &fl,
|
||||
Charges: []*ChargingInterval{},
|
||||
@@ -3615,9 +3615,10 @@ func TestEventCostString(t *testing.T) {
|
||||
}
|
||||
|
||||
rcv := e.String()
|
||||
exp := `{"CGRID":"test","RunID":"test","StartTime":"2021-08-15T14:30:45.0000001Z","Usage":1000000000,"Cost":1.2,"Charges":[],"AccountSummary":{"Tenant":"","ID":"","BalanceSummaries":null,"AllowNegative":false,"Disabled":false},"Rating":{},"Accounting":{},"RatingFilters":{},"Rates":{},"Timings":{}}`
|
||||
|
||||
if rcv != `{"CGRID":"test","RunID":"test","StartTime":"2021-08-15T14:30:45.0000001+02:00","Usage":1000000000,"Cost":1.2,"Charges":[],"AccountSummary":{"Tenant":"","ID":"","BalanceSummaries":null,"AllowNegative":false,"Disabled":false},"Rating":{},"Accounting":{},"RatingFilters":{},"Rates":{},"Timings":{}}` {
|
||||
t.Error(rcv)
|
||||
if rcv != exp {
|
||||
t.Errorf("expected %s, received %s", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2712,10 +2712,10 @@ func TestModelHelpersAPItoModelTPAttribute(t *testing.T) {
|
||||
|
||||
func TestModelHelpersmodelEqual(t *testing.T) {
|
||||
type Test struct {
|
||||
Fl float64
|
||||
Nm int
|
||||
Bl bool
|
||||
Str string
|
||||
Fl float64 `index:"0"`
|
||||
Nm int `index:"1"`
|
||||
Bl bool `index:"2"`
|
||||
Str string `index:"3"`
|
||||
}
|
||||
tst := Test{
|
||||
Fl: fl,
|
||||
@@ -2723,6 +2723,24 @@ func TestModelHelpersmodelEqual(t *testing.T) {
|
||||
Bl: bl,
|
||||
Str: str,
|
||||
}
|
||||
tst2 := Test{
|
||||
Fl: 2.5,
|
||||
}
|
||||
tst3 := Test{
|
||||
Fl: fl,
|
||||
Nm: 5,
|
||||
}
|
||||
tst4 := Test{
|
||||
Fl: fl,
|
||||
Nm: nm,
|
||||
Bl: false,
|
||||
}
|
||||
tst5 := Test{
|
||||
Fl: fl,
|
||||
Nm: nm,
|
||||
Bl: bl,
|
||||
Str: "test1",
|
||||
}
|
||||
type args struct {
|
||||
this any
|
||||
other any
|
||||
@@ -2742,6 +2760,26 @@ func TestModelHelpersmodelEqual(t *testing.T) {
|
||||
args: args{nm, str},
|
||||
exp: false,
|
||||
},
|
||||
{
|
||||
name: "false return",
|
||||
args: args{tst, tst2},
|
||||
exp: false,
|
||||
},
|
||||
{
|
||||
name: "false return",
|
||||
args: args{tst, tst3},
|
||||
exp: false,
|
||||
},
|
||||
{
|
||||
name: "false return",
|
||||
args: args{tst, tst4},
|
||||
exp: false,
|
||||
},
|
||||
{
|
||||
name: "false return",
|
||||
args: args{tst, tst5},
|
||||
exp: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -2927,7 +2965,6 @@ func TestModelHelpersAPItoThresholdProfile(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := APItoThresholdProfile(tpST, "")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != errors.New("time: invalid duration "+`"`+errStr+`"`).Error() {
|
||||
t.Error(err)
|
||||
@@ -2943,3 +2980,280 @@ func TestModelHelpersAPItoThresholdProfile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAPItoDispatcherProfile(t *testing.T) {
|
||||
tpDPP := &utils.TPDispatcherProfile{
|
||||
StrategyParams: []any{str},
|
||||
Hosts: []*utils.TPDispatcherHostProfile{
|
||||
{
|
||||
Params: []any{""},
|
||||
},
|
||||
},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := APItoDispatcherProfile(tpDPP, "test")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "unknown time zone test" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAPItoChargerProfile(t *testing.T) {
|
||||
tpCPP := &utils.TPChargerProfile{
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := APItoChargerProfile(tpCPP, "test")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "unknown time zone test" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAPItoModelTPCharger(t *testing.T) {
|
||||
tpCPP := &utils.TPChargerProfile{
|
||||
FilterIDs: []string{},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
}
|
||||
|
||||
rcv := APItoModelTPCharger(tpCPP)
|
||||
exp := TPChargers{{
|
||||
ActivationInterval: "test;test",
|
||||
}}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("expected %v, received %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
|
||||
tpCPP2 := &utils.TPChargerProfile{
|
||||
FilterIDs: []string{"test"},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
}
|
||||
|
||||
rcv = APItoModelTPCharger(tpCPP2)
|
||||
exp = TPChargers{{
|
||||
FilterIDs: str,
|
||||
ActivationInterval: "test;test",
|
||||
}}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("expected %v, received %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAPItoAttributeProfile(t *testing.T) {
|
||||
errStr := "test`"
|
||||
tpAttr := &utils.TPAttributeProfile{
|
||||
Attributes: []*utils.TPAttribute{
|
||||
{
|
||||
Value: errStr,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_, err := APItoAttributeProfile(tpAttr, "")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "Unclosed unspilit syntax" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
tpAttr2 := &utils.TPAttributeProfile{
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
}
|
||||
|
||||
_, err = APItoAttributeProfile(tpAttr2, "test")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "unknown time zone test" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAPItoSupplierProfile(t *testing.T) {
|
||||
tpSPP := &utils.TPSupplierProfile{
|
||||
SortingParameters: slc,
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := APItoSupplierProfile(tpSPP, str)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "unknown time zone test" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAPItoFilter(t *testing.T) {
|
||||
tpTH := &utils.TPFilterProfile{
|
||||
Filters: []*utils.TPFilter{
|
||||
{
|
||||
Type: utils.MetaRSR,
|
||||
Values: []string{"test)"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_, err := APItoFilter(tpTH, "")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "invalid RSRFilter start rule in string: <test)>" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
tpTH2 := &utils.TPFilterProfile{
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
}
|
||||
|
||||
_, err = APItoFilter(tpTH2, "test")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "unknown time zone test" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAPItoModelTPThreshold(t *testing.T) {
|
||||
th := &utils.TPThresholdProfile{
|
||||
ActionIDs: []string{str},
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
}
|
||||
|
||||
rcv := APItoModelTPThreshold(th)
|
||||
exp := TpThresholds{{
|
||||
ActivationInterval: "test;test",
|
||||
ActionIDs: str,
|
||||
}}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("expected %v, received %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAPItoStatsErr(t *testing.T) {
|
||||
tpST := &utils.TPStatProfile{
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := APItoStats(tpST, "test")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "unknown time zone test" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAPItoModelResourceErrors(t *testing.T) {
|
||||
rl := &utils.TPResourceProfile{
|
||||
ActivationInterval: &utils.TPActivationInterval{
|
||||
ActivationTime: str,
|
||||
ExpiryTime: str,
|
||||
},
|
||||
ThresholdIDs: []string{str, str},
|
||||
}
|
||||
|
||||
rcv := APItoModelResource(rl)
|
||||
exp := TpResources{{
|
||||
ThresholdIDs: "test;test",
|
||||
ActivationInterval: "test;test",
|
||||
}}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("expected %v, received %v", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAsMapRates(t *testing.T) {
|
||||
tps := TpRates{{
|
||||
Id: 1,
|
||||
Tpid: str,
|
||||
Tag: str,
|
||||
ConnectFee: fl,
|
||||
Rate: fl,
|
||||
RateUnit: str,
|
||||
RateIncrement: str,
|
||||
GroupIntervalStart: str,
|
||||
}}
|
||||
|
||||
_, err := tps.AsMapRates()
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != `time: invalid duration "test"` {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelpersAsTPRates(t *testing.T) {
|
||||
tps := TpRates{{
|
||||
Id: 1,
|
||||
Tpid: str,
|
||||
Tag: str,
|
||||
ConnectFee: fl,
|
||||
Rate: fl,
|
||||
RateUnit: str,
|
||||
RateIncrement: str,
|
||||
GroupIntervalStart: str,
|
||||
}}
|
||||
|
||||
_, err := tps.AsTPRates()
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != `time: invalid duration "test"` {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelperscsvDump(t *testing.T) {
|
||||
type Test struct {
|
||||
Fl float64 `index:"a"`
|
||||
}
|
||||
tst := Test{1.2}
|
||||
|
||||
_, err := csvDump(&tst)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "invalid Test.Fl index a" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user