mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add coverage tests for engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
84cb2ddd1a
commit
a905707f93
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -198,3 +199,121 @@ func TestCallCostToDataCostError(t *testing.T) {
|
||||
t.Error("Failed to throw error on call to datacost!")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallCostGetStartTime(t *testing.T) {
|
||||
cc := CallCost{}
|
||||
|
||||
rcv := cc.GetStartTime()
|
||||
|
||||
if rcv.Minute() != time.Now().Minute() {
|
||||
t.Error(rcv)
|
||||
}
|
||||
|
||||
cc2 := CallCost{
|
||||
Timespans: TimeSpans{{TimeStart: time.Now()}},
|
||||
}
|
||||
|
||||
rcv = cc2.GetStartTime()
|
||||
|
||||
if rcv.Minute() != time.Now().Minute() {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallCostGetEndTime(t *testing.T) {
|
||||
cc := CallCost{}
|
||||
|
||||
rcv := cc.GetEndTime()
|
||||
|
||||
if rcv.Minute() != time.Now().Minute() {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallCostIsPaid(t *testing.T) {
|
||||
cc := CallCost{}
|
||||
|
||||
rcv := cc.IsPaid()
|
||||
|
||||
if rcv != true {
|
||||
t.Error(rcv)
|
||||
}
|
||||
|
||||
cc2 := CallCost{
|
||||
Timespans: TimeSpans{{Increments: Increments{}}},
|
||||
}
|
||||
|
||||
rcv = cc2.IsPaid()
|
||||
|
||||
if rcv != false {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallCostToDataCost(t *testing.T) {
|
||||
str := "test"
|
||||
bl := false
|
||||
fl := 1.2
|
||||
cc := CallCost{
|
||||
Category: str,
|
||||
Tenant: str,
|
||||
Subject: str,
|
||||
Account: str,
|
||||
Destination: str,
|
||||
ToR: str,
|
||||
Cost: fl,
|
||||
Timespans: TimeSpans{{
|
||||
Increments: Increments{{}},
|
||||
}},
|
||||
RatedUsage: fl,
|
||||
AccountSummary: &AccountSummary{},
|
||||
deductConnectFee: bl,
|
||||
negativeConnectFee: bl,
|
||||
maxCostDisconect: bl,
|
||||
}
|
||||
|
||||
exp := &DataCost{
|
||||
Category: cc.Category,
|
||||
Tenant: cc.Tenant,
|
||||
Subject: cc.Subject,
|
||||
Account: cc.Account,
|
||||
Destination: cc.Destination,
|
||||
ToR: cc.ToR,
|
||||
Cost: cc.Cost,
|
||||
deductConnectFee: cc.deductConnectFee,
|
||||
DataSpans: []*DataSpan{{
|
||||
DataStart: 0,
|
||||
DataEnd: 0,
|
||||
Cost: 0,
|
||||
ratingInfo: nil,
|
||||
RateInterval: nil,
|
||||
DataIndex: 0,
|
||||
Increments: []*DataIncrement{{}},
|
||||
MatchedSubject: "",
|
||||
MatchedPrefix: "",
|
||||
MatchedDestId: "",
|
||||
RatingPlanId: "",
|
||||
}},
|
||||
}
|
||||
|
||||
rcv, err := cc.ToDataCost()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("expected %v\n received %v\n", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallCostUpdateCost(t *testing.T) {
|
||||
cc := CallCost{
|
||||
deductConnectFee: false,
|
||||
}
|
||||
|
||||
cc.UpdateCost()
|
||||
|
||||
if cc.deductConnectFee != true {
|
||||
t.Error("didn't update")
|
||||
}
|
||||
}
|
||||
69
engine/cdre_test.go
Normal file
69
engine/cdre_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package engine
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
)
|
||||
|
||||
func TestCDRENewCDRExporter(t *testing.T) {
|
||||
_, err := NewCDRExporter([]*CDR{}, &config.CdreCfg{}, "test", "test", "test", "test", false, 1, 'a', false, []string{}, &FilterS{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDREmetaHandler(t *testing.T) {
|
||||
cdre := CDRExporter{}
|
||||
|
||||
rcv, err := cdre.metaHandler("test", "test")
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "Unsupported METATAG: test" {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if rcv != "" {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCDREcomposeHeader(t *testing.T) {
|
||||
cdre := CDRExporter{
|
||||
exportTemplate: &config.CdreCfg{
|
||||
Fields: []*config.FCTemplate{
|
||||
{
|
||||
Type: "*filler",
|
||||
Value: config.RSRParsers{{Rules: "test()"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := cdre.composeHeader()
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "err" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1224,51 +1224,51 @@ func TestLibeventcostChargedTimingFieldAsInterface(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg []string
|
||||
exp any
|
||||
err string
|
||||
arg []string
|
||||
exp any
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "empty filepath",
|
||||
arg: []string{},
|
||||
exp: nil,
|
||||
err: "NOT_FOUND",
|
||||
name: "empty filepath",
|
||||
arg: []string{},
|
||||
exp: nil,
|
||||
err: "NOT_FOUND",
|
||||
},
|
||||
{
|
||||
name: "empty filepath",
|
||||
arg: []string{"test"},
|
||||
exp: nil,
|
||||
err: "unsupported field prefix: <test>",
|
||||
name: "empty filepath",
|
||||
arg: []string{"test"},
|
||||
exp: nil,
|
||||
err: "unsupported field prefix: <test>",
|
||||
},
|
||||
{
|
||||
name: "Years case",
|
||||
arg: []string{"Years"},
|
||||
exp: utils.Years{1999},
|
||||
err: "",
|
||||
name: "Years case",
|
||||
arg: []string{"Years"},
|
||||
exp: utils.Years{1999},
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "Months case",
|
||||
arg: []string{"Months"},
|
||||
exp: utils.Months{time.August},
|
||||
err: "",
|
||||
name: "Months case",
|
||||
arg: []string{"Months"},
|
||||
exp: utils.Months{time.August},
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "MonthDays case",
|
||||
arg: []string{"MonthDays"},
|
||||
exp: utils.MonthDays{28},
|
||||
err: "",
|
||||
name: "MonthDays case",
|
||||
arg: []string{"MonthDays"},
|
||||
exp: utils.MonthDays{28},
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "WeekDays case",
|
||||
arg: []string{"WeekDays"},
|
||||
exp: utils.WeekDays{time.Friday},
|
||||
err: "",
|
||||
name: "WeekDays case",
|
||||
arg: []string{"WeekDays"},
|
||||
exp: utils.WeekDays{time.Friday},
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "StartTime case",
|
||||
arg: []string{"StartTime"},
|
||||
exp: "00:00:00",
|
||||
err: "",
|
||||
name: "StartTime case",
|
||||
arg: []string{"StartTime"},
|
||||
exp: "00:00:00",
|
||||
err: "",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1306,69 +1306,69 @@ func TestLibeventcostRatingUnitFieldAsInterface(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg []string
|
||||
exp any
|
||||
err string
|
||||
arg []string
|
||||
exp any
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "empty filepath",
|
||||
arg: []string{},
|
||||
exp: nil,
|
||||
err: "NOT_FOUND",
|
||||
name: "empty filepath",
|
||||
arg: []string{},
|
||||
exp: nil,
|
||||
err: "NOT_FOUND",
|
||||
},
|
||||
{
|
||||
name: "empty filepath",
|
||||
arg: []string{"test"},
|
||||
exp: nil,
|
||||
err: "unsupported field prefix: <test>",
|
||||
arg: []string{"test"},
|
||||
exp: nil,
|
||||
err: "unsupported field prefix: <test>",
|
||||
},
|
||||
{
|
||||
name: "ConnectFee case",
|
||||
arg: []string{"ConnectFee"},
|
||||
exp: fl,
|
||||
err: "",
|
||||
name: "ConnectFee case",
|
||||
arg: []string{"ConnectFee"},
|
||||
exp: fl,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "RoundingMethod case",
|
||||
arg: []string{"RoundingMethod"},
|
||||
exp: str,
|
||||
err: "",
|
||||
name: "RoundingMethod case",
|
||||
arg: []string{"RoundingMethod"},
|
||||
exp: str,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "RoundingDecimals case",
|
||||
arg: []string{"RoundingDecimals"},
|
||||
exp: nm,
|
||||
err: "",
|
||||
name: "RoundingDecimals case",
|
||||
arg: []string{"RoundingDecimals"},
|
||||
exp: nm,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "MaxCost case",
|
||||
arg: []string{"MaxCost"},
|
||||
exp: fl,
|
||||
err: "",
|
||||
name: "MaxCost case",
|
||||
arg: []string{"MaxCost"},
|
||||
exp: fl,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "MaxCostStrategy case",
|
||||
arg: []string{"MaxCostStrategy"},
|
||||
exp: str,
|
||||
err: "",
|
||||
name: "MaxCostStrategy case",
|
||||
arg: []string{"MaxCostStrategy"},
|
||||
exp: str,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "TimingID case",
|
||||
arg: []string{"TimingID"},
|
||||
exp: str,
|
||||
err: "",
|
||||
name: "TimingID case",
|
||||
arg: []string{"TimingID"},
|
||||
exp: str,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "RatesID case",
|
||||
arg: []string{"RatesID"},
|
||||
exp: str,
|
||||
err: "",
|
||||
name: "RatesID case",
|
||||
arg: []string{"RatesID"},
|
||||
exp: str,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "RatingFiltersID case",
|
||||
arg: []string{"RatingFiltersID"},
|
||||
exp: str,
|
||||
err: "",
|
||||
name: "RatingFiltersID case",
|
||||
arg: []string{"RatingFiltersID"},
|
||||
exp: str,
|
||||
err: "",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1508,9 +1508,9 @@ func TestLibeventcostChargedRatesFieldAsInterface(t *testing.T) {
|
||||
}},
|
||||
}
|
||||
|
||||
tests := []struct{
|
||||
name string
|
||||
arg []string
|
||||
tests := []struct {
|
||||
name string
|
||||
arg []string
|
||||
val any
|
||||
err string
|
||||
}{
|
||||
@@ -1535,24 +1535,24 @@ func TestLibeventcostChargedRatesFieldAsInterface(t *testing.T) {
|
||||
{
|
||||
name: "found",
|
||||
arg: []string{"test"},
|
||||
val: RateGroups{{
|
||||
GroupIntervalStart: tm,
|
||||
Value: 1.2,
|
||||
RateIncrement: tm,
|
||||
RateUnit: tm,
|
||||
}},
|
||||
err: "",
|
||||
val: RateGroups{{
|
||||
GroupIntervalStart: tm,
|
||||
Value: 1.2,
|
||||
RateIncrement: tm,
|
||||
RateUnit: tm,
|
||||
}},
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "found",
|
||||
arg: []string{"test[0]"},
|
||||
val: &Rate{
|
||||
GroupIntervalStart: tm,
|
||||
Value: 1.2,
|
||||
RateIncrement: tm,
|
||||
RateUnit: tm,
|
||||
},
|
||||
err: "",
|
||||
val: &Rate{
|
||||
GroupIntervalStart: tm,
|
||||
Value: 1.2,
|
||||
RateIncrement: tm,
|
||||
RateUnit: tm,
|
||||
},
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "found",
|
||||
@@ -1577,4 +1577,171 @@ func TestLibeventcostChargedRatesFieldAsInterface(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibeventcostChargedTimingsFieldAsInterface(t *testing.T) {
|
||||
ct := ChargedTiming{
|
||||
Years: utils.Years{1999},
|
||||
Months: utils.Months{time.August},
|
||||
MonthDays: utils.MonthDays{28},
|
||||
WeekDays: utils.WeekDays{time.Friday},
|
||||
StartTime: "00:00:00",
|
||||
}
|
||||
c := ChargedTimings{
|
||||
"test1": &ct,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
arg []string
|
||||
val any
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "empty filepath",
|
||||
arg: []string{},
|
||||
val: nil,
|
||||
err: "NOT_FOUND",
|
||||
},
|
||||
{
|
||||
name: "keyword not found",
|
||||
arg: []string{"test"},
|
||||
val: nil,
|
||||
err: "NOT_FOUND",
|
||||
},
|
||||
{
|
||||
name: "found",
|
||||
arg: []string{"test1"},
|
||||
val: &ct,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "found",
|
||||
arg: []string{"test1", "StartTime"},
|
||||
val: "00:00:00",
|
||||
err: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
rcv, err := c.FieldAsInterface(tt.arg)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != tt.err {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, tt.val) {
|
||||
t.Errorf("expected %v, received %v", tt.val, rcv)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibeventcostAccountingFieldAsInterface(t *testing.T) {
|
||||
bc := BalanceCharge{
|
||||
AccountID: "test",
|
||||
}
|
||||
ac := Accounting{
|
||||
"test1": &bc,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
arg []string
|
||||
val any
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "empty filepath",
|
||||
arg: []string{},
|
||||
val: nil,
|
||||
err: "NOT_FOUND",
|
||||
},
|
||||
{
|
||||
name: "keyword not found",
|
||||
arg: []string{"test"},
|
||||
val: nil,
|
||||
err: "NOT_FOUND",
|
||||
},
|
||||
{
|
||||
name: "found",
|
||||
arg: []string{"test1"},
|
||||
val: &bc,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "found",
|
||||
arg: []string{"test1", "AccountID"},
|
||||
val: "test",
|
||||
err: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
rcv, err := ac.FieldAsInterface(tt.arg)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != tt.err {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, tt.val) {
|
||||
t.Errorf("expected %v, received %v", tt.val, rcv)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibeventcostIfaceAsEventCost(t *testing.T) {
|
||||
e := EventCost{
|
||||
CGRID: "test",
|
||||
}
|
||||
mp := map[string]any{
|
||||
"CGRID": "test",
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg any
|
||||
exp *EventCost
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "EventCost case",
|
||||
arg: &e,
|
||||
exp: &e,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "map string interface case",
|
||||
arg: mp,
|
||||
exp: &e,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "default case",
|
||||
arg: 1,
|
||||
exp: nil,
|
||||
err: "not convertible : from: int to:*EventCost",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
rcv, err := IfaceAsEventCost(tt.arg)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != tt.err {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, tt.exp) {
|
||||
t.Errorf("expected %v, received %v", tt.exp, rcv)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user