Add coverage tests for engine

This commit is contained in:
NikolasPetriti
2023-09-13 17:07:18 +02:00
committed by Dan Christian Bogos
parent d68a0d7e64
commit 49f0fa439c
3 changed files with 337 additions and 0 deletions

View File

@@ -537,3 +537,56 @@ func TestRatingPlanEqual(t *testing.T) {
t.Error(rcv)
}
}
func TestRAtingPlangetFirstUnsaneRating(t *testing.T) {
str := "test"
rt := &RITiming{
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{},
StartTime: "00:00:00",
EndTime: "00:00:00",
cronString: str,
tag: str,
}
rr := &RIRate{
ConnectFee: fl,
RoundingMethod: str,
RoundingDecimals: nm,
MaxCost: fl,
MaxCostStrategy: str,
Rates: RateGroups{{
GroupIntervalStart: 0 * time.Second,
Value: fl,
RateIncrement: 0 * time.Second,
RateUnit: 0 * time.Second,
}, {
GroupIntervalStart: 1 * time.Second,
Value: fl,
RateIncrement: 1 * time.Second,
RateUnit: 1 * time.Second,
}},
tag: "TestTag",
}
rl := RPRateList{{
Timing: str,
Rating: str,
Weight: fl,
}}
rp := &RatingPlan{
Id: "test2",
Timings: map[string]*RITiming{str: rt},
Ratings: map[string]*RIRate{str: rr},
DestinationRates: map[string]RPRateList{str: rl},
}
rcv := rp.getFirstUnsaneRating()
if rcv != "TestTag" {
t.Error(rcv)
}
}

View File

@@ -99,3 +99,118 @@ func TestSureTaxNewSureTaxRequest(t *testing.T) {
t.Error(rcv)
}
}
func TestSureTaxSureTaxProcessCdr(t *testing.T) {
str := "test"
var nm int64 = 1
fl := 1.2
bl := false
td := 1 * time.Second
tm := time.Date(2023, 8, 17, 20, 34, 58, 651387237, time.UTC)
tm2 := time.Date(2023, 8, 17, 20, 34, 59, 651387237, time.UTC)
nm2 := 1
ct := &ChargedTiming{
Years: utils.Years{1, 2},
Months: utils.Months{2, 3},
MonthDays: utils.MonthDays{4, 5},
WeekDays: utils.WeekDays{2, 3},
StartTime: "Time",
}
r := &Rate{
GroupIntervalStart: td,
Value: fl,
RateIncrement: td,
RateUnit: td,
}
rg := RateGroups{r}
rm := RatingMatchedFilters{str: nm2}
bc := &BalanceCharge{
AccountID: str,
BalanceUUID: str,
RatingID: str,
Units: fl,
ExtraChargeID: str,
}
ru := &RatingUnit{
ConnectFee: fl,
RoundingMethod: str,
RoundingDecimals: nm2,
MaxCost: fl,
MaxCostStrategy: str,
TimingID: str,
RatesID: str,
RatingFiltersID: str,
}
cdr := &CDR{
CGRID: str,
RunID: str,
OrderID: nm,
OriginHost: str,
Source: str,
OriginID: str,
ToR: str,
RequestType: str,
Tenant: str,
Category: str,
Account: str,
Subject: str,
Destination: str,
SetupTime: tm,
AnswerTime: tm2,
Usage: td,
ExtraFields: map[string]string{str: str},
ExtraInfo: str,
Partial: bl,
PreRated: bl,
CostSource: str,
Cost: fl,
CostDetails: &EventCost{
CGRID: str,
RunID: str,
StartTime: tm,
Usage: &td,
Cost: &fl,
Charges: []*ChargingInterval{{
RatingID: str,
Increments: []*ChargingIncrement{{
Usage: td,
Cost: fl,
AccountingID: str,
CompressFactor: nm2,
}},
CompressFactor: nm2,
usage: &td,
ecUsageIdx: &td,
cost: &fl,
}},
AccountSummary: &AccountSummary{
Tenant: str,
ID: str,
BalanceSummaries: BalanceSummaries{{
UUID: str,
ID: str,
Type: str,
Value: fl,
Disabled: bl,
}},
AllowNegative: bl,
Disabled: bl,
},
Rating: Rating{str: ru},
Accounting: Accounting{str: bc},
RatingFilters: RatingFilters{str: rm},
Rates: ChargedRates{str: rg},
Timings: ChargedTimings{str: ct},
},
}
err := SureTaxProcessCdr(cdr)
if err != nil {
if err.Error() != `Post "": unsupported protocol scheme ""` {
t.Error(err)
}
} else {
t.Error("was expecting an error")
}
}

