mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
Add coverage tests for engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
302cb2aec8
commit
94afae087f
@@ -451,3 +451,59 @@ func TestCachetoStringSlice(t *testing.T) {
|
||||
t.Error(slc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCacheSV1ReloadCacheErrors(t *testing.T) {
|
||||
str := "test"
|
||||
type args struct {
|
||||
attrs utils.AttrReloadCacheWithArgDispatcher
|
||||
reply *string
|
||||
}
|
||||
|
||||
chS := CacheS{
|
||||
cfg: &config.CGRConfig{},
|
||||
dm: &DataManager{
|
||||
cacheCfg: config.CacheCfg{},
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "FlushAll",
|
||||
args: args{attrs: utils.AttrReloadCacheWithArgDispatcher{
|
||||
&utils.ArgDispatcher{},
|
||||
utils.TenantArg{},
|
||||
utils.AttrReloadCache{
|
||||
FlushAll: true,
|
||||
},
|
||||
}, reply: &str},
|
||||
err: "",
|
||||
},
|
||||
{
|
||||
name: "REload destination error",
|
||||
args: args{attrs: utils.AttrReloadCacheWithArgDispatcher{
|
||||
&utils.ArgDispatcher{},
|
||||
utils.TenantArg{},
|
||||
utils.AttrReloadCache{
|
||||
FlushAll: true,
|
||||
},
|
||||
}, reply: &str},
|
||||
err: "err",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := chS.V1ReloadCache(tt.args.attrs, tt.args.reply)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != tt.err {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,3 +267,16 @@ func TestDispatcherprflClone(t *testing.T) {
|
||||
t.Errorf("expected %v, received %v", dC, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcherprflCall(t *testing.T) {
|
||||
dH := DispatcherHost{}
|
||||
|
||||
err := dH.Call("test", 1, 1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if dH.rpcConn == nil {
|
||||
t.Error(dH.Tenant)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3664,17 +3664,17 @@ func TestEventCostnewChargingIncrement(t *testing.T) {
|
||||
e := EventCost{}
|
||||
|
||||
rcv := e.newChargingIncrement(&Increment{
|
||||
Duration: 1 * time.Second,
|
||||
Cost: 1,
|
||||
Duration: 1 * time.Second,
|
||||
Cost: 1,
|
||||
CompressFactor: 1,
|
||||
}, RatingMatchedFilters{}, false)
|
||||
exp := &ChargingIncrement{
|
||||
Usage: 1 * time.Second,
|
||||
Cost: 1,
|
||||
Usage: 1 * time.Second,
|
||||
Cost: 1,
|
||||
CompressFactor: 1,
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("expected %v, received %v", exp, rcv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2992,3 +2992,151 @@ func TestFilterspassEqualTo(t *testing.T) {
|
||||
t.Error("Recived:", rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFiltersNewFilterRule(t *testing.T) {
|
||||
_, err := NewFilterRule("*rsr", "test", []string{"test)"})
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "invalid RSRFilter start rule in string: <test)>" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFiltersgetFieldNameDataProvider(t *testing.T) {
|
||||
fS := FilterS{}
|
||||
|
||||
type args struct {
|
||||
initialDP utils.DataProvider
|
||||
fieldName string
|
||||
tenant string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
exp utils.DataProvider
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "",
|
||||
args: args{
|
||||
initialDP: utils.MapStorage{},
|
||||
fieldName: "~*accounts",
|
||||
tenant: "test",
|
||||
},
|
||||
exp: nil,
|
||||
err: "invalid fieldname <~*accounts>",
|
||||
},
|
||||
{
|
||||
name: "",
|
||||
args: args{
|
||||
initialDP: utils.MapStorage{},
|
||||
fieldName: "~*resources",
|
||||
tenant: "test",
|
||||
},
|
||||
exp: nil,
|
||||
err: "invalid fieldname <~*resources>",
|
||||
},
|
||||
{
|
||||
name: "",
|
||||
args: args{
|
||||
initialDP: utils.MapStorage{},
|
||||
fieldName: "~*stats",
|
||||
tenant: "test",
|
||||
},
|
||||
exp: nil,
|
||||
err: "invalid fieldname <~*stats>",
|
||||
},
|
||||
{
|
||||
name: "",
|
||||
args: args{
|
||||
initialDP: utils.MapStorage{},
|
||||
fieldName: "test",
|
||||
tenant: "test",
|
||||
},
|
||||
exp: nil,
|
||||
err: "filter path: <test> doesn't have a valid prefix",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
rcv, err := fS.getFieldNameDataProvider(tt.args.initialDP, tt.args.fieldName, tt.args.tenant)
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFiltersgetFieldValueDataProvider(t *testing.T) {
|
||||
fS := FilterS{}
|
||||
|
||||
type args struct {
|
||||
initialDP utils.DataProvider
|
||||
fieldName string
|
||||
tenant string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
exp utils.DataProvider
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "",
|
||||
args: args{
|
||||
initialDP: utils.MapStorage{},
|
||||
fieldName: "~*accounts",
|
||||
tenant: "test",
|
||||
},
|
||||
exp: nil,
|
||||
err: "invalid fieldname <~*accounts>",
|
||||
},
|
||||
{
|
||||
name: "",
|
||||
args: args{
|
||||
initialDP: utils.MapStorage{},
|
||||
fieldName: "~*resources",
|
||||
tenant: "test",
|
||||
},
|
||||
exp: nil,
|
||||
err: "invalid fieldname <~*resources>",
|
||||
},
|
||||
{
|
||||
name: "",
|
||||
args: args{
|
||||
initialDP: utils.MapStorage{},
|
||||
fieldName: "~*stats",
|
||||
tenant: "test",
|
||||
},
|
||||
exp: nil,
|
||||
err: "invalid fieldname <~*stats>",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
rcv, err := fS.getFieldValueDataProvider(tt.args.initialDP, tt.args.fieldName, tt.args.tenant)
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,3 +534,17 @@ func TestFsCdrFirstDefined(t *testing.T) {
|
||||
t.Errorf("Expecting: 1001, received: %s", value)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFSCdrNewFSCdr(t *testing.T) {
|
||||
rcv, err := NewFSCdr([]byte{}, nil)
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "unexpected end of JSON input" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if rcv != nil {
|
||||
t.Error(rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -867,3 +867,88 @@ func TestThSProcessEventMaxHits(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestThresholdsProcessEvent3(t *testing.T) {
|
||||
to := Threshold{
|
||||
Snooze: time.Date(
|
||||
2024, 11, 17, 20, 34, 58, 651387237, time.UTC),
|
||||
}
|
||||
|
||||
err := to.ProcessEvent(nil, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
to2 := Threshold{
|
||||
Hits: 1,
|
||||
tPrfl: &ThresholdProfile{
|
||||
MinHits: 2,
|
||||
},
|
||||
}
|
||||
|
||||
err = to2.ProcessEvent(nil, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
to3 := Threshold{
|
||||
Hits: 2,
|
||||
tPrfl: &ThresholdProfile{
|
||||
MinHits: 2,
|
||||
MaxHits: 1,
|
||||
},
|
||||
}
|
||||
|
||||
err = to3.ProcessEvent(nil, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestThresholdsStoreThreshold(t *testing.T) {
|
||||
ts := ThresholdService{}
|
||||
|
||||
err := ts.StoreThreshold(&Threshold{})
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestThresholdsV1GetThresholdsForEvent(t *testing.T) {
|
||||
tS := ThresholdService{}
|
||||
|
||||
err := tS.V1GetThresholdsForEvent(&ArgsProcessEvent{}, &Thresholds{})
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "MANDATORY_IE_MISSING: [CGREvent]" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
err = tS.V1GetThresholdsForEvent(&ArgsProcessEvent{
|
||||
CGREvent: &utils.CGREvent{},
|
||||
}, &Thresholds{})
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "MANDATORY_IE_MISSING: [Tenant ID]" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
err = tS.V1GetThresholdsForEvent(&ArgsProcessEvent{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "test",
|
||||
ID: "test",
|
||||
},
|
||||
}, &Thresholds{})
|
||||
|
||||
if err != nil {
|
||||
if err.Error() != "MANDATORY_IE_MISSING: [Event]" {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user