mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 21:59:53 +05:00
Added integration tests in apier/v1/actionprofiles.go
This commit is contained in:
committed by
Dan Christian Bogos
parent
06e4fd13c3
commit
ce00012fb1
@@ -53,7 +53,7 @@ func (apierSv1 *APIerSv1) GetActionProfileIDs(args *utils.PaginatorWithTenant, a
|
||||
if tnt == utils.EmptyString {
|
||||
tnt = apierSv1.Config.GeneralCfg().DefaultTenant
|
||||
}
|
||||
prfx := utils.RateProfilePrefix + tnt + utils.CONCATENATED_KEY_SEP
|
||||
prfx := utils.ActionProfilePrefix + tnt + utils.CONCATENATED_KEY_SEP
|
||||
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -37,7 +37,7 @@ var (
|
||||
actPrfCfg *config.CGRConfig
|
||||
actSRPC *rpc.Client
|
||||
actPrfDataDir = "/usr/share/cgrates"
|
||||
actPrf *AttributeWithCache
|
||||
actPrf *ActionProfileWithCache
|
||||
actPrfConfigDIR string //run tests for specific configuration
|
||||
|
||||
sTestsActPrf = []func(t *testing.T){
|
||||
@@ -49,13 +49,16 @@ var (
|
||||
testActionSLoadFromFolder,
|
||||
testActionSGetActionProfile,
|
||||
testActionSPing,
|
||||
testActionSSettActionProfile,
|
||||
testActionSGetActionProfileIDs,
|
||||
testActionSUpdateActionProfile,
|
||||
testActionSRemoveActionProfile,
|
||||
testActionSKillEngine,
|
||||
}
|
||||
)
|
||||
|
||||
//Test start here
|
||||
func TestActionSIT(t *testing.T) {
|
||||
actsTests := sTestsActPrf
|
||||
switch *dbType {
|
||||
case utils.MetaInternal:
|
||||
actPrfConfigDIR = "tutinternal"
|
||||
@@ -68,7 +71,7 @@ func TestActionSIT(t *testing.T) {
|
||||
default:
|
||||
t.Fatal("Unknown Database type")
|
||||
}
|
||||
for _, stest := range actsTests {
|
||||
for _, stest := range sTestsActPrf {
|
||||
t.Run(actPrfConfigDIR, stest)
|
||||
}
|
||||
}
|
||||
@@ -195,6 +198,121 @@ func testActionSPing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testActionSSettActionProfile(t *testing.T) {
|
||||
actPrf = &ActionProfileWithCache{
|
||||
ActionProfileWithOpts: &engine.ActionProfileWithOpts{
|
||||
&engine.ActionProfile{
|
||||
Tenant: "tenant_test",
|
||||
ID: "id_test",
|
||||
FilterIDs: nil,
|
||||
ActivationInterval: nil,
|
||||
Weight: 0,
|
||||
Schedule: "",
|
||||
AccountIDs: utils.StringSet{},
|
||||
Actions: []*engine.APAction{
|
||||
{
|
||||
ID: "test_action_id",
|
||||
FilterIDs: nil,
|
||||
Blocker: false,
|
||||
TTL: 0,
|
||||
Type: "",
|
||||
Opts: nil,
|
||||
Path: "",
|
||||
Value: nil,
|
||||
},
|
||||
{
|
||||
ID: "test_action_id2",
|
||||
FilterIDs: nil,
|
||||
Blocker: false,
|
||||
TTL: 0,
|
||||
Type: "",
|
||||
Opts: nil,
|
||||
Path: "",
|
||||
Value: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{},
|
||||
},
|
||||
}
|
||||
var result string
|
||||
expErr := utils.ErrNotFound.Error()
|
||||
if err := actSRPC.Call(utils.APIerSv1GetActionProfile, &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}, &result); err == nil || err.Error() != expErr {
|
||||
t.Errorf("Expected error: %v received: %v", expErr, err)
|
||||
}
|
||||
var reply string
|
||||
if err := actSRPC.Call(utils.APIerSv1SetActionProfile, actPrf, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
var reply2 *engine.ActionProfile
|
||||
if err := actSRPC.Call(utils.APIerSv1GetActionProfile, &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}, &reply2); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(actPrf.ActionProfile, reply2) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", actPrf.ActionProfile, reply2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testActionSGetActionProfileIDs(t *testing.T) {
|
||||
|
||||
expected := []string{"id_test"}
|
||||
var result []string
|
||||
if err := actSRPC.Call(utils.APIerSv1GetActionProfileIDs, utils.PaginatorWithTenant{}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(expected) != len(result) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expected, result)
|
||||
}
|
||||
if err := actSRPC.Call(utils.APIerSv1GetActionProfileIDs, utils.PaginatorWithTenant{Tenant: "tenant_test"}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(expected) != len(result) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expected, result)
|
||||
}
|
||||
if err := actSRPC.Call(utils.APIerSv1GetActionProfileIDs, utils.PaginatorWithTenant{
|
||||
Tenant: "tenant_test",
|
||||
Paginator: utils.Paginator{Limit: utils.IntPointer(1)},
|
||||
}, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if 1 != len(result) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expected, result)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testActionSUpdateActionProfile(t *testing.T) {
|
||||
var reply string
|
||||
actPrf.Weight = 2
|
||||
if err := actSRPC.Call(utils.APIerSv1SetActionProfile, actPrf, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
var reply2 *engine.ActionProfile
|
||||
if err := actSRPC.Call(utils.APIerSv1GetActionProfile, &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}, &reply2); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(actPrf.ActionProfile, reply2) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", actPrf.ActionProfile, reply2)
|
||||
}
|
||||
}
|
||||
|
||||
func testActionSRemoveActionProfile(t *testing.T) {
|
||||
var reply string
|
||||
if err := actSRPC.Call(utils.APIerSv1RemoveActionProfile, &utils.TenantIDWithCache{Tenant: "tenant_test", ID: "id_test"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
var reply2 *engine.ActionProfile
|
||||
expErr := utils.ErrNotFound.Error()
|
||||
if err := actSRPC.Call(utils.APIerSv1GetActionProfile, &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}, &reply2); err == nil || err.Error() != expErr {
|
||||
t.Errorf("Expected error: %v received: %v", expErr, err)
|
||||
}
|
||||
if err := actSRPC.Call(utils.APIerSv1RemoveActionProfile, &utils.TenantIDWithCache{Tenant: "tenant_test", ID: "id_test"}, &reply2); err == nil || err.Error() != expErr {
|
||||
t.Errorf("Expected error: %v received: %v", expErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
func testActionSKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(100); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -226,6 +226,9 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b
|
||||
case utils.RateProfilePrefix:
|
||||
tntID := utils.NewTenantID(dataID)
|
||||
_, err = dm.GetRateProfile(tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
|
||||
case utils.ActionProfilePrefix:
|
||||
tntID := utils.NewTenantID(dataID)
|
||||
_, err = dm.GetActionProfile(tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
|
||||
case utils.AttributeFilterIndexes:
|
||||
var tntCtx, idxKey string
|
||||
if tntCtx, idxKey, err = splitFilterIndex(dataID); err != nil {
|
||||
@@ -280,6 +283,12 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b
|
||||
return
|
||||
}
|
||||
_, err = dm.GetIndexes(utils.CacheRateFilterIndexes, tntCtx, idxKey, false, true)
|
||||
case utils.ActionProfilesFilterIndexPrfx:
|
||||
var tntCtx, idxKey string
|
||||
if tntCtx, idxKey, err = splitFilterIndex(dataID); err != nil {
|
||||
return
|
||||
}
|
||||
_, err = dm.GetIndexes(utils.CacheActionProfilesFilterIndexes, tntCtx, idxKey, false, true)
|
||||
case utils.FilterIndexPrfx:
|
||||
idx := strings.LastIndexByte(dataID, utils.InInFieldSep[0])
|
||||
if idx < 0 {
|
||||
|
||||
@@ -563,38 +563,40 @@ func GetDefaultEmptyCacheStats() map[string]*ltcache.CacheStats {
|
||||
|
||||
func GetDefaultEmptyArgCachePrefix() map[string][]string {
|
||||
return map[string][]string{
|
||||
utils.DESTINATION_PREFIX: nil,
|
||||
utils.REVERSE_DESTINATION_PREFIX: nil,
|
||||
utils.RATING_PLAN_PREFIX: nil,
|
||||
utils.RATING_PROFILE_PREFIX: nil,
|
||||
utils.ACTION_PREFIX: nil,
|
||||
utils.ACTION_PLAN_PREFIX: nil,
|
||||
utils.AccountActionPlansPrefix: nil,
|
||||
utils.ACTION_TRIGGER_PREFIX: nil,
|
||||
utils.SHARED_GROUP_PREFIX: nil,
|
||||
utils.ResourceProfilesPrefix: nil,
|
||||
utils.ResourcesPrefix: nil,
|
||||
utils.StatQueuePrefix: nil,
|
||||
utils.StatQueueProfilePrefix: nil,
|
||||
utils.ThresholdPrefix: nil,
|
||||
utils.ThresholdProfilePrefix: nil,
|
||||
utils.FilterPrefix: nil,
|
||||
utils.RouteProfilePrefix: nil,
|
||||
utils.AttributeProfilePrefix: nil,
|
||||
utils.ChargerProfilePrefix: nil,
|
||||
utils.DispatcherProfilePrefix: nil,
|
||||
utils.DispatcherHostPrefix: nil,
|
||||
utils.RateProfilePrefix: nil,
|
||||
utils.TimingsPrefix: nil,
|
||||
utils.AttributeFilterIndexes: nil,
|
||||
utils.ResourceFilterIndexes: nil,
|
||||
utils.StatFilterIndexes: nil,
|
||||
utils.ThresholdFilterIndexes: nil,
|
||||
utils.RouteFilterIndexes: nil,
|
||||
utils.ChargerFilterIndexes: nil,
|
||||
utils.DispatcherFilterIndexes: nil,
|
||||
utils.RateProfilesFilterIndexPrfx: nil,
|
||||
utils.RateFilterIndexPrfx: nil,
|
||||
utils.FilterIndexPrfx: nil,
|
||||
utils.DESTINATION_PREFIX: nil,
|
||||
utils.REVERSE_DESTINATION_PREFIX: nil,
|
||||
utils.RATING_PLAN_PREFIX: nil,
|
||||
utils.RATING_PROFILE_PREFIX: nil,
|
||||
utils.ACTION_PREFIX: nil,
|
||||
utils.ACTION_PLAN_PREFIX: nil,
|
||||
utils.AccountActionPlansPrefix: nil,
|
||||
utils.ACTION_TRIGGER_PREFIX: nil,
|
||||
utils.SHARED_GROUP_PREFIX: nil,
|
||||
utils.ResourceProfilesPrefix: nil,
|
||||
utils.ResourcesPrefix: nil,
|
||||
utils.StatQueuePrefix: nil,
|
||||
utils.StatQueueProfilePrefix: nil,
|
||||
utils.ThresholdPrefix: nil,
|
||||
utils.ThresholdProfilePrefix: nil,
|
||||
utils.FilterPrefix: nil,
|
||||
utils.RouteProfilePrefix: nil,
|
||||
utils.AttributeProfilePrefix: nil,
|
||||
utils.ChargerProfilePrefix: nil,
|
||||
utils.DispatcherProfilePrefix: nil,
|
||||
utils.DispatcherHostPrefix: nil,
|
||||
utils.RateProfilePrefix: nil,
|
||||
utils.ActionProfilePrefix: nil,
|
||||
utils.TimingsPrefix: nil,
|
||||
utils.AttributeFilterIndexes: nil,
|
||||
utils.ResourceFilterIndexes: nil,
|
||||
utils.StatFilterIndexes: nil,
|
||||
utils.ThresholdFilterIndexes: nil,
|
||||
utils.RouteFilterIndexes: nil,
|
||||
utils.ChargerFilterIndexes: nil,
|
||||
utils.DispatcherFilterIndexes: nil,
|
||||
utils.RateProfilesFilterIndexPrfx: nil,
|
||||
utils.RateFilterIndexPrfx: nil,
|
||||
utils.ActionProfilesFilterIndexPrfx: nil,
|
||||
utils.FilterIndexPrfx: nil,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user