Add coverage tests for engine

This commit is contained in:
NikolasPetriti
2023-08-17 16:24:58 +02:00
committed by Dan Christian Bogos
parent 5ef01e6f0b
commit b2ce0ce167
9 changed files with 340 additions and 76 deletions

View File

@@ -667,4 +667,4 @@ func TestBalanceCloneNil(t *testing.T) {
if rcv != nil {
t.Error(rcv)
}
}
}

View File

@@ -326,4 +326,4 @@ func TestCallCostUpdateRatedUsage(t *testing.T) {
if rcv != 0 {
t.Error(rcv)
}
}
}

View File

@@ -1636,4 +1636,4 @@ func TestCDRCloneNil(t *testing.T) {
if rcv != nil {
t.Error(rcv)
}
}
}

View File

@@ -3434,12 +3434,12 @@ func TestModelHelperscsvLoadErrors(t *testing.T) {
{
name: "index tag error",
args: args{tst, []string{"test"}},
err: "invalid Test.Fl index a",
err: "invalid Test.Fl index a",
},
{
name: "regex tag error",
args: args{tst2, []string{"123"}},
err: "invalid Test2.Field value 123",
err: "invalid Test2.Field value 123",
},
}

View File

@@ -454,14 +454,14 @@ func BenchmarkRatingPlanRestore(b *testing.B) {
func TestRatingPlanEqual(t *testing.T) {
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,
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{
@@ -470,13 +470,13 @@ func TestRatingPlanEqual(t *testing.T) {
RoundingDecimals: nm,
MaxCost: fl,
MaxCostStrategy: str,
Rates: RateGroups{{
Rates: RateGroups{{
GroupIntervalStart: 1 * time.Second,
Value: fl,
RateIncrement: 1 * time.Second,
RateUnit: 1 * time.Second,
}},
tag: str,
tag: str,
}
rl := RPRateList{{
@@ -486,21 +486,21 @@ func TestRatingPlanEqual(t *testing.T) {
}}
rp := &RatingPlan{
Id: "test",
Id: "test",
Timings: map[string]*RITiming{str: rt},
Ratings: map[string]*RIRate{str: rr},
DestinationRates: map[string]RPRateList{str: rl},
}
rt2 := &RITiming{
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{},
StartTime: "00:00:00",
EndTime: "00:00:00",
cronString: "val1",
tag: str,
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{},
StartTime: "00:00:00",
EndTime: "00:00:00",
cronString: "val1",
tag: str,
}
rr2 := &RIRate{
@@ -509,13 +509,13 @@ func TestRatingPlanEqual(t *testing.T) {
RoundingDecimals: nm,
MaxCost: fl,
MaxCostStrategy: str,
Rates: RateGroups{{
Rates: RateGroups{{
GroupIntervalStart: 1 * time.Second,
Value: fl,
RateIncrement: 1 * time.Second,
RateUnit: 1 * time.Second,
}},
tag: str,
tag: str,
}
rl2 := RPRateList{{
@@ -525,7 +525,7 @@ func TestRatingPlanEqual(t *testing.T) {
}}
o := &RatingPlan{
Id: "test2",
Id: "test2",
Timings: map[string]*RITiming{str: rt2},
Ratings: map[string]*RIRate{str: rr2},
DestinationRates: map[string]RPRateList{str: rl2},
@@ -536,4 +536,4 @@ func TestRatingPlanEqual(t *testing.T) {
if rcv != false {
t.Error(rcv)
}
}
}

View File

@@ -3059,14 +3059,14 @@ func TestStatMetricsGetFilterIDs(t *testing.T) {
FilterIDs: slc,
Sum: 1 * time.Second,
Count: 1,
Events: map[string]*DurationWithCompress{
Events: map[string]*DurationWithCompress{
str: {
Duration: 1 * time.Second,
Duration: 1 * time.Second,
CompressFactor: 1,
},
},
MinItems: 1,
val: &tm,
MinItems: 1,
val: &tm,
}
exp := slc
@@ -3084,14 +3084,14 @@ func TestStatMetricsGetFilterIDsStatTCD(t *testing.T) {
FilterIDs: slc,
Sum: 1 * time.Second,
Count: 1,
Events: map[string]*DurationWithCompress{
Events: map[string]*DurationWithCompress{
str: {
Duration: 1 * time.Second,
Duration: 1 * time.Second,
CompressFactor: 1,
},
},
MinItems: 1,
val: &tm,
MinItems: 1,
val: &tm,
}
exp := slc
@@ -3109,14 +3109,14 @@ func TestStatMetricsGetFloat64ValueStatACC(t *testing.T) {
FilterIDs: slc,
Sum: 1.2,
Count: 1,
Events: map[string]*StatWithCompress{
Events: map[string]*StatWithCompress{
"test": {
Stat: fl,
CompressFactor: 1,
},
},
MinItems: 1,
val: &fl,
MinItems: 1,
val: &fl,
}
exp := fl
@@ -3134,14 +3134,14 @@ func TestStatMetricsGetFilterIDsStatACC(t *testing.T) {
FilterIDs: slc,
Sum: 1.2,
Count: 1,
Events: map[string]*StatWithCompress{
Events: map[string]*StatWithCompress{
"test": {
Stat: fl,
CompressFactor: 1,
},
},
MinItems: 1,
val: &fl,
MinItems: 1,
val: &fl,
}
exp := slc
@@ -3159,14 +3159,14 @@ func TestStatMetricsGetFloat64ValueStatTCC(t *testing.T) {
FilterIDs: slc,
Sum: 1.2,
Count: 1,
Events: map[string]*StatWithCompress{
Events: map[string]*StatWithCompress{
"test": {
Stat: fl,
CompressFactor: 1,
},
},
MinItems: 1,
val: &fl,
MinItems: 1,
val: &fl,
}
exp := fl
@@ -3184,14 +3184,14 @@ func TestStatMetricsGetFilterIDsStatTCC(t *testing.T) {
FilterIDs: slc,
Sum: 1.2,
Count: 1,
Events: map[string]*StatWithCompress{
Events: map[string]*StatWithCompress{
"test": {
Stat: fl,
CompressFactor: 1,
},
},
MinItems: 1,
val: &fl,
MinItems: 1,
val: &fl,
}
exp := slc
@@ -3209,14 +3209,14 @@ func TestStatMetricsGetFilterIDsStatPDD(t *testing.T) {
FilterIDs: slc,
Sum: 1 * time.Second,
Count: 1,
Events: map[string]*DurationWithCompress{
Events: map[string]*DurationWithCompress{
str: {
Duration: 1 * time.Second,
Duration: 1 * time.Second,
CompressFactor: 1,
},
},
MinItems: 1,
val: &tm,
MinItems: 1,
val: &tm,
}
exp := slc
@@ -3230,9 +3230,9 @@ func TestStatMetricsGetFilterIDsStatPDD(t *testing.T) {
func TestStatMetricsGetFilterIDsStatDDC(t *testing.T) {
slc := []string{"test"}
acd := &StatDDC{
FilterIDs: slc,
MinItems: 1,
Count: 1,
FilterIDs: slc,
MinItems: 1,
Count: 1,
}
rcv := acd.GetValue()
@@ -3245,9 +3245,9 @@ func TestStatMetricsGetFilterIDsStatDDC(t *testing.T) {
func TestStatMetricsGetFilterIDsDDC(t *testing.T) {
slc := []string{"test"}
acd := &StatDDC{
FilterIDs: slc,
MinItems: 1,
Count: 1,
FilterIDs: slc,
MinItems: 1,
Count: 1,
}
rcv := acd.GetFilterIDs()
@@ -3263,14 +3263,14 @@ func TestStatMetricsGetValueSum(t *testing.T) {
FilterIDs: slc,
Sum: 1.2,
Count: 1,
Events: map[string]*StatWithCompress{
Events: map[string]*StatWithCompress{
"test": {
Stat: fl,
CompressFactor: 1,
},
},
MinItems: 1,
val: &fl,
MinItems: 1,
val: &fl,
}
rcv := acd.GetValue()
@@ -3286,14 +3286,14 @@ func TestStatMetricsGetFilterIDsSum(t *testing.T) {
FilterIDs: slc,
Sum: 1.2,
Count: 1,
Events: map[string]*StatWithCompress{
Events: map[string]*StatWithCompress{
"test": {
Stat: fl,
CompressFactor: 1,
},
},
MinItems: 1,
val: &fl,
MinItems: 1,
val: &fl,
}
rcv := acd.GetFilterIDs()
@@ -3309,14 +3309,14 @@ func TestStatMetricsGetValueAvarage(t *testing.T) {
FilterIDs: slc,
Sum: 1.2,
Count: 1,
Events: map[string]*StatWithCompress{
Events: map[string]*StatWithCompress{
"test": {
Stat: fl,
CompressFactor: 1,
},
},
MinItems: 1,
val: &fl,
MinItems: 1,
val: &fl,
}
rcv := acd.GetValue()
@@ -3332,14 +3332,14 @@ func TestStatMetricsGetFilterIDsAvarage(t *testing.T) {
FilterIDs: slc,
Sum: 1.2,
Count: 1,
Events: map[string]*StatWithCompress{
Events: map[string]*StatWithCompress{
"test": {
Stat: fl,
CompressFactor: 1,
},
},
MinItems: 1,
val: &fl,
MinItems: 1,
val: &fl,
}
rcv := acd.GetFilterIDs()
@@ -3352,9 +3352,9 @@ func TestStatMetricsGetFilterIDsAvarage(t *testing.T) {
func TestStatMetricsGetValueDistinct(t *testing.T) {
slc := []string{"test"}
acd := &StatDistinct{
FilterIDs: slc,
MinItems: 1,
Count: 1,
FilterIDs: slc,
MinItems: 1,
Count: 1,
}
rcv := acd.GetValue()
@@ -3367,9 +3367,9 @@ func TestStatMetricsGetValueDistinct(t *testing.T) {
func TestStatMetricsGetFilterIDsDistinct(t *testing.T) {
slc := []string{"test"}
acd := &StatDistinct{
FilterIDs: slc,
MinItems: 1,
Count: 1,
FilterIDs: slc,
MinItems: 1,
Count: 1,
}
rcv := acd.GetFilterIDs()

View File

@@ -0,0 +1,239 @@
/*
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 (
"reflect"
"testing"
"github.com/ugorji/go/codec"
)
func TestStorageInterfaceNewMarshaler(t *testing.T) {
str := "json"
rcv, err := NewMarshaler(str)
exp := new(JSONMarshaler)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("expected %v, received %v", exp, rcv)
}
}
func TestSorageInterfaceMarshal(t *testing.T) {
type Test struct {
Field string
}
arg := Test{
Field: "test",
}
jm := BSONMarshaler{}
rcv, err := jm.Marshal(&arg)
if err != nil {
t.Error(err)
}
exp := []byte{21, 0, 0, 0, 2, 102, 105, 101, 108, 100, 0, 5, 0, 0, 0, 116, 101, 115, 116, 0, 0}
if !reflect.DeepEqual(exp, rcv) {
t.Errorf("expected %v, received %v", exp, rcv)
}
}
func TestStorageInterfaceUnmarshal(t *testing.T) {
type Test struct {
Field string
}
arg := Test{
Field: "test",
}
jm := BSONMarshaler{}
rcv, err := jm.Marshal(&arg)
if err != nil {
t.Error(err)
}
var um Test
err = jm.Unmarshal(rcv, &um)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(um, arg) {
t.Errorf("expected %v, received %v", arg, um)
}
}
func TestStorageInterfaceMarshalBufMarshaler(t *testing.T) {
type Test struct {
Field string
}
arg := Test{
Field: "test",
}
jbm := JSONBufMarshaler{}
rcv, err := jbm.Marshal(arg)
if err != nil {
t.Error(err)
}
exp := []byte{123, 34, 70, 105, 101, 108, 100, 34, 58, 34, 116, 101, 115, 116, 34, 125, 10}
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("expeted %v, received %v", exp, rcv)
}
}
func TestStorageInterfaceUnmarshalBufMarshaler(t *testing.T) {
type Test struct {
Field string
}
arg := Test{
Field: "test",
}
jbm := JSONBufMarshaler{}
rcv, err := jbm.Marshal(arg)
if err != nil {
t.Error(err)
}
var um Test
err = jbm.Unmarshal(rcv, &um)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(arg, um) {
t.Errorf("expeted %v, received %v", arg, um)
}
}
func TestStorageInterfaceNewBincMarshaler(t *testing.T) {
rcv := NewBincMarshaler()
exp := &BincMarshaler{new(codec.BincHandle)}
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("expeted %v, received %v", exp, rcv)
}
}
func TestStorageInterfaceMarshalBinc(t *testing.T) {
type Test struct {
Field string
}
arg := Test{
Field: "test",
}
bm := NewBincMarshaler()
rcv, err := bm.Marshal(arg)
if err != nil {
t.Error(err)
}
exp := []byte{117, 73, 70, 105, 101, 108, 100, 72, 116, 101, 115, 116}
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("expeted %v, received %v", exp, rcv)
}
}
func TestStorageInterfaceUnmarshalBinc(t *testing.T) {
type Test struct {
Field string
}
arg := Test{
Field: "test",
}
bm := NewBincMarshaler()
rcv, err := bm.Marshal(arg)
if err != nil {
t.Error(err)
}
var um Test
err = bm.Unmarshal(rcv, &um)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(arg, um) {
t.Errorf("expeted %v, received %v", arg, um)
}
}
func TestStorageInterfaceMarshalGOB(t *testing.T) {
type Test struct {
Field string
}
arg := Test{
Field: "test",
}
bm := GOBMarshaler{}
rcv, err := bm.Marshal(arg)
if err != nil {
t.Error(err)
}
exp := []byte{28, 255, 185, 3, 1, 1, 4, 84, 101, 115, 116, 1, 255, 186, 0, 1, 1, 1, 5, 70, 105, 101, 108, 100, 1, 12, 0, 0, 0, 9, 255, 186, 1, 4, 116, 101, 115, 116, 0}
if !reflect.DeepEqual(rcv, exp) {
t.Errorf("expeted %v, received %v", exp, rcv)
}
}
func TestStorageInterfaceUnmarshalGOB(t *testing.T) {
type Test struct {
Field string
}
arg := Test{
Field: "test",
}
bm := GOBMarshaler{}
rcv, err := bm.Marshal(arg)
if err != nil {
t.Error(err)
}
var um Test
err = bm.Unmarshal(rcv, &um)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(arg, um) {
t.Errorf("expeted %v, received %v", arg, um)
}
}

View File

@@ -84,3 +84,18 @@ func TestNewSureTaxRequest(t *testing.T) {
t.Errorf("Expecting:\n%s\nReceived:\n%s", string(eSureTaxRequest.Request), string(stReq.Request))
}
}
func TestSureTaxNewSureTaxRequest(t *testing.T) {
cdr := &CDR{}
rcv, err := NewSureTaxRequest(cdr, nil)
if err != nil {
if err.Error() != "invalid SureTax config" {
t.Fatal(err)
}
}
if rcv != nil {
t.Error(rcv)
}
}

View File

@@ -1993,3 +1993,13 @@ func TestIncrementClone(t *testing.T) {
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(eOut), utils.ToJSON(clone))
}
}
func TestTimeSpansClone(t *testing.T) {
var incs Increments
rcv := incs.Clone()
if rcv != nil {
t.Error(rcv)
}
}