mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 18:46:24 +05:00
Repaired tests in general
This commit is contained in:
committed by
Dan Christian Bogos
parent
9830c61424
commit
09358dbc3e
140
data/conf/samples/acc_generaltest_internal/cgrates.json
Normal file
140
data/conf/samples/acc_generaltest_internal/cgrates.json
Normal file
@@ -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"],
|
||||
},
|
||||
|
||||
}
|
||||
157
data/conf/samples/acc_generaltest_mongo/cgrates.json
Normal file
157
data/conf/samples/acc_generaltest_mongo/cgrates.json
Normal file
@@ -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"],
|
||||
},
|
||||
|
||||
|
||||
|
||||
}
|
||||
148
data/conf/samples/acc_generaltest_mysql/cgrates.json
Normal file
148
data/conf/samples/acc_generaltest_mysql/cgrates.json
Normal file
@@ -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: <redis|mongo>
|
||||
"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"],
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
0
data/tariffplans/testit/DispatcherHosts.csv
Normal file
0
data/tariffplans/testit/DispatcherHosts.csv
Normal file
|
|
0
data/tariffplans/testit/DispatcherProfiles.csv
Normal file
0
data/tariffplans/testit/DispatcherProfiles.csv
Normal file
|
|
@@ -20,288 +20,333 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user