mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add ApierV1.GetRatingPlanIDs + test ( fixes #1692 )
This commit is contained in:
committed by
Dan Christian Bogos
parent
5d45c339a3
commit
9b8d08dc0d
@@ -1254,7 +1254,7 @@ func (self *ApierV1) ComputeActionPlanIndexes(_ string, reply *string) (err erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetActionPlanIDs returns list of attributeProfile IDs registered for a tenant
|
||||
// GetActionPlanIDs returns list of ActionPlan IDs registered for a tenant
|
||||
func (apierV1 *ApierV1) GetActionPlanIDs(args utils.TenantArgWithPaginator, attrPrfIDs *[]string) error {
|
||||
prfx := utils.ACTION_PLAN_PREFIX
|
||||
keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(utils.ACTION_PLAN_PREFIX)
|
||||
@@ -1271,3 +1271,21 @@ func (apierV1 *ApierV1) GetActionPlanIDs(args utils.TenantArgWithPaginator, attr
|
||||
*attrPrfIDs = args.PaginateStringSlice(retIDs)
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRatingPlanIDs returns list of RatingPlan IDs registered for a tenant
|
||||
func (apierV1 *ApierV1) GetRatingPlanIDs(args utils.TenantArgWithPaginator, attrPrfIDs *[]string) error {
|
||||
prfx := utils.RATING_PLAN_PREFIX
|
||||
keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(utils.RATING_PLAN_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
retIDs := make([]string, len(keys))
|
||||
for i, key := range keys {
|
||||
retIDs[i] = key[len(prfx):]
|
||||
}
|
||||
*attrPrfIDs = args.PaginateStringSlice(retIDs)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -58,6 +59,7 @@ var sTestsAPIer = []func(t *testing.T){
|
||||
testAPIerGetRatingPlanCost2,
|
||||
testAPIerGetRatingPlanCost3,
|
||||
testAPIerGetActionPlanIDs,
|
||||
testAPIerGetRatingPlanIDs,
|
||||
testAPIerKillEngine,
|
||||
}
|
||||
|
||||
@@ -277,13 +279,32 @@ func testAPIerGetActionPlanIDs(t *testing.T) {
|
||||
utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}},
|
||||
&reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(reply) != 1 {
|
||||
} else if len(reply) != 1 {
|
||||
t.Errorf("Expected: 1 , received: <%+v>", len(reply))
|
||||
}else if reply[0]!="AP_PACKAGE_10"{
|
||||
} else if reply[0] != "AP_PACKAGE_10" {
|
||||
t.Errorf("Expected: AP_PACKAGE_10 , received: <%+v>", reply[0])
|
||||
}
|
||||
}
|
||||
|
||||
func testAPIerGetRatingPlanIDs(t *testing.T) {
|
||||
var reply []string
|
||||
expected := []string{"RP_1002_LOW", "RP_1003", "RP_1001", "RP_SMS", "RP_1002"}
|
||||
if err := apierRPC.Call(utils.ApierV1GetRatingPlanIDs,
|
||||
utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}},
|
||||
&reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(reply) != 5 {
|
||||
t.Errorf("Expected: 5 , received: <%+v>", len(reply))
|
||||
} else {
|
||||
sort.Strings(reply)
|
||||
sort.Strings(expected)
|
||||
if !reflect.DeepEqual(reply, expected) {
|
||||
t.Errorf("Expected: <%+v> , received: <%+v>", expected, reply)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testAPIerKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(*waitRater); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -811,6 +811,7 @@ const (
|
||||
ApierV1GetAccountActionPlan = "ApierV1.GetAccountActionPlan"
|
||||
ApierV1ComputeActionPlanIndexes = "ApierV1.ComputeActionPlanIndexes"
|
||||
ApierV1GetActionPlanIDs = "ApierV1.GetActionPlanIDs"
|
||||
ApierV1GetRatingPlanIDs = "ApierV1.GetRatingPlanIDs"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user