From 997a990db1d8df52966d66dac2db839863186298 Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Mon, 19 Jul 2021 18:08:11 +0300 Subject: [PATCH] Removed any* for rating-profile ID --- apier/v1/apier.go | 11 +++-- apier/v1/apier2_it_test.go | 88 +++++++++++++++++++++++++++++++++++ apier/v1/apier_it_test.go | 13 ++++++ engine/datamanager_it_test.go | 1 + 4 files changed, 108 insertions(+), 5 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index c57df9181..2f82a8a11 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1058,28 +1058,29 @@ type AttrRemoveRatingProfile struct { func (arrp *AttrRemoveRatingProfile) GetId() (result string) { result = utils.META_OUT + utils.CONCATENATED_KEY_SEP - if arrp.Tenant != "" && arrp.Tenant != utils.ANY { + if arrp.Tenant != utils.EmptyString && arrp.Tenant != utils.ANY { result += arrp.Tenant + utils.CONCATENATED_KEY_SEP } else { return } - if arrp.Category != "" && arrp.Category != utils.ANY { + if arrp.Category != utils.EmptyString && arrp.Category != utils.ANY { result += arrp.Category + utils.CONCATENATED_KEY_SEP } else { return } - if arrp.Subject != "" && arrp.Subject != utils.ANY { + if arrp.Subject != utils.EmptyString { result += arrp.Subject } return } func (apiv1 *APIerSv1) RemoveRatingProfile(attr AttrRemoveRatingProfile, reply *string) error { - if (attr.Subject != "" && utils.IsSliceMember([]string{attr.Tenant, attr.Category}, "")) || - (attr.Category != "" && attr.Tenant == "") { + if (attr.Subject != utils.EmptyString && utils.IsSliceMember([]string{attr.Tenant, attr.Category}, "")) || + (attr.Category != utils.EmptyString && attr.Tenant == utils.EmptyString) { return utils.ErrMandatoryIeMissing } + utils.Logger.Debug(fmt.Sprintf("%v", attr.GetId())) _, err := guardian.Guardian.Guard(func() (interface{}, error) { return 0, apiv1.DataManager.RemoveRatingProfile(attr.GetId(), utils.NonTransactional) }, config.CgrConfig().GeneralCfg().LockingTimeout, "RemoveRatingProfile") diff --git a/apier/v1/apier2_it_test.go b/apier/v1/apier2_it_test.go index dac3917e8..bc50f05ef 100644 --- a/apier/v1/apier2_it_test.go +++ b/apier/v1/apier2_it_test.go @@ -22,6 +22,7 @@ package v1 import ( "net/rpc" + "os/exec" "path" "reflect" "sort" @@ -58,6 +59,14 @@ var ( testAPIerGetActionPlanIDs, testAPIerGetRatingPlanIDs, testAPIerKillEngine, + + testAPIerInitDataDb, + testAPIerResetStorDb, + testAPIerStartEngine, + testAPIerRPCConn, + testAPIerSleep, + testApierSetAndRemoveRatingProfileAnySubject, + testAPIerKillEngine, } ) @@ -317,6 +326,85 @@ func testAPIerGetRatingPlanIDs(t *testing.T) { } } +func testAPIerSleep(t *testing.T) { + var rply string + if err := apierRPC.Call(utils.CoreSv1Sleep, + &DurationArgs{DurationTime: time.Duration(100 * time.Millisecond)}, + &rply); err != nil { + t.Error(err) + return + } +} + +func testApierSetAndRemoveRatingProfileAnySubject(t *testing.T) { + var rply string + if err := apierRPC.Call(utils.CoreSv1Sleep, + &DurationArgs{DurationTime: time.Duration(100 * time.Millisecond)}, + &rply); err != nil { + t.Error(err) + return + } + + loader := exec.Command("cgr-loader", "-config_path", apierCfgPath, "-path", path.Join(*dataDir, "tariffplans", "tutorial")) + if err := loader.Run(); err != nil { + t.Error(err) + } + + rpf := &utils.AttrSetRatingProfile{ + Tenant: "cgrates.org", + Category: "call", + Subject: "SUPPLIER1", + RatingPlanActivations: []*utils.TPRatingActivation{ + { + ActivationTime: "2018-01-01T00:00:00Z", + RatingPlanId: "RP_SMS", + }, + }, + Overwrite: true, + } + var reply string + if err := apierRPC.Call(utils.APIerSv1SetRatingProfile, rpf, &reply); err != nil { + t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error()) + } else if reply != utils.OK { + t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply) + } + + expected := engine.RatingProfile{ + Id: "*out:cgrates.org:call:SUPPLIER1", + RatingPlanActivations: engine.RatingPlanActivations{ + { + ActivationTime: time.Date(2018, 1, 1, 0, 0, 0,0, time.UTC), + RatingPlanId: "RP_SMS", + }, + }, + } + attrGetRatingPlan := &utils.AttrGetRatingProfile{ + Tenant: "cgrates.org", Category: "call", Subject: "SUPPLIER1"} + var rpl engine.RatingProfile + if err := apierRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { + t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err) + } else if !reflect.DeepEqual(expected, rpl) { + t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) + } + + if err := apierRPC.Call(utils.APIerSv1RemoveRatingProfile, &AttrRemoveRatingProfile{ + Tenant: "cgrates.org", + Category: utils.CALL, + Subject: utils.ANY, + }, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Errorf("Expected: %s, received: %s ", utils.OK, reply) + } + + if err := apierRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { + t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err) + } else if !reflect.DeepEqual(expected, rpl) { + t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) + } +} + + func testAPIerKillEngine(t *testing.T) { if err := engine.KillEngine(*waitRater); err != nil { t.Error(err) diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index cd3fb39ab..248d2f7db 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -2074,3 +2074,16 @@ func testApierStopEngine(t *testing.T) { t.Error(err) } } + +func TestAttrRemoveRatingProfileGetID(t *testing.T) { + attr := &AttrRemoveRatingProfile{ + Tenant: "cgrates.org", + Category: "sms", + Subject: "*any", + } + expRes := "*out:cgrates.org:sms:*any" + if rply := attr.GetId(); rply != expRes { + t.Errorf("Expected %+v, received %v", expRes, rply) + } +} + diff --git a/engine/datamanager_it_test.go b/engine/datamanager_it_test.go index 6e6af0de3..e55106770 100644 --- a/engine/datamanager_it_test.go +++ b/engine/datamanager_it_test.go @@ -143,3 +143,4 @@ func testDMitCRUDStatQueue(t *testing.T) { t.Error(rcvErr) } } +