From 0229e47bb079d07e721f8754ba0d2f71575842de Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 9 Jun 2016 20:57:44 +0200 Subject: [PATCH] Initial apierv2/tp_it_test file --- apier/v2/tp_it_test.go | 100 ++++++++++++++++++ data/conf/samples/tutmongo/cgrates.json | 71 +++++++++++++ .../{tutlocal => tutmysql}/cgrates.json | 0 data/conf/samples/tutpostgres/cgrates.json | 56 ++++++++++ general_tests/dest_management_it_test.go | 2 +- general_tests/tp_it_test.go | 2 +- general_tests/tutorial_local_test.go | 2 +- 7 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 apier/v2/tp_it_test.go create mode 100644 data/conf/samples/tutmongo/cgrates.json rename data/conf/samples/{tutlocal => tutmysql}/cgrates.json (100%) create mode 100644 data/conf/samples/tutpostgres/cgrates.json diff --git a/apier/v2/tp_it_test.go b/apier/v2/tp_it_test.go new file mode 100644 index 000000000..805e56c79 --- /dev/null +++ b/apier/v2/tp_it_test.go @@ -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 +*/ + +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) + } +} diff --git a/data/conf/samples/tutmongo/cgrates.json b/data/conf/samples/tutmongo/cgrates.json new file mode 100644 index 000000000..0e50d9c17 --- /dev/null +++ b/data/conf/samples/tutmongo/cgrates.json @@ -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: + "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: + "db_port": 27017, // the port to reach the stordb + "db_name": "datadb", +}, + +"stor_db": { + "db_type": "mongo", // stor database type to use: + "db_port": 27017, // the port to reach the stordb + "db_name": "stordb", +}, + + +"rals": { + "enabled": true, // enable Rater service: + "cdrstats_conns": [ + {"address": "*internal"} + ], + "pubsubs_conns": [ + {"address": "*internal"} + ], + "users_conns": [ + {"address": "*internal"} + ], +}, + +"scheduler": { + "enabled": true, // start Scheduler service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: + "cdrstats_conns": [ + {"address": "*internal"} + ], +}, + +"cdrstats": { + "enabled": true, // starts the cdrstats service: +}, + +"pubsubs": { + "enabled": true, // starts PubSub service: . +}, + + +"users": { + "enabled": true, // starts User service: . + "indexes": ["Uuid"], // user profile field indexes +}, + +} diff --git a/data/conf/samples/tutlocal/cgrates.json b/data/conf/samples/tutmysql/cgrates.json similarity index 100% rename from data/conf/samples/tutlocal/cgrates.json rename to data/conf/samples/tutmysql/cgrates.json diff --git a/data/conf/samples/tutpostgres/cgrates.json b/data/conf/samples/tutpostgres/cgrates.json new file mode 100644 index 000000000..7f60b4b5d --- /dev/null +++ b/data/conf/samples/tutpostgres/cgrates.json @@ -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: + "db_port": 5432, // the port to reach the stordb +}, + +"rals": { + "enabled": true, // enable Rater service: + "cdrstats_conns": [ + {"address": "*internal"} + ], + "pubsubs_conns": [ + {"address": "*internal"} + ], + "users_conns": [ + {"address": "*internal"} + ], +}, + +"scheduler": { + "enabled": true, // start Scheduler service: +}, + +"cdrs": { + "enabled": true, // start the CDR Server service: + "cdrstats_conns": [ + {"address": "*internal"} + ], +}, + +"cdrstats": { + "enabled": true, // starts the cdrstats service: +}, + +"pubsubs": { + "enabled": true, // starts PubSub service: . +}, + + +"users": { + "enabled": true, // starts User service: . + "indexes": ["Uuid"], // user profile field indexes +}, + +} diff --git a/general_tests/dest_management_it_test.go b/general_tests/dest_management_it_test.go index c895241a7..eb364f9c4 100644 --- a/general_tests/dest_management_it_test.go +++ b/general_tests/dest_management_it_test.go @@ -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) diff --git a/general_tests/tp_it_test.go b/general_tests/tp_it_test.go index 03bd8c9d8..3e44567e9 100644 --- a/general_tests/tp_it_test.go +++ b/general_tests/tp_it_test.go @@ -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) diff --git a/general_tests/tutorial_local_test.go b/general_tests/tutorial_local_test.go index d57ce2fdd..0f04f18e5 100644 --- a/general_tests/tutorial_local_test.go +++ b/general_tests/tutorial_local_test.go @@ -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)