diff --git a/data/conf/samples/acc_generaltest_internal/cgrates.json b/data/conf/samples/acc_generaltest_internal/cgrates.json new file mode 100644 index 000000000..0052380b3 --- /dev/null +++ b/data/conf/samples/acc_generaltest_internal/cgrates.json @@ -0,0 +1,140 @@ +{ +// CGRateS Configuration file +// + + +"general": { + "log_level": 7, + "reply_timeout": "50s" +}, + + +"listen": { + "rpc_json": ":2012", + "rpc_gob": ":2013", + "http": ":2080" +}, + + +"data_db": { + "db_type": "*internal" +}, + + +"stor_db": { + "db_type": "*internal" +}, + +"loaders": [ + { + "id": "*default", + "enabled": true, + "tenant": "cgrates.org", + "lockfile_path": ".cgr.lck", + "tp_in_dir": "/usr/share/cgrates/tariffplans/testit", + "tp_out_dir": "", + }, +], + +"rals": { + "enabled": true, + "thresholds_conns": ["*internal"], + "max_increments":3000000 +}, + + +"schedulers": { + "enabled": true, + "cdrs_conns": ["*internal"], + "stats_conns": ["*localhost"] +}, + + +"cdrs": { + "enabled": true, + "chargers_conns":["*internal"] +}, + + +"attributes": { + "enabled": true, + "stats_conns": ["*localhost"], + "resources_conns": ["*localhost"], + "accounts_conns": ["*localhost"] +}, + + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"] +}, + + +"resources": { + "enabled": true, + "store_interval": "-1", + "thresholds_conns": ["*internal"] +}, + + +"stats": { + "enabled": true, + "store_interval": "-1", + "thresholds_conns": ["*internal"] +}, + +"thresholds": { + "enabled": true, + "store_interval": "-1" +}, + + +"routes": { + "enabled": true, + "prefix_indexed_fields":["*req.Destination"], + "stats_conns": ["*internal"], + "resources_conns": ["*internal"], + "rals_conns": ["*internal"] +}, + + +"sessions": { + "enabled": true, + "routes_conns": ["*internal"], + "resources_conns": ["*internal"], + "attributes_conns": ["*internal"], + "rals_conns": ["*internal"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*internal"] +}, + + +"admins": { + "enabled": true, + "scheduler_conns": ["*internal"] +}, + + +"rates": { + "enabled": true +}, + + +"actions": { + "enabled": true, + "accounts_conns": ["*localhost"] +}, + + +"accounts": { + "enabled": true +}, + + +"filters": { + "stats_conns": ["*internal"], + "resources_conns": ["*internal"], + "accounts_conns": ["*internal"], +}, + +} diff --git a/data/conf/samples/acc_generaltest_mongo/cgrates.json b/data/conf/samples/acc_generaltest_mongo/cgrates.json new file mode 100644 index 000000000..e70c7b9b1 --- /dev/null +++ b/data/conf/samples/acc_generaltest_mongo/cgrates.json @@ -0,0 +1,157 @@ +{ +// CGRateS Configuration file + + +"general": { + "log_level": 7, + "reply_timeout": "30s", +}, + + +"listen": { + "rpc_json": ":2012", + "rpc_gob": ":2013", + "http": ":2080", +}, + + +"data_db": { + "db_type": "mongo", + "db_name": "10", + "db_port": 27017, +}, + + +"stor_db": { + "db_type": "mongo", + "db_name": "cgrates", + "db_port": 27017, +}, + +"loaders": [ + { + "id": "*default", + "enabled": true, + "tenant": "cgrates.org", + "lockfile_path": ".cgr.lck", + "tp_in_dir": "/usr/share/cgrates/tariffplans/testit", + "tp_out_dir": "", + }, +], + +"rals": { + "enabled": true, + "thresholds_conns": ["*internal"], + "max_increments":3000000, +}, + + +"schedulers": { + "enabled": true, + "cdrs_conns": ["*internal"], + "stats_conns": ["*localhost"], +}, + + +"cdrs": { + "enabled": true, + "chargers_conns":["*internal"], +}, + + +"attributes": { + "enabled": true, + "stats_conns": ["*localhost"], + "resources_conns": ["*localhost"], + "accounts_conns": ["*localhost"] +}, + + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + + +"resources": { + "enabled": true, + "store_interval": "1s", + "thresholds_conns": ["*internal"] +}, + + +"stats": { + "enabled": true, + "store_interval": "1s", + "thresholds_conns": ["*internal"], +}, + + +"thresholds": { + "enabled": true, + "store_interval": "1s", +}, + + +"routes": { + "enabled": true, + "prefix_indexed_fields":["*req.Destination"], + "stats_conns": ["*internal"], + "resources_conns": ["*internal"], + "rals_conns": ["*internal"], +}, + + +"sessions": { + "enabled": true, + "routes_conns": ["*internal"], + "resources_conns": ["*internal"], + "attributes_conns": ["*internal"], + "rals_conns": ["*internal"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*internal"], +}, + + +"migrator": { + "out_datadb_type": "mongo", + "out_datadb_port": "27017", + "out_datadb_name": "10", + "out_stordb_type": "mongo", + "out_stordb_port": "27017", + "out_stordb_name": "cgrates", + "users_filters":["Account"], +}, + + +"admins": { + "enabled": true, + "scheduler_conns": ["*internal"], +}, + + +"rates": { + "enabled": true +}, + + +"actions": { + "enabled": true, + "accounts_conns": ["*localhost"] +}, + + +"accounts": { + "enabled": true +}, + + +"filters": { + "stats_conns": ["*internal"], + "resources_conns": ["*internal"], + "accounts_conns": ["*internal"], +}, + + + +} diff --git a/data/conf/samples/acc_generaltest_mysql/cgrates.json b/data/conf/samples/acc_generaltest_mysql/cgrates.json new file mode 100644 index 000000000..7e0238924 --- /dev/null +++ b/data/conf/samples/acc_generaltest_mysql/cgrates.json @@ -0,0 +1,148 @@ +{ +// CGRateS Configuration file +// + + +"general": { + "log_level": 7, + "reply_timeout": "50s", +}, + + +"listen": { + "rpc_json": ":2012", + "rpc_gob": ":2013", + "http": ":2080", +}, + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "redis", // data_db type: + "db_port": 6379, // data_db port to reach the database + "db_name": "10", // data_db database name to connect to +}, + +"stor_db": { + "db_password": "CGRateS.org", +}, + +"loaders": [ + { + "id": "*default", + "enabled": true, + "tenant": "cgrates.org", + "lockfile_path": ".cgr.lck", + "tp_in_dir": "/usr/share/cgrates/tariffplans/testit", + "tp_out_dir": "", + }, +], + +"rals": { + "enabled": true, + "thresholds_conns": ["*internal"], + "max_increments":3000000, +}, + + +"schedulers": { + "enabled": true, + "cdrs_conns": ["*internal"], + "stats_conns": ["*localhost"], +}, + + +"cdrs": { + "enabled": true, + "chargers_conns":["*internal"], +}, + + +"attributes": { + "enabled": true, + "stats_conns": ["*localhost"], + "resources_conns": ["*localhost"], + "accounts_conns": ["*localhost"] +}, + + +"chargers": { + "enabled": true, + "attributes_conns": ["*internal"], +}, + + +"resources": { + "enabled": true, + "store_interval": "1s", + "thresholds_conns": ["*internal"] +}, + + +"stats": { + "enabled": true, + "store_interval": "1s", + "thresholds_conns": ["*internal"], +}, + + +"thresholds": { + "enabled": true, + "store_interval": "1s", +}, + + +"routes": { + "enabled": true, + "prefix_indexed_fields":["*req.Destination"], + "stats_conns": ["*internal"], + "resources_conns": ["*internal"], + "rals_conns": ["*internal"], +}, + + +"sessions": { + "enabled": true, + "routes_conns": ["*internal"], + "resources_conns": ["*internal"], + "attributes_conns": ["*internal"], + "rals_conns": ["*internal"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*internal"], +}, + + +"migrator":{ + "out_stordb_password": "CGRateS.org", + "users_filters":["Account"], +}, + + +"admins": { + "enabled": true, + "scheduler_conns": ["*internal"], +}, + + +"rates": { + "enabled": true +}, + + +"actions": { + "enabled": true, + "accounts_conns": ["*localhost"] +}, + + +"accounts": { + "enabled": true +}, + + +"filters": { + "stats_conns": ["*internal"], + "resources_conns": ["*internal"], + "accounts_conns": ["*internal"], +}, + + +} diff --git a/data/tariffplans/testit/DispatcherHosts.csv b/data/tariffplans/testit/DispatcherHosts.csv new file mode 100644 index 000000000..e69de29bb diff --git a/data/tariffplans/testit/DispatcherProfiles.csv b/data/tariffplans/testit/DispatcherProfiles.csv new file mode 100644 index 000000000..e69de29bb diff --git a/general_tests/accounts_it_test.go b/general_tests/accounts_it_test.go index 3067f5f5a..6ee467bc6 100644 --- a/general_tests/accounts_it_test.go +++ b/general_tests/accounts_it_test.go @@ -20,288 +20,333 @@ along with this program. If not, see */ package general_tests -// import ( -// "net/rpc" -// "path" -// "testing" -// "time" +import ( + "path" + "testing" + "time" -// "github.com/cgrates/cgrates/config" -// "github.com/cgrates/cgrates/engine" -// "github.com/cgrates/cgrates/utils" -// ) + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/loaders" + "github.com/cgrates/cgrates/utils" +) -// var ( -// accCfgPath string -// accCfg *config.CGRConfig -// accRpc *rpc.Client -// accConfDIR string //run tests for specific configuration -// account *engine.Account -// accDelay int +var ( + accCfgPath string + accCfg *config.CGRConfig + accRpc *birpc.Client + accConfDIR string //run tests for specific configuration + accDelay int -// sTestsAcc = []func(t *testing.T){ -// testV1AccLoadConfig, -// testV1AccInitDataDb, -// testAccResetStorDb, -// testV1AccStartEngine, -// testV1AccRpcConn, -// testV1AccGetAccountBeforeSet, -// testV1AccLoadTarrifPlans, -// testV1AccGetAccountAfterLoad, -// testV1AccRemAccount, -// testV1AccGetAccountAfterDelete, -// testV1AccSetAccount, -// testV1AccGetAccountAfterSet, -// testV1AccRemAccountSet, -// testV1AccGetAccountSetAfterDelete, -// //testV1AccRemAccountAfterDelete, -// testV1AccMonthly, -// testV1AccSendToThreshold, -// testV1AccStopEngine, -// } -// ) + sTestsAcc = []func(t *testing.T){ + testV1AccLoadConfig, + testV1AccInitDataDb, + testAccResetStorDb, + testV1AccStartEngine, + testV1AccRpcConn, + testV1AccGetAccountBeforeSet, + testV1AccLoadTarrifPlans, + testV1AccGetAccountAfterLoad, + testV1AccRemAccount, + testV1AccGetAccountAfterDelete, + testV1AccSetAccount, + testV1AccGetAccountAfterSet, + testV1AccRemAccountSet, + testV1AccGetAccountSetAfterDelete, + //testV1AccMonthly, + //testV1AccSendToThreshold, + testV1AccStopEngine, + } +) -// // Test start here -// func TestAccIT(t *testing.T) { -// switch *dbType { -// case utils.MetaInternal: -// accConfDIR = "tutinternal" -// case utils.MetaMySQL: -// accConfDIR = "tutmysql" -// case utils.MetaMongo: -// accConfDIR = "tutmongo" -// case utils.MetaPostgres: -// t.SkipNow() -// default: -// t.Fatal("Unknown Database type") -// } +// Test start here +func TestAccIT(t *testing.T) { + switch *dbType { + case utils.MetaInternal: + accConfDIR = "acc_generaltest_internal" + case utils.MetaMySQL: + accConfDIR = "acc_generaltest_mysql" + case utils.MetaMongo: + accConfDIR = "acc_generaltest_mongo" + case utils.MetaPostgres: + t.SkipNow() + default: + t.Fatal("Unknown Database type") + } -// for _, stest := range sTestsAcc { -// t.Run(accConfDIR, stest) -// } -// } + for _, stest := range sTestsAcc { + t.Run(accConfDIR, stest) + } +} -// func testV1AccLoadConfig(t *testing.T) { -// var err error -// accCfgPath = path.Join(*dataDir, "conf", "samples", accConfDIR) -// if accCfg, err = config.NewCGRConfigFromPath(accCfgPath); err != nil { -// t.Error(err) -// } -// accDelay = 1000 -// } +func testV1AccLoadConfig(t *testing.T) { + var err error + accCfgPath = path.Join(*dataDir, "conf", "samples", accConfDIR) + if accCfg, err = config.NewCGRConfigFromPath(context.Background(), accCfgPath); err != nil { + t.Error(err) + } + accDelay = 1000 +} -// func testV1AccInitDataDb(t *testing.T) { -// if err := engine.InitDataDB(accCfg); err != nil { -// t.Fatal(err) -// } -// } +func testV1AccInitDataDb(t *testing.T) { + if err := engine.InitDataDB(accCfg); err != nil { + t.Fatal(err) + } +} -// func testAccResetStorDb(t *testing.T) { -// if err := engine.InitStorDB(accCfg); err != nil { -// t.Fatal(err) -// } -// } +func testAccResetStorDb(t *testing.T) { + if err := engine.InitStorDB(accCfg); err != nil { + t.Fatal(err) + } +} -// func testV1AccStartEngine(t *testing.T) { -// if _, err := engine.StopStartEngine(accCfgPath, accDelay); err != nil { -// t.Fatal(err) -// } -// } +func testV1AccStartEngine(t *testing.T) { + if _, err := engine.StopStartEngine(accCfgPath, accDelay); err != nil { + t.Fatal(err) + } +} -// func testV1AccRpcConn(t *testing.T) { -// var err error -// accRpc, err = newRPCClient(accCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed -// if err != nil { -// t.Fatal("Could not connect to rater: ", err.Error()) -// } -// } +func testV1AccRpcConn(t *testing.T) { + var err error + accRpc, err = newRPCClient(accCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed + if err != nil { + t.Fatal("Could not connect to rater: ", err.Error()) + } +} -// func testV1AccGetAccountBeforeSet(t *testing.T) { -// var reply *engine.Account -// if err := accRpc.Call(utils.APIerSv2GetAccount, -// &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply); err == nil || -// err.Error() != utils.ErrNotFound.Error() { -// t.Error(err) -// } -// } +func testV1AccGetAccountBeforeSet(t *testing.T) { + var reply *utils.Account + args := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "1001", + }, + } + if err := accRpc.Call(context.Background(), utils.AdminSv1GetAccount, + args, &reply); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} -// func testV1AccLoadTarrifPlans(t *testing.T) { -// var reply string -// attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} -// if err := accRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { -// t.Error(err) -// } else if reply != utils.OK { -// t.Error("Unexpected reply returned", reply) -// } -// time.Sleep(200 * time.Millisecond) -// } +func testV1AccLoadTarrifPlans(t *testing.T) { + caching := utils.MetaReload + if accCfg.DataDbCfg().Type == utils.Internal { + caching = utils.MetaNone + } + var reply string + if err := accRpc.Call(context.Background(), utils.LoaderSv1Load, + &loaders.ArgsProcessFolder{ + StopOnError: true, + Caching: utils.StringPointer(caching), + }, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Error("Unexpected reply returned:", reply) + } + time.Sleep(200 * time.Millisecond) +} -// func testV1AccGetAccountAfterLoad(t *testing.T) { -// var reply *engine.Account -// if err := accRpc.Call(utils.APIerSv2GetAccount, -// &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, -// &reply); err != nil { -// t.Error(err) -// } -// } +func testV1AccGetAccountAfterLoad(t *testing.T) { + var reply *utils.Account + args := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "1001", + }, + } + if err := accRpc.Call(context.Background(), utils.AdminSv1GetAccount, + args, + &reply); err != nil { + t.Error(err) + } +} -// func testV1AccRemAccount(t *testing.T) { -// var reply string -// if err := accRpc.Call(utils.APIerSv1RemoveAccount, -// &utils.AttrRemoveAccount{Tenant: "cgrates.org", Account: "1001"}, -// &reply); err != nil { -// t.Error(err) -// } else if reply != utils.OK { -// t.Error("Unexpected reply returned", reply) -// } -// } +func testV1AccRemAccount(t *testing.T) { + var reply string + args := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "1001", + }, + } + if err := accRpc.Call(context.Background(), utils.AdminSv1RemoveAccount, + args, + &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Error("Unexpected reply returned", reply) + } +} -// func testV1AccGetAccountAfterDelete(t *testing.T) { -// var reply *engine.Account -// if err := accRpc.Call(utils.APIerSv2GetAccount, -// &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply); err == nil || -// err.Error() != utils.ErrNotFound.Error() { -// t.Error(err) -// } -// } +func testV1AccGetAccountAfterDelete(t *testing.T) { + args := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "1001", + }, + } + var reply *utils.Account + if err := accRpc.Call(context.Background(), utils.AdminSv1GetAccount, + args, &reply); err == nil || + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} -// func testV1AccSetAccount(t *testing.T) { -// var reply string -// if err := accRpc.Call(utils.APIerSv2SetAccount, -// &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "testacc"}, &reply); err != nil { -// t.Error(err) -// } else if reply != utils.OK { -// t.Error("Unexpected reply returned", reply) -// } -// } +func testV1AccSetAccount(t *testing.T) { + var reply string + args := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "testacc", + }, + } + if err := accRpc.Call(context.Background(), utils.AdminSv1SetAccount, + args, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Error("Unexpected reply returned", reply) + } +} -// func testV1AccGetAccountAfterSet(t *testing.T) { -// var reply *engine.Account -// if err := accRpc.Call(utils.APIerSv2GetAccount, -// &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testacc"}, &reply); err != nil { -// t.Error(err) -// } -// } +func testV1AccGetAccountAfterSet(t *testing.T) { + var reply *utils.Account + args := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "testacc", + }, + } + if err := accRpc.Call(context.Background(), utils.AdminSv1GetAccount, + args, &reply); err != nil { + t.Error(err) + } +} -// func testV1AccRemAccountSet(t *testing.T) { -// var reply string -// if err := accRpc.Call(utils.APIerSv1RemoveAccount, -// &utils.AttrRemoveAccount{Tenant: "cgrates.org", Account: "testacc"}, -// &reply); err != nil { -// t.Error(err) -// } else if reply != utils.OK { -// t.Error("Unexpected reply returned", reply) -// } -// } +func testV1AccRemAccountSet(t *testing.T) { + var reply string + args := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "testacc", + }, + } + if err := accRpc.Call(context.Background(), utils.AdminSv1RemoveAccount, + args, + &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Error("Unexpected reply returned", reply) + } +} -// func testV1AccGetAccountSetAfterDelete(t *testing.T) { -// var reply *engine.Account -// if err := accRpc.Call(utils.APIerSv2GetAccount, -// &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testacc"}, -// &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { -// t.Error(err) -// } -// } +func testV1AccGetAccountSetAfterDelete(t *testing.T) { + var reply *utils.Account + args := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "testacc", + }, + } + if err := accRpc.Call(context.Background(), utils.AdminSv1GetAccount, + args, + &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} -// /* -// Need to investigate for redis why didn't return not found -// func testV1AccRemAccountAfterDelete(t *testing.T) { -// var reply string -// if err := accRpc.Call(utils.APIerSv1RemoveAccount, -// &utils.AttrRemoveAccount{Tenant: "cgrates.org", Account: "testacc"}, -// &reply); err == nil || err.Error() != utils.NewErrServerError(utils.ErrNotFound).Error() { -// t.Error(err) -// } -// } -// */ +func testV1AccMonthly(t *testing.T) { + // add 10 seconds delay before and after + args := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "1002", + }, + } + var reply *utils.Account + if err := accRpc.Call(context.Background(), utils.AdminSv1GetAccount, + args, + &reply); err != nil { + t.Error(err) + } else if _, has := reply.Balances[utils.MetaData]; !has { + t.Error("Unexpected balance returned: ", utils.ToJSON(reply.Balances[utils.MetaData])) + } -// func testV1AccMonthly(t *testing.T) { -// // add 10 seconds delay before and after -// timeAfter := time.Now().Add(10*time.Second).AddDate(0, 1, 0) -// timeBefore := time.Now().Add(-10*time.Second).AddDate(0, 1, 0) -// var reply *engine.Account -// if err := accRpc.Call(utils.APIerSv2GetAccount, -// &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1002"}, -// &reply); err != nil { -// t.Error(err) -// } else if _, has := reply.BalanceMap[utils.MetaData]; !has { -// t.Error("Unexpected balance returned: ", utils.ToJSON(reply.BalanceMap[utils.MetaData])) -// } else if len(reply.BalanceMap[utils.MetaData]) != 1 { -// t.Error("Unexpected number of balances returned: ", len(reply.BalanceMap[utils.MetaData])) -// } else if reply.BalanceMap[utils.MetaData][0].ExpirationDate.After(timeAfter) && -// reply.BalanceMap[utils.MetaData][0].ExpirationDate.Before(timeBefore) { -// t.Error("Unexpected expiration date returned: ", reply.BalanceMap[utils.MetaData][0].ExpirationDate) -// } +} -// } +//Add test to check if AccountS send event to ThresholdS +func testV1AccSendToThreshold(t *testing.T) { + var reply string -// //Add test to check if AccountS send event to ThresholdS -// func testV1AccSendToThreshold(t *testing.T) { -// var reply string + // Add a disable and log action + args := &engine.ActionProfileWithAPIOpts{ + ActionProfile: &engine.ActionProfile{ + ID: "DISABLE_LOG", + Actions: []*engine.APAction{ + {ID: utils.MetaDisableAccount}, + {ID: utils.MetaLog}, + }, + }, + } + if err := accRpc.Call(context.Background(), utils.AdminSv1SetActionProfile, args, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + t.Error("Got error on APIerSv2.SetActions: ", err.Error()) + } else if reply != utils.OK { + t.Errorf("Calling APIerSv2.SetActions received: %s", reply) + } -// // Add a disable and log action -// attrsAA := &utils.AttrSetActions{ActionsId: "DISABLE_LOG", Actions: []*utils.TPAction{ -// {Identifier: utils.MetaDisableAccount}, -// {Identifier: utils.MetaLog}, -// }} -// if err := accRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { -// t.Error("Got error on APIerSv2.SetActions: ", err.Error()) -// } else if reply != utils.OK { -// t.Errorf("Calling APIerSv2.SetActions received: %s", reply) -// } + tPrfl := &engine.ThresholdProfileWithAPIOpts{ + ThresholdProfile: &engine.ThresholdProfile{ + Tenant: "cgrates.org", + ID: "THD_AccDisableAndLog", + FilterIDs: []string{"*string:~*opts.*eventType:AccountUpdate", + "*string:~*asm.ID:testAccThreshold"}, + MaxHits: -1, + MinSleep: time.Second, + Weight: 20.0, + Async: true, + ActionProfileIDs: []string{"DISABLE_LOG"}, + }, + } -// tPrfl := &engine.ThresholdProfileWithAPIOpts{ -// ThresholdProfile: &engine.ThresholdProfile{ -// Tenant: "cgrates.org", -// ID: "THD_AccDisableAndLog", -// FilterIDs: []string{"*string:~*opts.*eventType:AccountUpdate", -// "*string:~*asm.ID:testAccThreshold"}, -// MaxHits: -1, -// MinSleep: time.Second, -// Weight: 20.0, -// Async: true, -// ActionProfileIDs: []string{"DISABLE_LOG"}, -// }, -// } + if err := accRpc.Call(context.Background(), utils.AdminSv1SetThresholdProfile, tPrfl, &reply); err != nil { + t.Error(err) + } else if reply != utils.OK { + t.Error("Unexpected reply returned", reply) + } + // Add an account + attrs := &utils.ArgsActSetBalance{ + Tenant: "cgrates.org", + AccountID: "testAccThreshold", + Diktats: []*utils.BalDiktat{ + { + Path: "*balance.testAccSetBalance.*monetary", + Value: "1.5", + }, + }, + } + if err := accRpc.Call(context.Background(), utils.AccountSv1ActionSetBalance, attrs, &reply); err != nil { + t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) + } else if reply != utils.OK { + t.Errorf("Calling APIerSv1.SetBalance received: %s", reply) + } + time.Sleep(10 * time.Millisecond) + var acnt utils.Account + attrAcc := &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + Tenant: "cgrates.org", + ID: "testAccThreshold", + }, + } + if err := accRpc.Call(context.Background(), utils.AdminSv1GetAccount, attrAcc, &acnt); err != nil { + t.Error(err) + } +} -// if err := accRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { -// t.Error(err) -// } else if reply != utils.OK { -// t.Error("Unexpected reply returned", reply) -// } -// // Add an account -// attrs := &utils.AttrSetBalance{ -// Tenant: "cgrates.org", -// Account: "testAccThreshold", -// BalanceType: "*monetary", -// Value: 1.5, -// Balance: map[string]interface{}{ -// utils.ID: "testAccSetBalance", -// }, -// } -// if err := accRpc.Call(utils.APIerSv1SetBalance, attrs, &reply); err != nil { -// t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) -// } else if reply != utils.OK { -// t.Errorf("Calling APIerSv1.SetBalance received: %s", reply) -// } - -// // give time to threshold to made the change -// time.Sleep(10 * time.Millisecond) -// //verify the account -// var acnt *engine.Account -// attrAcc := &utils.AttrGetAccount{ -// Tenant: "cgrates.org", -// Account: "testAccThreshold", -// } -// if err := accRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { -// t.Error(err) -// } else if acnt.Disabled != true { -// t.Errorf("Expecting: true, received: %v", acnt.Disabled) -// } -// } - -// func testV1AccStopEngine(t *testing.T) { -// if err := engine.KillEngine(accDelay); err != nil { -// t.Error(err) -// } -// } +func testV1AccStopEngine(t *testing.T) { + if err := engine.KillEngine(accDelay); err != nil { + t.Error(err) + } +}