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
189e6d5f6c
commit
9bef7cdd1f
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/ltcache"
|
||||
)
|
||||
|
||||
func TestV1LoadCache(t *testing.T) {
|
||||
@@ -320,3 +321,133 @@ func TestCacheV1GetItemExpiryTime(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestCachesV1GetItemIDs(t *testing.T) {
|
||||
c := CacheS{}
|
||||
|
||||
err := c.V1GetItemIDs(&utils.ArgsGetCacheItemIDsWithArgDispatcher{}, &[]string{})
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "NOT_FOUND" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCachesV1GetItemExpiryTime(t *testing.T) {
|
||||
c := CacheS{}
|
||||
tm := time.Now()
|
||||
|
||||
err := c.V1GetItemExpiryTime(&utils.ArgsGetCacheItemWithArgDispatcher{}, &tm)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "NOT_FOUND" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1RemoveItem(t *testing.T) {
|
||||
ch := CacheS{}
|
||||
str := "test"
|
||||
|
||||
err := ch.V1RemoveItem(&utils.ArgsGetCacheItemWithArgDispatcher{}, &str)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if str != "OK" {
|
||||
t.Error(str)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1Clear(t *testing.T) {
|
||||
ch := CacheS{}
|
||||
str := "test"
|
||||
|
||||
err := ch.V1Clear(&utils.AttrCacheIDsWithArgDispatcher{}, &str)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if str != "OK" {
|
||||
t.Error(str)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1GetCacheStats(t *testing.T) {
|
||||
ch := CacheS{}
|
||||
cs := map[string]*ltcache.CacheStats{}
|
||||
|
||||
err := ch.V1GetCacheStats(&utils.AttrCacheIDsWithArgDispatcher{}, &cs)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if cs == nil {
|
||||
t.Error("didnt get cache stats")
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1PrecacheStatus(t *testing.T) {
|
||||
c := CacheS{}
|
||||
|
||||
err := c.V1PrecacheStatus(&utils.AttrCacheIDsWithArgDispatcher{}, &map[string]string{})
|
||||
|
||||
if err == nil {
|
||||
t.Error("didn't receive an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheV1HasGroup(t *testing.T) {
|
||||
c := CacheS{}
|
||||
bl := true
|
||||
err := c.V1HasGroup(&utils.ArgsGetGroupWithArgDispatcher{}, &bl)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "unknown cacheID: *resources" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1GetGroupItemIDs(t *testing.T) {
|
||||
c := CacheS{}
|
||||
slc := []string{"test"}
|
||||
|
||||
err := c.V1GetGroupItemIDs(&utils.ArgsGetGroupWithArgDispatcher{}, &slc)
|
||||
|
||||
if err.Error() != "NOT_FOUND" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestV1RemoveGroup(t *testing.T) {
|
||||
c := CacheS{}
|
||||
str := ""
|
||||
|
||||
err := c.V1RemoveGroup(&utils.ArgsGetGroupWithArgDispatcher{}, &str)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCachetoStringSlice(t *testing.T) {
|
||||
s := []string{}
|
||||
|
||||
slc := toStringSlice(&s)
|
||||
|
||||
if !reflect.DeepEqual(s, slc) {
|
||||
t.Errorf("received %v, expected %v", slc, s)
|
||||
}
|
||||
|
||||
slc = toStringSlice(nil)
|
||||
|
||||
if slc != nil {
|
||||
t.Error(slc)
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package engine
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -123,6 +124,30 @@ func TestDestinationNonCachedDestWrongPrefix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDestinationsString(t *testing.T) {
|
||||
d := Destination{
|
||||
Prefixes: []string{"val1"},
|
||||
}
|
||||
|
||||
rcv := d.String()
|
||||
|
||||
if rcv != ": val1" {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDestinationsAddPrefix(t *testing.T) {
|
||||
d := Destination{
|
||||
Prefixes: []string{"val1"},
|
||||
}
|
||||
|
||||
d.AddPrefix("val2")
|
||||
|
||||
if !reflect.DeepEqual(d.Prefixes, []string{"val1", "val2"}) {
|
||||
t.Error(d.Prefixes)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestCleanStalePrefixes(t *testing.T) {
|
||||
x := struct{}{}
|
||||
|
||||
@@ -253,3 +253,17 @@ func TestDispatcherHostCall(t *testing.T) {
|
||||
t.Errorf("Expected: %s , received: %s", utils.ToJSON(etRPC), utils.ToJSON(tRPC))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherprflClone(t *testing.T) {
|
||||
dC := DispatcherHostProfile{
|
||||
Params: map[string]any{
|
||||
"test": 1,
|
||||
},
|
||||
}
|
||||
|
||||
rcv := dC.Clone()
|
||||
|
||||
if !reflect.DeepEqual(dC, *rcv) {
|
||||
t.Errorf("expected %v, received %v", dC, rcv)
|
||||
}
|
||||
}
|
||||
@@ -140,3 +140,65 @@ func TestNewAttributeFromInline(t *testing.T) {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(expAttrPrf1), utils.ToJSON(attr))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibattributescompileSubstitutes(t *testing.T) {
|
||||
ap := AttributeProfile{
|
||||
Attributes: []*Attribute{
|
||||
{
|
||||
Value: config.RSRParsers{{Rules: "test)"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := ap.compileSubstitutes()
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "invalid RSRFilter start rule in string: <test)>" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibattributesSort(t *testing.T) {
|
||||
aps := AttributeProfiles{{Weight: 1.2}, {Weight: 1.5}}
|
||||
|
||||
aps.Sort()
|
||||
|
||||
if aps[0].Weight != 1.5 {
|
||||
t.Error("didn't sort")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibattributesNewAttributeFromInline(t *testing.T) {
|
||||
tests := []struct{
|
||||
name string
|
||||
t string
|
||||
in string
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "split error check",
|
||||
t: "",
|
||||
in: "",
|
||||
err: "inline parse error for string: <>",
|
||||
},
|
||||
{
|
||||
name: "NewRSRParsers error check",
|
||||
t: "",
|
||||
in: "test):test):test)",
|
||||
err: "invalid RSRFilter start rule in string: <test)>",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := NewAttributeFromInline(tt.t, tt.in)
|
||||
|
||||
if err != nil {
|
||||
if tt.err != err.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1016,3 +1016,151 @@ func TestAccountingClone(t *testing.T) {
|
||||
t.Errorf("Expecting 1001 , received: %+v", a2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibeventcostChargingIncrementFieldAsInterface(t *testing.T) {
|
||||
cIt := ChargingIncrement{
|
||||
Usage: 1 * time.Millisecond,
|
||||
Cost: 1.2,
|
||||
AccountingID: "test",
|
||||
CompressFactor: 1,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg []string
|
||||
val any
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "empty file path",
|
||||
arg: []string{},
|
||||
val: nil,
|
||||
err: "NOT_FOUND",
|
||||
},
|
||||
{
|
||||
name: "default case",
|
||||
arg: []string{"test"},
|
||||
val: nil,
|
||||
err: "unsupported field prefix: <test>",
|
||||
},
|
||||
{
|
||||
name: "Usage case",
|
||||
arg: []string{"Usage"},
|
||||
val: 1 * time.Millisecond,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "Cost case",
|
||||
arg: []string{"Cost"},
|
||||
val: 1.2,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "AccountingID case",
|
||||
arg: []string{"AccountingID"},
|
||||
val: "test",
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "Compress factor case",
|
||||
arg: []string{"CompressFactor"},
|
||||
val: 1,
|
||||
err: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
rcv, err := cIt.FieldAsInterface(tt.arg)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != tt.err {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if rcv != tt.val {
|
||||
t.Error(rcv)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibeventcostBalanceChargeFieldAsInterface(t *testing.T) {
|
||||
str := "test"
|
||||
fl := 1.2
|
||||
|
||||
cIt := BalanceCharge{
|
||||
AccountID: str,
|
||||
BalanceUUID: str,
|
||||
RatingID: str,
|
||||
Units: fl,
|
||||
ExtraChargeID: str,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg []string
|
||||
val any
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "empty file path",
|
||||
arg: []string{},
|
||||
val: nil,
|
||||
err: "NOT_FOUND",
|
||||
},
|
||||
{
|
||||
name: "default case",
|
||||
arg: []string{"test"},
|
||||
val: nil,
|
||||
err: "unsupported field prefix: <test>",
|
||||
},
|
||||
{
|
||||
name: "AccountID case",
|
||||
arg: []string{"AccountID"},
|
||||
val: str,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "BalanceUUID case",
|
||||
arg: []string{"BalanceUUID"},
|
||||
val: str,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "RatingID case",
|
||||
arg: []string{"RatingID"},
|
||||
val: str,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "Units factor case",
|
||||
arg: []string{"Units"},
|
||||
val: fl,
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "ExtraChargeID factor case",
|
||||
arg: []string{"ExtraChargeID"},
|
||||
val: str,
|
||||
err: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
rcv, err := cIt.FieldAsInterface(tt.arg)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != tt.err {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if rcv != tt.val {
|
||||
t.Error(rcv)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1003,3 +1003,53 @@ func TestArgsSuppAsOptsGetSupplier(t *testing.T) {
|
||||
}
|
||||
//unifinished
|
||||
}
|
||||
|
||||
func TestSupplierscompileCacheParamaters(t *testing.T) {
|
||||
sp := SupplierProfile{
|
||||
Sorting: "*load",
|
||||
SortingParameters: []string{"1:2", "2:1"},
|
||||
Suppliers: []*Supplier{{}},
|
||||
}
|
||||
|
||||
err := sp.compileCacheParameters()
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
sp2 := SupplierProfile{
|
||||
Sorting: "*load",
|
||||
SortingParameters: []string{"test:test"},
|
||||
Suppliers: []*Supplier{{}},
|
||||
}
|
||||
|
||||
err = sp2.compileCacheParameters()
|
||||
|
||||
if err.Error() != `strconv.Atoi: parsing "test": invalid syntax` {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
sp3 := SupplierProfile{
|
||||
Sorting: "*load",
|
||||
SortingParameters: []string{"*default:1",},
|
||||
Suppliers: []*Supplier{{}},
|
||||
}
|
||||
|
||||
err = sp3.compileCacheParameters()
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
sp4 := SupplierProfile{
|
||||
Sorting: "*load",
|
||||
SortingParameters: []string{"test:1",},
|
||||
Suppliers: []*Supplier{{ID: "test"}},
|
||||
}
|
||||
|
||||
err = sp4.compileCacheParameters()
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user