169
engine/tpexporter_test.go Normal file
View File

@@ -0,0 +1,169 @@
/*
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 (
"archive/zip"
"bytes"
"reflect"
"testing"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
func TestTpExporterNewTPExporter(t *testing.T) {
str := "test"
bl := false
sSCfg, _ := config.NewDefaultCGRConfig()
mpStr := NewInternalDB(nil, nil, true, sSCfg.DataDbCfg().Items)
rcv, err := NewTPExporter(mpStr, str, str, str, str, false)
if err != nil {
if err.Error() != "Unsupported file format" {
t.Error(err)
}
} else {
t.Error("was expecting an error")
}
if rcv != nil {
t.Error(rcv)
}
rcv, err = NewTPExporter(mpStr, "", str, utils.CSV, str, false)
if err != nil {
if err.Error() != "Missing TPid" {
t.Error(err)
}
} else {
t.Error("was expecting an error")
}
if rcv != nil {
t.Error(rcv)
}
rcv, err = NewTPExporter(mpStr, str, str, utils.CSV, str, bl)
if err != nil {
t.Error(err)
}
exp := &TPExporter{
storDb: mpStr,
tpID: str,
exportPath: str,
fileFormat: utils.CSV,
sep: 't',
compress: bl,
cacheBuff: new(bytes.Buffer),
}
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("\nexpected %v\nreceived %v\n", exp, rcv)
}
rcv, err = NewTPExporter(mpStr, str, str, utils.CSV, "", bl)
if err != nil {
if err.Error() != "Invalid field separator: " {
t.Error(err)
}
} else {
t.Error("was expecting an error")
}
if rcv != nil {
t.Error(rcv)
}
rcv, err = NewTPExporter(mpStr, str, str, utils.CSV, str, true)
if err != nil {
if err.Error() != "open test/tpexport.zip: no such file or directory" {
t.Error(err)
}
} else {
t.Error("was expecting an error")
}
if rcv != nil {
t.Error(rcv)
}
rcv, err = NewTPExporter(mpStr, str, "", utils.CSV, str, true)
if err != nil {
t.Error(err)
}
exp2 := &TPExporter{
storDb: mpStr,
tpID: str,
exportPath: "",
fileFormat: utils.CSV,
sep: 't',
compress: true,
cacheBuff: exp.cacheBuff,
zipWritter: zip.NewWriter(exp.cacheBuff),
}
if !reflect.DeepEqual(rcv, exp2) {
t.Errorf("\nexpected %v\nreceived %v\n", exp2, rcv)
}
}
func TestTpExporterExportStats(t *testing.T) {
str := "test"
bl := false
sSCfg, _ := config.NewDefaultCGRConfig()
mpStr := NewInternalDB(nil, nil, true, sSCfg.DataDbCfg().Items)
self, err := NewTPExporter(mpStr, str, str, utils.CSV, str, bl)
if err != nil {
t.Error(err)
}
rcv := self.ExportStats()
exp := &utils.ExportedTPStats{
ExportPath: str,
Compressed: bl,
}
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("\nexpected %v\nreceived %v\n", utils.ToJSON(exp), utils.ToJSON(rcv))
}
}
func TestTpExporterGetCacheBuffer(t *testing.T) {
str := "test"
bl := false
sSCfg, _ := config.NewDefaultCGRConfig()
mpStr := NewInternalDB(nil, nil, true, sSCfg.DataDbCfg().Items)
self, err := NewTPExporter(mpStr, str, str, utils.CSV, str, bl)
if err != nil {
t.Error(err)
}
rcv := self.GetCacheBuffer()
exp := new(bytes.Buffer)
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("\nexpected %v\nreceived %v\n", utils.ToJSON(exp), utils.ToJSON(rcv))
}
}