mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Initial apierv2/tp_it_test file
This commit is contained in:
100
apier/v2/tp_it_test.go
Normal file
100
apier/v2/tp_it_test.go
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Real-time Charging System for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can Storagetribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITH*out ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var testIT = flag.Bool("integration", false, "Perform the tests in integration mode, not by default.")
|
||||
var storDBType = flag.String("stordb_type", utils.MYSQL, "Perform the tests for MongoDB, not by default.")
|
||||
|
||||
var tpCfgPath string
|
||||
var tpCfg *config.CGRConfig
|
||||
var tpRPC *rpc.Client
|
||||
|
||||
func TestTPitLoadConfig(t *testing.T) {
|
||||
if !*testIT {
|
||||
return
|
||||
}
|
||||
var err error
|
||||
switch *storDBType {
|
||||
case utils.MYSQL:
|
||||
tpCfgPath = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
case utils.POSTGRES:
|
||||
tpCfgPath = path.Join(*dataDir, "conf", "samples", "tutpostgres")
|
||||
case utils.MONGO:
|
||||
tpCfgPath = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
default:
|
||||
t.Fatalf("Unsupported stordb_type: %s", *storDBType)
|
||||
}
|
||||
if tpCfg, err = config.NewCGRConfigFromFolder(tpCfgPath); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove data in both rating and accounting db
|
||||
func TestTPitResetDataDb(t *testing.T) {
|
||||
if !*testIT {
|
||||
return
|
||||
}
|
||||
if err := engine.InitDataDb(tpCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func TestTPitResetStorDb(t *testing.T) {
|
||||
if !*testIT {
|
||||
return
|
||||
}
|
||||
if err := engine.InitStorDb(tpCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func TestTPitStartEngine(t *testing.T) {
|
||||
if !*testIT {
|
||||
return
|
||||
}
|
||||
if _, err := engine.StopStartEngine(tpCfgPath, *waitRater); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func TestTPitRpcConn(t *testing.T) {
|
||||
if !*testIT {
|
||||
return
|
||||
}
|
||||
var err error
|
||||
tpRPC, err = jsonrpc.Dial("tcp", tpCfg.RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
71
data/conf/samples/tutmongo/cgrates.json
Normal file
71
data/conf/samples/tutmongo/cgrates.json
Normal file
@@ -0,0 +1,71 @@
|
||||
{
|
||||
// CGRateS Configuration file
|
||||
//
|
||||
// Used for cgradmin
|
||||
// Starts rater, scheduler
|
||||
|
||||
"listen": {
|
||||
"rpc_json": ":2012", // RPC JSON listening address
|
||||
"rpc_gob": ":2013", // RPC GOB listening address
|
||||
"http": ":2080", // HTTP listening address
|
||||
},
|
||||
|
||||
"tariffplan_db": { // database used to store active tariff plan configuration
|
||||
"db_type": "mongo", // stor database type to use: <mysql|postgres>
|
||||
"db_port": 27017, // the port to reach the stordb
|
||||
"db_name": "tpdb",
|
||||
},
|
||||
|
||||
|
||||
"data_db": { // database used to store runtime data (eg: accounts, cdr stats)
|
||||
"db_type": "mongo", // stor database type to use: <mysql|postgres>
|
||||
"db_port": 27017, // the port to reach the stordb
|
||||
"db_name": "datadb",
|
||||
},
|
||||
|
||||
"stor_db": {
|
||||
"db_type": "mongo", // stor database type to use: <mysql|postgres>
|
||||
"db_port": 27017, // the port to reach the stordb
|
||||
"db_name": "stordb",
|
||||
},
|
||||
|
||||
|
||||
"rals": {
|
||||
"enabled": true, // enable Rater service: <true|false>
|
||||
"cdrstats_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
"pubsubs_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
"users_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
},
|
||||
|
||||
"scheduler": {
|
||||
"enabled": true, // start Scheduler service: <true|false>
|
||||
},
|
||||
|
||||
"cdrs": {
|
||||
"enabled": true, // start the CDR Server service: <true|false>
|
||||
"cdrstats_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
},
|
||||
|
||||
"cdrstats": {
|
||||
"enabled": true, // starts the cdrstats service: <true|false>
|
||||
},
|
||||
|
||||
"pubsubs": {
|
||||
"enabled": true, // starts PubSub service: <true|false>.
|
||||
},
|
||||
|
||||
|
||||
"users": {
|
||||
"enabled": true, // starts User service: <true|false>.
|
||||
"indexes": ["Uuid"], // user profile field indexes
|
||||
},
|
||||
|
||||
}
|
||||
56
data/conf/samples/tutpostgres/cgrates.json
Normal file
56
data/conf/samples/tutpostgres/cgrates.json
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
// CGRateS Configuration file
|
||||
//
|
||||
// Used for cgradmin
|
||||
// Starts rater, scheduler
|
||||
|
||||
"listen": {
|
||||
"rpc_json": ":2012", // RPC JSON listening address
|
||||
"rpc_gob": ":2013", // RPC GOB listening address
|
||||
"http": ":2080", // HTTP listening address
|
||||
},
|
||||
|
||||
"stor_db": {
|
||||
"db_type": "postgres", // stor database type to use: <mysql|postgres>
|
||||
"db_port": 5432, // the port to reach the stordb
|
||||
},
|
||||
|
||||
"rals": {
|
||||
"enabled": true, // enable Rater service: <true|false>
|
||||
"cdrstats_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
"pubsubs_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
"users_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
},
|
||||
|
||||
"scheduler": {
|
||||
"enabled": true, // start Scheduler service: <true|false>
|
||||
},
|
||||
|
||||
"cdrs": {
|
||||
"enabled": true, // start the CDR Server service: <true|false>
|
||||
"cdrstats_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
},
|
||||
|
||||
"cdrstats": {
|
||||
"enabled": true, // starts the cdrstats service: <true|false>
|
||||
},
|
||||
|
||||
"pubsubs": {
|
||||
"enabled": true, // starts PubSub service: <true|false>.
|
||||
},
|
||||
|
||||
|
||||
"users": {
|
||||
"enabled": true, // starts User service: <true|false>.
|
||||
"indexes": ["Uuid"], // user profile field indexes
|
||||
},
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ func TestDestManagInitCfg(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
destCfgPath = path.Join(*dataDir, "conf", "samples", "tutlocal")
|
||||
destCfgPath = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
// Init config first
|
||||
var err error
|
||||
destCfg, err = config.NewCGRConfigFromFolder(destCfgPath)
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestTpInitCfg(t *testing.T) {
|
||||
if !*testIntegration {
|
||||
return
|
||||
}
|
||||
tpCfgPath = path.Join(*dataDir, "conf", "samples", "tutlocal")
|
||||
tpCfgPath = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
// Init config first
|
||||
var err error
|
||||
tpCfg, err = config.NewCGRConfigFromFolder(tpCfgPath)
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestTutLocalInitCfg(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
tutLocalCfgPath = path.Join(*dataDir, "conf", "samples", "tutlocal")
|
||||
tutLocalCfgPath = path.Join(*dataDir, "conf", "samples", "tutmysql")
|
||||
// Init config first
|
||||
var err error
|
||||
tutFsLocalCfg, err = config.NewCGRConfigFromFolder(tutLocalCfgPath)
|
||||
|
||||
Reference in New Issue
Block a user