mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Improving coverage at engine
This commit is contained in:
committed by
Dan Christian Bogos
parent
c216fad65c
commit
affaf7a5f7
@@ -2119,6 +2119,26 @@ func TestPassNever(t *testing.T) {
|
||||
fltr := &FilterRule{}
|
||||
dDP := utils.MapStorage{}
|
||||
if ok, err := fltr.passNever(dDP); ok != false && err != nil {
|
||||
t.Errorf("Expected filter to never pass, unexpected error <%v>", err)
|
||||
t.Errorf("Expected filter to pass never, unexpected error <%v>", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterRulePassRegexParseErrNotFound(t *testing.T) {
|
||||
|
||||
rsrBadParse := config.NewRSRParserMustCompile("~*opts.<~*opts.*originID;~*req.RunID;-Cost>")
|
||||
|
||||
fltr := &FilterRule{
|
||||
|
||||
rsrElement: rsrBadParse,
|
||||
}
|
||||
|
||||
dDP := utils.MapStorage{
|
||||
utils.MetaReq: utils.MapStorage{},
|
||||
utils.MetaOpts: utils.MapStorage{
|
||||
utils.MetaOriginID: "originIDUniq",
|
||||
},
|
||||
}
|
||||
if ok, err := fltr.passRegex(dDP); ok != false && err != utils.ErrNotFound {
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", utils.ErrNotFound, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,6 +208,12 @@ func (TestRPCDspMock) SessionSv1Do(*context.Context, interface{}, *string) error
|
||||
func (TestRPCDspMock) StatSv1Do(*context.Context, interface{}, *string) error { return nil }
|
||||
func (TestRPCDspMock) ThresholdSv1Do(*context.Context, interface{}, *string) error { return nil }
|
||||
func (TestRPCDspMock) CDRsv1Do(*context.Context, interface{}, *string) error { return nil }
|
||||
func (TestRPCDspMock) EeSv1Do(*context.Context, interface{}, *string) error { return nil }
|
||||
func (TestRPCDspMock) CoreSv1Do(*context.Context, interface{}, *string) error { return nil }
|
||||
func (TestRPCDspMock) AnalyzerSv1Do(*context.Context, interface{}, *string) error { return nil }
|
||||
func (TestRPCDspMock) AdminSv1Do(*context.Context, interface{}, *string) error { return nil }
|
||||
func (TestRPCDspMock) LoaderSv1Do(*context.Context, interface{}, *string) error { return nil }
|
||||
|
||||
func TestIntServiceNewDispatcherService(t *testing.T) {
|
||||
expErrMsg := `rpc.Register: no service name for type struct {}`
|
||||
if _, err := NewDispatcherService(struct{}{}); err == nil || err.Error() != expErrMsg {
|
||||
@@ -234,11 +240,17 @@ func TestIntServiceNewDispatcherService(t *testing.T) {
|
||||
"RouteSv1": {"Do", "Ping"},
|
||||
"SessionSv1": {"Do", "Ping"},
|
||||
"StatSv1": {"Do", "Ping"},
|
||||
"TestRPCDspMock": {"AccountSv1Do", "ActionSv1Do", "AttributeSv1Do", "CDRsv1Do", "CacheSv1Do", "ChargerSv1Do", "ConfigSv1Do", "DispatcherSv1Do", "GuardianSv1Do", "Ping", "RateSv1Do", "ReplicatorSv1Do", "ResourceSv1Do", "RouteSv1Do", "SessionSv1Do", "StatSv1Do", "ThresholdSv1Do"},
|
||||
"TestRPCDspMock": {"AccountSv1Do", "ActionSv1Do", "AdminSv1Do", "AnalyzerSv1Do", "AttributeSv1Do", "CDRsv1Do", "CacheSv1Do", "ChargerSv1Do", "ConfigSv1Do", "CoreSv1Do", "DispatcherSv1Do", "EeSv1Do", "GuardianSv1Do", "LoaderSv1Do", "Ping", "RateSv1Do", "ReplicatorSv1Do", "ResourceSv1Do", "RouteSv1Do", "SessionSv1Do", "StatSv1Do", "ThresholdSv1Do"},
|
||||
"ThresholdSv1": {"Do", "Ping"},
|
||||
"ReplicatorSv1": {"Do", "Ping"},
|
||||
|
||||
"EeSv1": {"Do", "Ping"},
|
||||
"CoreSv1": {"Do", "Ping"},
|
||||
"AnalyzerSv1": {"Do", "Ping"},
|
||||
"AdminSv1": {"Do", "Ping"},
|
||||
"LoaderSv1": {"Do", "Ping"},
|
||||
}
|
||||
if !reflect.DeepEqual(exp, methods) {
|
||||
t.Errorf("Expeceted: %v, received: %v", utils.ToJSON(exp), utils.ToJSON(methods))
|
||||
t.Errorf("Expeceted: %v, \nreceived: \n%v", utils.ToJSON(exp), utils.ToJSON(methods))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
@@ -1435,3 +1436,156 @@ func TestSortedRoutesAsNavigableMap(t *testing.T) {
|
||||
t.Errorf("Expected %+v, received %+v", utils.ToJSON(expNavMap), utils.ToJSON(rcv))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortedRoutesListRouteIDs(t *testing.T) {
|
||||
sr := SortedRoutesList{
|
||||
{
|
||||
Routes: []*SortedRoute{
|
||||
{
|
||||
RouteID: "sr1id1",
|
||||
},
|
||||
{
|
||||
RouteID: "sr1id2",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Routes: []*SortedRoute{
|
||||
{
|
||||
RouteID: "sr2id1",
|
||||
},
|
||||
{
|
||||
RouteID: "sr2id2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
val := sr.RouteIDs()
|
||||
sort.Slice(val, func(i, j int) bool {
|
||||
return val[i] < val[j]
|
||||
})
|
||||
exp := []string{"sr1id1", "sr1id2", "sr2id1", "sr2id2"}
|
||||
if !reflect.DeepEqual(val, exp) {
|
||||
t.Errorf("expected %v ,received %v", exp, val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortedRoutesListRoutesWithParams(t *testing.T) {
|
||||
sRs := SortedRoutesList{
|
||||
{
|
||||
Routes: []*SortedRoute{
|
||||
{
|
||||
RouteID: "route1",
|
||||
RouteParameters: "params1",
|
||||
},
|
||||
{
|
||||
RouteID: "route2",
|
||||
RouteParameters: "params2",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Routes: []*SortedRoute{
|
||||
{
|
||||
RouteID: "route3",
|
||||
RouteParameters: "params3",
|
||||
},
|
||||
{
|
||||
RouteID: "route4",
|
||||
RouteParameters: "params4",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
val := sRs.RoutesWithParams()
|
||||
sort.Slice(val, func(i, j int) bool {
|
||||
return val[i] < val[j]
|
||||
})
|
||||
exp := []string{"route1:params1", "route2:params2", "route3:params3", "route4:params4"}
|
||||
|
||||
if !reflect.DeepEqual(val, exp) {
|
||||
t.Errorf("expected %v ,received %v", val, exp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRouteSortDispatcherSortRoutes(t *testing.T) {
|
||||
ssd := RouteSortDispatcher{}
|
||||
suppls := map[string]*RouteWithWeight{}
|
||||
suplEv := new(utils.CGREvent)
|
||||
extraOpts := new(optsGetRoutes)
|
||||
expErr := "unsupported sorting strategy: "
|
||||
if _, err := ssd.SortRoutes(context.Background(), "", "", suppls, suplEv, extraOpts); err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v>, Received <%v>", expErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortedRoutesListAsNavigableMap(t *testing.T) {
|
||||
|
||||
sRs := SortedRoutesList{
|
||||
|
||||
{
|
||||
Routes: []*SortedRoute{
|
||||
{
|
||||
RouteID: "route1",
|
||||
RouteParameters: "params1",
|
||||
},
|
||||
{
|
||||
RouteID: "route2",
|
||||
RouteParameters: "params2",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Routes: []*SortedRoute{
|
||||
{
|
||||
RouteID: "route3",
|
||||
RouteParameters: "params3",
|
||||
},
|
||||
{
|
||||
RouteID: "route4",
|
||||
RouteParameters: "params4",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
exp := &utils.DataNode{Type: utils.NMSliceType, Slice: make([]*utils.DataNode, len(sRs))}
|
||||
for i, ss := range sRs {
|
||||
exp.Slice[i] = ss.AsNavigableMap()
|
||||
}
|
||||
if rcv := sRs.AsNavigableMap(); !reflect.DeepEqual(rcv, exp) {
|
||||
t.Errorf("Expected <%v>, \n Received \n<%v>", utils.ToJSON(exp), utils.ToJSON(rcv))
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRouteLazyPass(t *testing.T) {
|
||||
|
||||
filters := []*FilterRule{
|
||||
{
|
||||
Type: "nr1",
|
||||
Element: "nr1",
|
||||
Values: []string{"nr1"},
|
||||
},
|
||||
{
|
||||
Type: "nr2",
|
||||
Element: "nr2",
|
||||
Values: []string{"nr2"},
|
||||
},
|
||||
}
|
||||
|
||||
ev := new(utils.CGREvent)
|
||||
data := utils.MapStorage{
|
||||
"FirstLevel": map[string]interface{}{},
|
||||
"AnotherFirstLevel": "ValAnotherFirstLevel",
|
||||
}
|
||||
|
||||
expErr := "NOT_IMPLEMENTED:nr1"
|
||||
if _, err := routeLazyPass(context.Background(), filters, ev,
|
||||
data, []string{""}, []string{""}, []string{""}); err == nil || err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v>, received <%v>", expErr, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1480,6 +1480,9 @@ func TestStatQueueProfileAsInterface(t *testing.T) {
|
||||
}, {
|
||||
MetricID: utils.MetaACD,
|
||||
FilterIDs: []string{"fltr1"},
|
||||
}, {
|
||||
|
||||
Blockers: utils.DynamicBlockers{{Blocker: true}},
|
||||
}},
|
||||
}
|
||||
if _, err := sqp.FieldAsInterface(nil); err != utils.ErrNotFound {
|
||||
@@ -1618,6 +1621,12 @@ func TestStatQueueProfileAsInterface(t *testing.T) {
|
||||
if val, exp := sqp.Metrics[0].String(), utils.ToJSON(sqp.Metrics[0]); exp != val {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(val))
|
||||
}
|
||||
|
||||
if val, err := sqp.Metrics[2].FieldAsInterface([]string{utils.Blockers}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if exp := sqp.Metrics[2].Blockers; !reflect.DeepEqual(exp, val) {
|
||||
t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(val))
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatQueueProfileMerge(t *testing.T) {
|
||||
@@ -1788,3 +1797,21 @@ func TestStatQueueWithAPIOptsMarshalJSONNil(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestStatQueueUnmarshalJSONErrUnmarsheling(t *testing.T) {
|
||||
sq := &StatQueue{}
|
||||
expErr := "invalid character 'Ô' looking for beginning of value"
|
||||
if err := sq.UnmarshalJSON([]byte{212}); err == nil || err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", expErr, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestStatQueueWithAPIOptsUnmarshalJSONErrWithSSQ(t *testing.T) {
|
||||
ssq := &StatQueueWithAPIOpts{}
|
||||
expErr := "invalid character 'Ô' looking for beginning of value"
|
||||
if err := ssq.UnmarshalJSON([]byte{212}); err == nil || err.Error() != expErr {
|
||||
t.Errorf("Expected error <%v>, Received error <%v>", expErr, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -425,3 +425,28 @@ func TestMapEventData(t *testing.T) {
|
||||
t.Errorf("Expected: %+v, received: %+v", expStruct, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapEventGetBoolOrDefault(t *testing.T) {
|
||||
|
||||
me := MapEvent{}
|
||||
fldName := "fldTest"
|
||||
dflt := true
|
||||
|
||||
if out := me.GetBoolOrDefault(fldName, dflt); out != true {
|
||||
t.Errorf("Map doesn't have that field name. Expected bool to be default <true>, Received <%v>", out)
|
||||
}
|
||||
|
||||
me = MapEvent{
|
||||
fldName: "Fldname",
|
||||
}
|
||||
if out := me.GetBoolOrDefault(fldName, dflt); out != true {
|
||||
t.Errorf("Expected bool to be default <true>, Received <%v>", out)
|
||||
}
|
||||
|
||||
me = MapEvent{
|
||||
fldName: interface{}("false"),
|
||||
}
|
||||
if out := me.GetBoolOrDefault(fldName, dflt); out != false {
|
||||
t.Errorf("Expected bool to same output as fldName <false>, Received <%v>", out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user