mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 15:18:44 +05:00
Removed any* for rating-profile ID
This commit is contained in:
committed by
Dan Christian Bogos
parent
21a8de97c7
commit
997a990db1
@@ -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")
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -143,3 +143,4 @@ func testDMitCRUDStatQueue(t *testing.T) {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user