mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Test more methods for remote functinality
This commit is contained in:
committed by
Dan Christian Bogos
parent
d2fd2e19db
commit
5abb79be13
@@ -29,13 +29,13 @@ import (
|
||||
|
||||
var (
|
||||
apierDebit *ApierV1
|
||||
apierDebitStorage *engine.MapStorage
|
||||
apierDebitStorage *engine.InternalDB
|
||||
responder *engine.Responder
|
||||
dm *engine.DataManager
|
||||
)
|
||||
|
||||
func init() {
|
||||
apierDebitStorage, _ = engine.NewMapStorage()
|
||||
apierDebitStorage = engine.NewInternalDB(nil, nil)
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
responder := &engine.Responder{MaxComputedUsage: cfg.RalsCfg().MaxComputedUsage}
|
||||
dm = engine.NewDataManager(apierDebitStorage, config.CgrConfig().CacheCfg(), nil, nil)
|
||||
|
||||
@@ -49,11 +49,15 @@ var sTestsInternalRemoteIT = []func(t *testing.T){
|
||||
testInternalRemoteITInitCfg,
|
||||
testInternalRemoteITStartEngine,
|
||||
testInternalRemoteITRPCConn,
|
||||
testInternalRemoteITGetAccount,
|
||||
testInternalRemoteITGetAttribute,
|
||||
testInternalRemoteITGetThreshold,
|
||||
testInternalRemoteITGetThresholdProfile,
|
||||
testInternalRemoteITGetResource,
|
||||
testInternalRemoteITGetResourceProfile,
|
||||
testInternalRemoteITGetStatQueueProfile,
|
||||
testInternalRemoteITGetSupplier,
|
||||
testInternalRemoteITGetFilter,
|
||||
testInternalRemoteITKillEngine,
|
||||
}
|
||||
|
||||
@@ -120,6 +124,21 @@ func testInternalRemoteITLoadData(t *testing.T) {
|
||||
if err := loader.WriteToDatabase(false, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
acc := &engine.Account{
|
||||
ID: "cgrates.org:testAccount",
|
||||
BalanceMap: map[string]engine.Balances{
|
||||
"utils.MONETARY": []*engine.Balance{
|
||||
{
|
||||
ID: "testAccount",
|
||||
Value: 10,
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := rmtDM.DataDB().SetAccount(acc); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testInternalRemoteITVerifyLoadedDataInRemote(t *testing.T) {
|
||||
@@ -175,6 +194,40 @@ func testInternalRemoteITRPCConn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testInternalRemoteITGetAccount(t *testing.T) {
|
||||
var acnt *engine.Account
|
||||
expAcc := &engine.Account{
|
||||
ID: "cgrates.org:testAccount",
|
||||
BalanceMap: map[string]engine.Balances{
|
||||
"utils.MONETARY": []*engine.Balance{
|
||||
{
|
||||
ID: "testAccount",
|
||||
Value: 10,
|
||||
Weight: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
attrs := &utils.AttrGetAccount{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "testAccount",
|
||||
}
|
||||
if err := internalRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expAcc, acnt) {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(expAcc), utils.ToJSON(acnt))
|
||||
}
|
||||
|
||||
attrs = &utils.AttrGetAccount{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "nonexistAccount",
|
||||
}
|
||||
if err := internalRPC.Call("ApierV2.GetAccount", attrs, &acnt); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("expecting: %+v, received: %+v", utils.ErrNotFound, err)
|
||||
}
|
||||
}
|
||||
|
||||
func testInternalRemoteITGetAttribute(t *testing.T) {
|
||||
alsPrf = &AttributeWithCache{
|
||||
AttributeProfile: &engine.AttributeProfile{
|
||||
@@ -284,6 +337,95 @@ func testInternalRemoteITGetResourceProfile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testInternalRemoteITGetStatQueueProfile(t *testing.T) {
|
||||
expStq := &engine.StatQueueProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats2",
|
||||
FilterIDs: []string{"FLTR_ACNT_1001_1002"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
|
||||
},
|
||||
QueueLength: 100,
|
||||
TTL: -1,
|
||||
MinItems: 0,
|
||||
Metrics: []*engine.MetricWithFilters{
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: utils.MetaTCC,
|
||||
},
|
||||
&engine.MetricWithFilters{
|
||||
MetricID: utils.MetaTCD,
|
||||
},
|
||||
},
|
||||
Stored: false,
|
||||
Blocker: true,
|
||||
Weight: 30,
|
||||
ThresholdIDs: []string{utils.META_NONE},
|
||||
}
|
||||
var reply *engine.StatQueueProfile
|
||||
if err := internalRPC.Call("ApierV1.GetStatQueueProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "Stats2"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expStq, reply) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expStq), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testInternalRemoteITGetSupplier(t *testing.T) {
|
||||
var reply *engine.SupplierProfile
|
||||
splPrf := &engine.SupplierProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "SPL_ACNT_1001",
|
||||
FilterIDs: []string{"FLTR_ACNT_1001"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2017, 11, 27, 0, 0, 0, 0, time.UTC),
|
||||
},
|
||||
Sorting: utils.MetaWeight,
|
||||
SortingParameters: []string{},
|
||||
Suppliers: []*engine.Supplier{
|
||||
{
|
||||
ID: "supplier1",
|
||||
Weight: 10,
|
||||
},
|
||||
{
|
||||
ID: "supplier2",
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
|
||||
if err := internalRPC.Call("ApierV1.GetSupplierProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "SPL_ACNT_1001"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(splPrf, reply) {
|
||||
t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(splPrf), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testInternalRemoteITGetFilter(t *testing.T) {
|
||||
expFltr := &engine.Filter{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "FLTR_ACNT_1001",
|
||||
Rules: []*engine.FilterRule{
|
||||
{
|
||||
Type: "*string",
|
||||
FieldName: "~Account",
|
||||
Values: []string{"1001"},
|
||||
},
|
||||
},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
var reply *engine.Filter
|
||||
if err := internalRPC.Call("ApierV1.GetFilter",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACNT_1001"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expFltr, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expFltr), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testInternalRemoteITKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(100); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user