diff --git a/apis/actions_test.go b/apis/actions_test.go index bdb44b269..daf909479 100644 --- a/apis/actions_test.go +++ b/apis/actions_test.go @@ -160,7 +160,7 @@ func TestActionsSetActionProfileCheckErrors(t *testing.T) { actPrf.ID = "TestActionsSetActionProfileCheckErrors" actPrf.Actions = make([]*engine.APAction, 1) actPrf.FilterIDs = []string{"invalid_filter_format"} - experr = "SERVER_ERROR: broken reference to filter: invalid_filter_format for item with ID: cgrates.org:TestActionsSetActionProfileCheckErrors" + experr = "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:TestActionsSetActionProfileCheckErrors" if err := adms.SetActionProfile(context.Background(), actPrf, &reply); err == nil || err.Error() != experr { diff --git a/apis/attributes_it_test.go b/apis/attributes_it_test.go index 5df203661..a8dea75b7 100644 --- a/apis/attributes_it_test.go +++ b/apis/attributes_it_test.go @@ -376,7 +376,7 @@ func testAttributeSetAttributeProfileBrokenReference(t *testing.T) { }, } var reply string - expectedErr := "SERVER_ERROR: broken reference to filter: invalid_filter_format for item with ID: cgrates.org:TEST_ATTRIBUTES_IT_TEST_SECOND" + expectedErr := "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:TEST_ATTRIBUTES_IT_TEST_SECOND" if err := attrSRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, attrPrf, &reply); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+v \n, received %+v", expectedErr, err) diff --git a/apis/attributes_test.go b/apis/attributes_test.go index 92a9214c2..f0f46150c 100644 --- a/apis/attributes_test.go +++ b/apis/attributes_test.go @@ -130,7 +130,7 @@ func TestAttributesSetAttributeProfileCheckErrors(t *testing.T) { attrPrf.ID = "TestSetAttributeProfileCheckErrors" attrPrf.FilterIDs = []string{"invalid_fltier_format"} - expected = "SERVER_ERROR: broken reference to filter: invalid_fltier_format for item with ID: cgrates.org:TestSetAttributeProfileCheckErrors" + expected = "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:TestSetAttributeProfileCheckErrors" if err := admS.SetAttributeProfile(context.Background(), attrPrf, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } diff --git a/apis/rates_it_test.go b/apis/rates_it_test.go index 433de1855..f76005477 100644 --- a/apis/rates_it_test.go +++ b/apis/rates_it_test.go @@ -402,7 +402,7 @@ func testRateSetAttributeProfileBrokenReference(t *testing.T) { }, } var reply string - expectedErr := "SERVER_ERROR: broken reference to filter: invalid_filter_format for item with ID: cgrates.org:TEST_RATE_IT_TEST_SECOND" + expectedErr := "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:TEST_RATE_IT_TEST_SECOND" if err := rateSRPC.Call(context.Background(), utils.AdminSv1SetRateProfile, ratePrf, &reply); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+v \n, received %+v", expectedErr, err) diff --git a/apis/resources_test.go b/apis/resources_test.go index 1928999ff..6e125d657 100644 --- a/apis/resources_test.go +++ b/apis/resources_test.go @@ -154,7 +154,7 @@ func TestResourcesSetResourceProfileCheckErrors(t *testing.T) { resPrf.ID = "TestResourcesSetResourceProfileCheckErrors" resPrf.FilterIDs = []string{"invalid_filter_format"} - experr = "SERVER_ERROR: broken reference to filter: invalid_filter_format for item with ID: cgrates.org:TestResourcesSetResourceProfileCheckErrors" + experr = "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:TestResourcesSetResourceProfileCheckErrors" if err := adms.SetResourceProfile(context.Background(), resPrf, &reply); err == nil || err.Error() != experr { diff --git a/apis/stats_test.go b/apis/stats_test.go index 76e1c3ae0..d58c98615 100644 --- a/apis/stats_test.go +++ b/apis/stats_test.go @@ -153,7 +153,7 @@ func TestStatsSetStatQueueProfileCheckErrors(t *testing.T) { sqPrf.ID = "TestStatsSetStatQueueProfileCheckErrors" sqPrf.FilterIDs = []string{"invalid_filter_format"} - experr = "SERVER_ERROR: broken reference to filter: invalid_filter_format for item with ID: cgrates.org:TestStatsSetStatQueueProfileCheckErrors" + experr = "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:TestStatsSetStatQueueProfileCheckErrors" if err := adms.SetStatQueueProfile(context.Background(), sqPrf, &reply); err == nil || err.Error() != experr { diff --git a/apis/thresholds_test.go b/apis/thresholds_test.go index 2b05084ce..5e449d0e4 100644 --- a/apis/thresholds_test.go +++ b/apis/thresholds_test.go @@ -154,7 +154,7 @@ func TestThresholdsSetThresholdProfileCheckErrors(t *testing.T) { thPrf.ID = "TestThresholdsSetThresholdProfileCheckErrors" thPrf.FilterIDs = []string{"invalid_filter_format"} - experr = "SERVER_ERROR: broken reference to filter: invalid_filter_format for item with ID: cgrates.org:TestThresholdsSetThresholdProfileCheckErrors" + experr = "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:TestThresholdsSetThresholdProfileCheckErrors" if err := adms.SetThresholdProfile(context.Background(), thPrf, &reply); err == nil || err.Error() != experr { diff --git a/config/config_it_test.go b/config/config_it_test.go index d9048bdf0..c0c873f50 100644 --- a/config/config_it_test.go +++ b/config/config_it_test.go @@ -267,6 +267,7 @@ func testCGRConfigReloadThresholdS(t *testing.T) { SuffixIndexedFields: &[]string{}, ActionSConns: []string{}, IndexedSelects: true, + ActionSConns: []string{}, } if !reflect.DeepEqual(expAttr, cfg.ThresholdSCfg()) { t.Errorf("Expected %s , received: %s ", utils.ToJSON(expAttr), utils.ToJSON(cfg.ThresholdSCfg())) diff --git a/cores/server_it_test.go b/cores/server_it_test.go index f75b37498..4c96181b1 100644 --- a/cores/server_it_test.go +++ b/cores/server_it_test.go @@ -98,11 +98,11 @@ func TestServerIT(t *testing.T) { type mockRegister string -func (x *mockRegister) ForTest(method *context.Context, args, reply interface{}) error { +func (x *mockRegister) ForTest(ctx *context.Context, args, reply interface{}) error { return nil } -func (robj *mockRegister) Ping(in string, out *string) error { +func (robj *mockRegister) Ping(ctx *context.Context, in string, out *string) error { *out = utils.Pong return nil } @@ -759,7 +759,7 @@ func testAcceptBiRPC(t *testing.T) { go server.acceptBiRPC(server.birpcSrv, l, utils.JSONCaps, jsonrpc.NewJSONBirpcCodec) rpc := jsonrpc.NewClient(p2) var reply string - expected := "rpc: can't find method AttributeSv1.Ping" + expected := "birpc: can't find method AttributeSv1.Ping" if err := rpc.Call(context.TODO(), utils.AttributeSv1Ping, utils.CGREvent{}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } diff --git a/engine/z_filterindexer_it_test.go b/engine/z_filterindexer_it_test.go index 2a15f5c47..957a64334 100644 --- a/engine/z_filterindexer_it_test.go +++ b/engine/z_filterindexer_it_test.go @@ -1137,7 +1137,7 @@ func testITResourceProfileIndexes(t *testing.T) { Stored: true, } - expected := "broken reference to filter: FIRST for item with ID: cgrates.org:RES_PRF1" + expected := "broken reference to filter: for item with ID: cgrates.org:RES_PRF1" if err := dataManager.SetResourceProfile(context.TODO(), resPref1, true); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } diff --git a/loaders/lib_test.go b/loaders/lib_test.go index 46224e26a..16c1d0128 100644 --- a/loaders/lib_test.go +++ b/loaders/lib_test.go @@ -23,12 +23,12 @@ import ( "errors" "flag" "io" - "net/rpc" - "net/rpc/jsonrpc" "strings" "testing" "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/rpcclient" @@ -48,12 +48,12 @@ var loaderPaths = []string{"/tmp/In", "/tmp/Out", "/tmp/LoaderIn", "/tmp/Subpath "/tmp/SubpathLoaderWithMove", "/tmp/SubpathOut", "/tmp/templateLoaderIn", "/tmp/templateLoaderOut", "/tmp/customSepLoaderIn", "/tmp/customSepLoaderOut"} -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/loaders/loader_it_test.go b/loaders/loader_it_test.go index 4733c637b..9b1c7e575 100644 --- a/loaders/loader_it_test.go +++ b/loaders/loader_it_test.go @@ -22,8 +22,9 @@ package loaders import ( "encoding/csv" "fmt" + "sort" + "io" - "net/rpc" "os" "path" "reflect" @@ -31,6 +32,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc" "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -41,7 +43,7 @@ var ( loaderCfgPath string loaderCfgDIR string //run tests for specific configuration loaderCfg *config.CGRConfig - loaderRPC *rpc.Client + loaderRPC *birpc.Client customAttributes = "12012000001\t12018209998\n12012000002\t15512580598\n12012000007\t19085199998\n12012000008\t18622784999\n12012000010\t17329440866\n12012000011\t18623689800\n12012000012\t19082050951\n12012000014\t17329440866\n12012000015\t12018209999\n12012000031\t12018209999\n12012000032\t19082050951\n12012000033\t12018209998\n12012000034\t12018209998\n" sTestsLoader = []func(t *testing.T){ @@ -174,7 +176,7 @@ func testLoaderPopulateData(t *testing.T) { func testLoaderLoadAttributes(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "CustomLoader"}, &reply); err != nil { t.Error(err) } @@ -190,22 +192,22 @@ func testLoaderVerifyOutDir(t *testing.T) { } func testLoaderCheckAttributes(t *testing.T) { - eAttrPrf := &engine.AttributeProfile{ + eAttrPrf := &engine.APIAttributeProfile{ Tenant: "cgrates.org", ID: "ALS1", - FilterIDs: []string{"*string:~*req.Account:1001", "*ai:~*req.AnswerTime:2014-07-29T15:00:00Z", "*string:~*opts.*context:con1|con2|con3"}, - Attributes: []*engine.Attribute{ + FilterIDs: []string{"*string:~*req.Account:1001", "*string:~*opts.*context:con1", "*string:~*opts.*context:con2|con3"}, + Attributes: []*engine.ExternalAttribute{ { FilterIDs: []string{"*string:~*req.Field1:Initial"}, Path: utils.MetaReq + utils.NestingSep + "Field1", Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("Sub1", utils.InfieldSep), + Value: "Sub1", }, { FilterIDs: []string{}, Path: utils.MetaReq + utils.NestingSep + "Field2", Type: utils.MetaVariable, - Value: config.NewRSRParsersMustCompile("Sub2", utils.InfieldSep), + Value: "Sub2", }}, Blocker: true, Weight: 20, @@ -213,15 +215,15 @@ func testLoaderCheckAttributes(t *testing.T) { if *encoding == utils.MetaGOB { // gob threats empty slices as nil values eAttrPrf.Attributes[1].FilterIDs = nil } - var reply *engine.AttributeProfile - if err := loaderRPC.Call(utils.AdminSv1GetAttributeProfile, + var reply *engine.APIAttributeProfile + if err := loaderRPC.Call(context.Background(), utils.AdminSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ALS1"}, }, &reply); err != nil { t.Fatal(err) } - eAttrPrf.Compile() - reply.Compile() + sort.Strings(reply.FilterIDs) + sort.Strings(eAttrPrf.FilterIDs) if !reflect.DeepEqual(eAttrPrf, reply) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eAttrPrf), utils.ToJSON(reply)) } @@ -240,7 +242,7 @@ func testLoaderPopulateDataWithoutMoving(t *testing.T) { func testLoaderLoadAttributesWithoutMoving(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "WithoutMoveToOut"}, &reply); err != nil { t.Error(err) } @@ -272,7 +274,7 @@ func testLoaderPopulateDataWithSubpath(t *testing.T) { func testLoaderLoadAttributesWithSubpath(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "SubpathLoaderWithoutMove"}, &reply); err != nil { t.Error(err) } @@ -304,7 +306,7 @@ func testLoaderPopulateDataWithSubpathWithMove(t *testing.T) { func testLoaderLoadAttributesWithoutSubpathWithMove(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "SubpathLoaderWithMove"}, &reply); err != nil { t.Error(err) } @@ -335,7 +337,7 @@ func testLoaderPopulateDataForTemplateLoader(t *testing.T) { func testLoaderLoadAttributesForTemplateLoader(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "LoaderWithTemplate"}, &reply); err != nil { t.Error(err) } @@ -372,31 +374,29 @@ func testLoaderPopulateDataForCustomSep(t *testing.T) { } func testLoaderCheckForCustomSep(t *testing.T) { - eAttrPrf := &engine.AttributeProfile{ + eAttrPrf := &engine.APIAttributeProfile{ Tenant: "cgrates.org", ID: "ATTR_12012000001", FilterIDs: []string{"*string:~*req.Destination:12012000001"}, - Attributes: []*engine.Attribute{ + Attributes: []*engine.ExternalAttribute{ { FilterIDs: []string{}, Path: "*req.Destination", Type: utils.MetaConstant, - Value: config.NewRSRParsersMustCompile("12018209998", utils.InfieldSep), + Value: "12018209998", }, }, } if *encoding == utils.MetaGOB { // gob threats empty slices as nil values eAttrPrf.Attributes[0].FilterIDs = nil } - var reply *engine.AttributeProfile - if err := loaderRPC.Call(utils.AdminSv1GetAttributeProfile, + var reply *engine.APIAttributeProfile + if err := loaderRPC.Call(context.Background(), utils.AdminSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_12012000001"}, }, &reply); err != nil { t.Fatal(err) } - eAttrPrf.Compile() - reply.Compile() if !reflect.DeepEqual(eAttrPrf, reply) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eAttrPrf), utils.ToJSON(reply)) } diff --git a/migrator/resource_it_test.go b/migrator/resource_it_test.go index c5d34001d..fe2ce8cce 100644 --- a/migrator/resource_it_test.go +++ b/migrator/resource_it_test.go @@ -182,7 +182,7 @@ func testResITMigrateAndMove(t *testing.T) { resPrfl := &engine.ResourceProfile{ Tenant: "cgrates.org", ID: "RES1", - FilterIDs: []string{"*string:~Account:1001"}, + FilterIDs: []string{"*string:~*req.Account:1001"}, UsageTTL: time.Second, Limit: 1, Weight: 10, diff --git a/migrator/routes_it_test.go b/migrator/routes_it_test.go index 9c6b9710f..58fe8f427 100644 --- a/migrator/routes_it_test.go +++ b/migrator/routes_it_test.go @@ -181,7 +181,7 @@ func testSupITMigrateAndMove(t *testing.T) { supPrfl := &engine.RouteProfile{ Tenant: "cgrates.org", ID: "SUP1", - FilterIDs: []string{"*string:~Account:1001"}, + FilterIDs: []string{"*string:~*req.Account:1001"}, Weight: 10, Sorting: utils.MetaQOS, SortingParameters: []string{}, diff --git a/utils/dataprovider_test.go b/utils/dataprovider_test.go index 1a6cfe99b..a6ad99747 100644 --- a/utils/dataprovider_test.go +++ b/utils/dataprovider_test.go @@ -134,3 +134,84 @@ func TestComposeNavMapVal(t *testing.T) { t.Errorf("Expected error: %s received: %v", ErrWrongPath, err) } } + +func TestIsPathValid(t *testing.T) { + path := "Field1.Field2[0]" + if err := IsPathValid(path); err != nil { + t.Error(err) + } + + /// + path = "~Field1" + errExpect := "Path is missing " + if err := IsPathValid(path); err == nil || err.Error() != errExpect { + t.Errorf("Expected %v but received %v", errExpect, err) + } + + /// + path = "~Field1.\n\t.Field2[0]" + errExpect = "Empty field path " + if err := IsPathValid(path); err == nil || err.Error() != errExpect { + t.Errorf("Expected %v but received %v", errExpect, err) + } + + /// + path = "~Field1.Field2[0]" + if err := IsPathValid(path); err != nil { + t.Error(err) + } +} + +func TestIsPathValidForExporters(t *testing.T) { + path := "Field1.Field2[0]" + if err := IsPathValidForExporters(path); err != nil { + t.Error(err) + } + + /// + path = "~Field1.\n\t.Field2[0]" + errExpect := "Empty field path " + if err := IsPathValidForExporters(path); err == nil || err.Error() != errExpect { + t.Errorf("Expected %v but received %v", errExpect, err) + } + + /// + path = "~Field1.Field2[0]" + if err := IsPathValidForExporters(path); err != nil { + t.Error(err) + } +} + +func TestCheckInLineFilter(t *testing.T) { + fltrs := []string{"Test1", "Test2"} + if err := CheckInLineFilter(fltrs); err != nil { + t.Error(err) + } + + /// + fltrs = []string{"*Test1", "*Test2"} + errExpect := "inline parse error for string: <*Test1>" + if err := CheckInLineFilter(fltrs); err == nil || err.Error() != errExpect { + t.Errorf("Expected %v but received %v", errExpect, err) + } + + /// + fltrs = []string{"*Test1:*Test2:*Test3:*Test4"} + if err := CheckInLineFilter(fltrs); err != nil { + t.Error(err) + } + + /// + fltrs = []string{"*empty:~Field1..Field2[0]:*Test3:*Test4"} + errExpect = "Empty field path for <*empty:~Field1..Field2[0]:*Test3:*Test4>" + if err := CheckInLineFilter(fltrs); err == nil || err.Error() != errExpect { + t.Errorf("Expected %v but received %v", errExpect, err) + } + + /// + fltrs = []string{"*empty:~Field1.Field2[0]:~Field1..Field2[0]|Test4"} + errExpect = "Empty field path for <*empty:~Field1.Field2[0]:~Field1..Field2[0]|Test4>" + if err := CheckInLineFilter(fltrs); err == nil || err.Error() != errExpect { + t.Errorf("Expected %v but received %v", errExpect, err) + } +}