Initial apierv2/tp_it_test file

This commit is contained in:
DanB
2016-06-09 20:57:44 +02:00
parent db52989256
commit 0229e47bb0
7 changed files with 230 additions and 3 deletions

100
apier/v2/tp_it_test.go Normal file
View 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)
}
}

View 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
},
}

View 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
},
}

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)