mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added it tests for 'Count' APIs
This commit is contained in:
committed by
Dan Christian Bogos
parent
c8a9b18428
commit
035de962e9
@@ -62,6 +62,24 @@ func (APIerSv1 *APIerSv1) GetAttributeProfileIDs(args utils.TenantArgWithPaginat
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAttributeProfileIDsCount sets in reply var the total number of AttributeProfileIDs registered for a tenant
|
||||
// returns ErrNotFound in case of 0 AttributeProfileIDs
|
||||
func (APIerSv1 *APIerSv1) GetAttributeProfileIDsCount(args *utils.TenantArg, reply *int) (err error) {
|
||||
if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
var keys []string
|
||||
prfx := utils.AttributeProfilePrefix + args.Tenant + ":"
|
||||
if keys, err = APIerSv1.DataManager.DataDB().GetKeysForPrefix(prfx); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
*reply = len(keys)
|
||||
return
|
||||
}
|
||||
|
||||
type AttributeWithCache struct {
|
||||
*engine.AttributeProfile
|
||||
Cache *string
|
||||
|
||||
@@ -94,6 +94,24 @@ func (APIerSv1 *APIerSv1) GetThresholdProfileIDs(args utils.TenantArgWithPaginat
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetThresholdProfileIDsCount sets in reply var the total number of ThresholdProfileIDs registered for the received tenant
|
||||
// returns ErrNotFound in case of 0 ThresholdProfileIDs
|
||||
func (APIerSv1 *APIerSv1) GetThresholdProfileIDsCount(args *utils.TenantArg, reply *int) (err error) {
|
||||
if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
var keys []string
|
||||
prfx := utils.ThresholdProfilePrefix + args.Tenant + ":"
|
||||
if keys, err = APIerSv1.DataManager.DataDB().GetKeysForPrefix(prfx); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
*reply = len(keys)
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetThresholdProfile alters/creates a ThresholdProfile
|
||||
func (APIerSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdWithCache, reply *string) error {
|
||||
if missing := utils.MissingStructFields(args.ThresholdProfile, []string{"Tenant", "ID"}); len(missing) != 0 {
|
||||
|
||||
@@ -80,16 +80,19 @@ func (apiv2 *APIerSv2) GetAccounts(attr utils.AttrGetAccounts, reply *[]*engine.
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAccountsCount returns the total number of accounts
|
||||
func (apiv2 *APIerSv2) GetAccountsCount(attr utils.AttrGetAccountsCount, reply *int) (err error) {
|
||||
// GetAccountsCount sets in reply var the total number of accounts registered for the received tenant
|
||||
// returns ErrNotFound in case of 0 accounts
|
||||
func (apiv2 *APIerSv2) GetAccountsCount(attr *utils.AttrGetAccountsCount, reply *int) (err error) {
|
||||
if len(attr.Tenant) == 0 {
|
||||
return utils.NewErrMandatoryIeMissing("Tenant")
|
||||
}
|
||||
var accountKeys []string
|
||||
|
||||
if accountKeys, err = apiv2.DataManager.DataDB().GetKeysForPrefix(utils.ACCOUNT_PREFIX + attr.Tenant); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(accountKeys) == 0 {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
*reply = len(accountKeys)
|
||||
|
||||
return
|
||||
|
||||
@@ -218,8 +218,9 @@ func (apiv2 *APIerSv2) GetActions(attr AttrGetActions, reply *map[string]engine.
|
||||
|
||||
type AttrGetActionsCount struct{}
|
||||
|
||||
// GetActionsCount get
|
||||
func (apiv2 *APIerSv2) GetActionsCount(attr AttrGetActionsCount, reply *int) (err error) {
|
||||
// GetActionsCount sets in reply var the total number of actions registered for the received tenant
|
||||
// returns ErrNotFound in case of 0 actions
|
||||
func (apiv2 *APIerSv2) GetActionsCount(attr *AttrGetActionsCount, reply *int) (err error) {
|
||||
var actionKeys []string
|
||||
if actionKeys, err = apiv2.DataManager.DataDB().GetKeysForPrefix(utils.ACTION_PREFIX); err != nil {
|
||||
return err
|
||||
|
||||
@@ -55,7 +55,9 @@ var (
|
||||
testAPIerSv2itSetActionWithCategory,
|
||||
testAPIerSv2itSetActionPlanWithWrongTiming,
|
||||
testAPIerSv2itSetActionPlanWithWrongTiming2,
|
||||
testAPIerSv2BackwardsCompatible,
|
||||
testAPIerSv2itBackwardsCompatible,
|
||||
testAPIerSv2itGetAccountsCount,
|
||||
testAPIerSv2itGetActionsCount,
|
||||
testAPIerSv2itKillEngine,
|
||||
}
|
||||
)
|
||||
@@ -431,7 +433,7 @@ func testAPIerSv2itSetActionPlanWithWrongTiming2(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testAPIerSv2BackwardsCompatible(t *testing.T) {
|
||||
func testAPIerSv2itBackwardsCompatible(t *testing.T) {
|
||||
var reply string
|
||||
if err := apierRPC.Call("ApierV2.Ping", new(utils.CGREvent), &reply); err != nil {
|
||||
t.Error(err)
|
||||
@@ -440,6 +442,136 @@ func testAPIerSv2BackwardsCompatible(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testAPIerSv2itGetAccountsCount(t *testing.T) {
|
||||
var reply1 int
|
||||
if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{
|
||||
Tenant: "cgrates.org"}, &reply1); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply1 != 3 {
|
||||
t.Errorf("Expecting: 3, received: %+v", reply1)
|
||||
}
|
||||
var reply string
|
||||
if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{
|
||||
Account: "dan", Tenant: "cgrates.org"}, &reply); err != nil {
|
||||
t.Errorf("Unexpected error : %+v", err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{
|
||||
Account: "TestAPIerSv2itSetAccountWithAP1", Tenant: "cgrates.org"}, &reply); err != nil {
|
||||
t.Errorf("Unexpected error : %+v", err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{
|
||||
Account: "TestAPIerSv2itSetActionWithCategory", Tenant: "cgrates.org"}, &reply); err != nil {
|
||||
t.Errorf("Unexpected error : %+v", err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{
|
||||
Tenant: "cgrates.org"}, &reply1); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ErrNotFound, err)
|
||||
}
|
||||
argSetAccount := AttrSetAccount{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "TestAPIerSv2CountAccounts",
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2SetAccount, argSetAccount, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var acnt engine.Account
|
||||
if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{
|
||||
Tenant: "cgrates.org", Account: "TestAPIerSv2CountAccounts"}, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{Tenant: "cgrates.org"}, &reply1); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply1 != 1 {
|
||||
t.Errorf("Expecting: 1, received: %+v", reply1)
|
||||
}
|
||||
argSetAccount = AttrSetAccount{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "TestAPIerSv2CountAccounts2",
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2SetAccount, argSetAccount, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{
|
||||
Tenant: "cgrates.org", Account: "TestAPIerSv2CountAccounts2"}, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{Tenant: "cgrates.org"}, &reply1); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply1 != 2 {
|
||||
t.Errorf("Expecting: 2, received: %+v", reply1)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{
|
||||
Account: "TestAPIerSv2CountAccounts2", Tenant: "cgrates.org"}, &reply); err != nil {
|
||||
t.Errorf("Unexpected error : %+v", err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{Tenant: "cgrates.org"}, &reply1); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply1 != 1 {
|
||||
t.Errorf("Expecting: 1, received: %+v", reply1)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{
|
||||
Account: "TestAPIerSv2CountAccounts", Tenant: "cgrates.org"}, &reply); err != nil {
|
||||
t.Errorf("Unexpected error : %+v", err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{
|
||||
Tenant: "cgrates.org"}, &reply1); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ErrNotFound, err)
|
||||
}
|
||||
}
|
||||
|
||||
func testAPIerSv2itGetActionsCount(t *testing.T) {
|
||||
var reply1 int
|
||||
if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply1 != 3 {
|
||||
t.Errorf("Expecting: 3, received : %+v", reply1)
|
||||
}
|
||||
attrs := utils.AttrSetActions{ActionsId: "DISABLE_ACCOUNT2", Actions: []*utils.TPAction{
|
||||
{Identifier: utils.DISABLE_ACCOUNT, Weight: 0.7},
|
||||
}}
|
||||
var reply string
|
||||
if err := apierRPC.Call(utils.APIerSv2SetActions, attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply1 != 4 {
|
||||
t.Errorf("Expecting: 4, received : %+v", reply1)
|
||||
}
|
||||
|
||||
attrRemoveActions := &v1.AttrRemoveActions{
|
||||
ActionIDs: []string{"DISABLE_ACCOUNT", "DISABLE_ACCOUNT2", "TestAPIerSv2itSetAccountWithAP_ACT_1"},
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2RemoveActions, &attrRemoveActions, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply1 != 1 {
|
||||
t.Errorf("Expecting: 1, received : %+v", reply1)
|
||||
}
|
||||
attrRemoveActions = &v1.AttrRemoveActions{
|
||||
ActionIDs: []string{"TestAPIerSv2itSetActionWithCategory_ACT"},
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2RemoveActions, &attrRemoveActions, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expecting %+v, received: %+v", utils.ErrNotFound, err)
|
||||
}
|
||||
attrs = utils.AttrSetActions{ActionsId: "Test", Actions: []*utils.TPAction{
|
||||
{Identifier: utils.DISABLE_ACCOUNT, Weight: 0.7},
|
||||
}}
|
||||
if err := apierRPC.Call(utils.APIerSv2SetActions, attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply1 != 1 {
|
||||
t.Errorf("Expecting: 1, received : %+v", reply1)
|
||||
}
|
||||
}
|
||||
|
||||
func testAPIerSv2itKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(delay); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -1219,6 +1219,7 @@ const (
|
||||
APIerSv1GetSharedGroup = "APIerSv1.GetSharedGroup"
|
||||
APIerSv1RemoveActionTrigger = "APIerSv1.RemoveActionTrigger"
|
||||
APIerSv1GetAccount = "APIerSv1.GetAccount"
|
||||
APIerSv1GetAttributeProfileIDsCount = "APIerSv1.GetAttributeProfileIDsCount"
|
||||
)
|
||||
|
||||
// APIerSv1 TP APIs
|
||||
@@ -1259,6 +1260,8 @@ const (
|
||||
APIerSv2ResetAccountActionTriggers = "APIerSv2.ResetAccountActionTriggers"
|
||||
APIerSv2RemoveActions = "APIerSv2.RemoveActions"
|
||||
APIerSv2ExportCdrsToFile = "APIerSv2.ExportCdrsToFile"
|
||||
APIerSv2GetAccountsCount = "APIerSv2.GetAccountsCount"
|
||||
APIerSv2GetActionsCount = "APIerSv2.GetActionsCount"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user