mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
Improving coverage at utils
This commit is contained in:
committed by
Dan Christian Bogos
parent
8abd4d93c4
commit
f579e05221
@@ -809,6 +809,18 @@ func TestEventChargerMerge(t *testing.T) {
|
||||
CompressFactor: 2,
|
||||
},
|
||||
},
|
||||
Rates: map[string]*IntervalRate{
|
||||
"RATE_3": {
|
||||
IntervalStart: NewDecimal(0, 0),
|
||||
FixedFee: NewDecimal(4, 1),
|
||||
RecurrentFee: NewDecimal(24, 1),
|
||||
},
|
||||
"RATE_4": {
|
||||
IntervalStart: NewDecimal(12, 1),
|
||||
FixedFee: NewDecimal(1, 0),
|
||||
RecurrentFee: NewDecimal(5, 2),
|
||||
},
|
||||
},
|
||||
Accounts: map[string]*Account{
|
||||
"ACC3": {
|
||||
Tenant: CGRateSorg,
|
||||
@@ -937,6 +949,17 @@ func TestEventChargerMerge(t *testing.T) {
|
||||
FixedFee: NewDecimal(1, 0),
|
||||
RecurrentFee: NewDecimal(5, 2),
|
||||
},
|
||||
|
||||
"RATE_3": {
|
||||
IntervalStart: NewDecimal(0, 0),
|
||||
FixedFee: NewDecimal(4, 1),
|
||||
RecurrentFee: NewDecimal(24, 1),
|
||||
},
|
||||
"RATE_4": {
|
||||
IntervalStart: NewDecimal(12, 1),
|
||||
FixedFee: NewDecimal(1, 0),
|
||||
RecurrentFee: NewDecimal(5, 2),
|
||||
},
|
||||
},
|
||||
Accounts: map[string]*Account{
|
||||
"ACC1": {
|
||||
@@ -1666,4 +1689,148 @@ func TestEqualsAccountCharges(t *testing.T) {
|
||||
if rcv := ac.equals(nAc); rcv != true {
|
||||
t.Errorf("Expected <true>, Recevied <%v>", rcv)
|
||||
}
|
||||
|
||||
ac = &AccountCharge{
|
||||
AttributeIDs: []string{"test", "range"},
|
||||
}
|
||||
nAc = &AccountCharge{
|
||||
AttributeIDs: []string{"test2", "range"},
|
||||
}
|
||||
|
||||
if rcv := ac.equals(nAc); rcv != false {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSyncIDsEventCharges(t *testing.T) {
|
||||
eEvChgs := &EventCharges{
|
||||
Charges: []*ChargeEntry{
|
||||
{
|
||||
ChargingID: "GENUUID3",
|
||||
},
|
||||
},
|
||||
Accounting: map[string]*AccountCharge{
|
||||
"THIS_GENUUID1": {
|
||||
AccountID: "TestEventChargesEquals",
|
||||
},
|
||||
"GENUUID3": {
|
||||
AccountID: "TestEventChargesMerge",
|
||||
BalanceID: "CONCRETE1",
|
||||
Units: NewDecimal(8, 1),
|
||||
BalanceLimit: NewDecimal(200, 0),
|
||||
UnitFactorID: "GENUUID_FACTOR3",
|
||||
RatingID: "GENUUID_RATING1",
|
||||
JoinedChargeIDs: []string{"THIS_GENUUID1"},
|
||||
},
|
||||
},
|
||||
UnitFactors: map[string]*UnitFactor{
|
||||
"GENUUID_FACTOR3": {
|
||||
Factor: NewDecimal(100, 0),
|
||||
FilterIDs: []string{"*string:~*req.Account:1003"},
|
||||
},
|
||||
},
|
||||
Rating: map[string]*RateSInterval{
|
||||
"GENUUID_RATING1": {
|
||||
Increments: []*RateSIncrement{
|
||||
{
|
||||
Usage: NewDecimal(int64(time.Minute), 0),
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
IntervalStart: NewDecimal(int64(time.Second), 0),
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
newEc := &EventCharges{
|
||||
Charges: []*ChargeEntry{
|
||||
{
|
||||
ChargingID: "GENUUID2",
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
Accounting: map[string]*AccountCharge{
|
||||
"THIS_GENUUID2": {
|
||||
AccountID: "TestEventChargesEquals",
|
||||
BalanceID: "CONCRETE1",
|
||||
Units: NewDecimal(8, 1),
|
||||
BalanceLimit: NewDecimal(200, 0),
|
||||
UnitFactorID: "GENUUID_FACTOR1",
|
||||
},
|
||||
"GENUUID2": {
|
||||
AccountID: "TestEventChargesMerge",
|
||||
BalanceID: "CONCRETE1",
|
||||
Units: NewDecimal(8, 1),
|
||||
BalanceLimit: NewDecimal(200, 0),
|
||||
UnitFactorID: "GENUUID_FACTOR2",
|
||||
RatingID: "GENUUID_RATING2",
|
||||
JoinedChargeIDs: []string{"THIS_GENUUID2"},
|
||||
},
|
||||
},
|
||||
UnitFactors: map[string]*UnitFactor{
|
||||
"GENUUID_FACTOR2": {
|
||||
Factor: NewDecimal(100, 0),
|
||||
FilterIDs: []string{"*string:~*req.Account:1003"},
|
||||
},
|
||||
},
|
||||
Rating: map[string]*RateSInterval{
|
||||
"GENUUID_RATING2": {
|
||||
Increments: []*RateSIncrement{
|
||||
{
|
||||
Usage: NewDecimal(int64(time.Minute), 0),
|
||||
RateIntervalIndex: 0,
|
||||
RateID: "RATE_2",
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
IntervalStart: NewDecimal(int64(time.Second), 0),
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expEc := &EventCharges{
|
||||
Charges: []*ChargeEntry{
|
||||
{
|
||||
ChargingID: "GENUUID3",
|
||||
},
|
||||
},
|
||||
Accounting: map[string]*AccountCharge{
|
||||
"THIS_GENUUID1": {
|
||||
AccountID: "TestEventChargesEquals",
|
||||
},
|
||||
"GENUUID3": {
|
||||
AccountID: "TestEventChargesMerge",
|
||||
BalanceID: "CONCRETE1",
|
||||
Units: NewDecimal(8, 1),
|
||||
BalanceLimit: NewDecimal(200, 0),
|
||||
UnitFactorID: "GENUUID_FACTOR3",
|
||||
RatingID: "GENUUID_RATING1",
|
||||
JoinedChargeIDs: []string{"THIS_GENUUID1"},
|
||||
},
|
||||
},
|
||||
UnitFactors: map[string]*UnitFactor{
|
||||
"GENUUID_FACTOR3": {
|
||||
Factor: NewDecimal(100, 0),
|
||||
FilterIDs: []string{"*string:~*req.Account:1003"},
|
||||
},
|
||||
},
|
||||
Rating: map[string]*RateSInterval{
|
||||
"GENUUID_RATING1": {
|
||||
Increments: []*RateSIncrement{
|
||||
{
|
||||
Usage: NewDecimal(int64(time.Minute), 0),
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
IntervalStart: NewDecimal(int64(time.Second), 0),
|
||||
CompressFactor: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
eEvChgs.SyncIDs(newEc)
|
||||
if !reflect.DeepEqual(expEc, eEvChgs) {
|
||||
t.Errorf("Expected %v \n but received \n %v", ToJSON(expEc), ToJSON(eEvChgs))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2255,11 +2255,8 @@ func TestAsRateAPIConvert(t *testing.T) {
|
||||
Weights: "notEmpty",
|
||||
}
|
||||
expErr := "invalid DynamicWeight format for string <notEmpty>"
|
||||
var exp *Rate
|
||||
|
||||
if rcv, err := ext.AsRate(); err == nil || err.Error() != expErr {
|
||||
if _, err := ext.AsRate(); err == nil || err.Error() != expErr {
|
||||
t.Errorf("%+v", err)
|
||||
} else if !reflect.DeepEqual(exp, rcv) {
|
||||
t.Errorf("Expected <%+v %T>, Recevied <%+v %T>", ToJSON(exp), exp, ToJSON(rcv), rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,10 +385,25 @@ func TestCloseStdLogger(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// unfinished
|
||||
// func TestWriteStdLogger(t *testing.T) {
|
||||
// sl := &StdLogger{w: Logger}
|
||||
// if rcv, err := sl.Write([]byte{}); err != nil {
|
||||
// t.Errorf("Expected <nil>, received %v %v", err, rcv)
|
||||
// }
|
||||
// }
|
||||
func TestWriteStdLogger(t *testing.T) {
|
||||
sl := &StdLogger{
|
||||
w: &logWriter{
|
||||
log.New(io.Discard, EmptyString, log.LstdFlags),
|
||||
},
|
||||
}
|
||||
exp := 1
|
||||
if rcv, err := sl.Write([]byte{222}); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv != exp {
|
||||
t.Errorf("Expected <%v>, received <%v>", exp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetLogLevelStdLogger(t *testing.T) {
|
||||
sl := &StdLogger{}
|
||||
exp := 0
|
||||
if rcv := sl.GetLogLevel(); rcv != exp {
|
||||
t.Errorf("Expected <%v>, received %v %T", exp, rcv, rcv)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/ugocodec/codec"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
@@ -72,22 +73,22 @@ type dummyStruct struct {
|
||||
Field string
|
||||
}
|
||||
|
||||
// func TestJSONUnmarshaler(t *testing.T) {
|
||||
// data := []byte(`{"Field": "some_string"}`)
|
||||
// jsnM := &JSONMarshaler{}
|
||||
// dS := dummyStruct{
|
||||
// Field: "some_string",
|
||||
// }
|
||||
func TestJSONUnmarshaler(t *testing.T) {
|
||||
data := []byte(`{"Field": "some_string"}`)
|
||||
jsnM := &JSONMarshaler{}
|
||||
dS := dummyStruct{
|
||||
Field: "some_string",
|
||||
}
|
||||
|
||||
// var ndS dummyStruct
|
||||
// err := jsnM.Unmarshal(data, &ndS)
|
||||
// if err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// if reflect.DeepEqual(dS, ndS) {
|
||||
// t.Errorf("Expected: %s , received: %s", ToJSON(dS), ToJSON(ndS))
|
||||
// }
|
||||
// }
|
||||
var ndS dummyStruct
|
||||
err := jsnM.Unmarshal(data, &ndS)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !reflect.DeepEqual(dS, ndS) {
|
||||
t.Errorf("Expected: %s , received: %s", ToJSON(dS), ToJSON(ndS))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBSONMarshaler(t *testing.T) {
|
||||
v := bson.M{"ts": "test"}
|
||||
@@ -143,3 +144,25 @@ func TestJSONBufUnmarshaler(t *testing.T) {
|
||||
t.Errorf("Expected %v\n but received %v", s, rcv)
|
||||
}
|
||||
}
|
||||
func TestBsonUnmarshal(t *testing.T) {
|
||||
v := bson.M{"ts": "test"}
|
||||
bsnM := &BSONMarshaler{}
|
||||
rcvM, _ := bsnM.Marshal(v)
|
||||
dS := dummyStruct{}
|
||||
|
||||
var ndS dummyStruct
|
||||
err := bsnM.Unmarshal(rcvM, &ndS)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if !reflect.DeepEqual(dS, ndS) {
|
||||
t.Errorf("Expected: %s , received: %s", ToJSON(dS), ToJSON(ndS))
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewBincMarshler(t *testing.T) {
|
||||
exp := &BincMarshaler{new(codec.BincHandle)}
|
||||
if rcv := NewBincMarshaler(); !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected <%+v>, Received <%+v>", ToJSON(exp), ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1755,3 +1755,28 @@ func TestStringAsBig(t *testing.T) {
|
||||
t.Errorf("Expected %v \n but received \n %v", exp, v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIfaceAsTInt(t *testing.T) {
|
||||
|
||||
var testInt32 int32 = 132
|
||||
var testInt64 int64 = 164
|
||||
var testFloat32 float32 = 15.32
|
||||
var expInt32 int32 = 132
|
||||
var expInt64 int64 = 164
|
||||
var expFloat32 float32 = 15.32
|
||||
if rcv, err := IfaceAsInt(testInt32); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv != int(expInt32) {
|
||||
t.Errorf("Expected <%+v>, received <%+v>", expInt32, rcv)
|
||||
}
|
||||
if rcv, err := IfaceAsInt(testInt64); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv != int(expInt64) {
|
||||
t.Errorf("Expected <%+v>, received <%+v>", expInt32, rcv)
|
||||
}
|
||||
if rcv, err := IfaceAsInt(testFloat32); err != nil {
|
||||
t.Error(err)
|
||||
} else if rcv != int(expFloat32) {
|
||||
t.Errorf("Expected <%+v>, received <%+v>", expInt32, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user