mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 00:58:45 +05:00
More local tests for tutorials
This commit is contained in:
@@ -76,9 +76,6 @@ func TestCreateDirs(t *testing.T) {
|
||||
if err := os.RemoveAll(pathDir); err != nil {
|
||||
t.Fatal("Error removing folder: ", pathDir, err)
|
||||
}
|
||||
if err := os.MkdirAll(pathDir, 0755); err != nil {
|
||||
t.Fatal("Error creating folder: ", pathDir, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ func init() {
|
||||
fscsvCfg, _ = config.NewCGRConfig(&fscsvCfgPath)
|
||||
}
|
||||
|
||||
func TestFsCsvCreateDirs(t *testing.T) {
|
||||
// Remove here so they can be properly created by init script
|
||||
func TestFsCsvRemoveDirs(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
@@ -49,9 +50,6 @@ func TestFsCsvCreateDirs(t *testing.T) {
|
||||
if err := os.RemoveAll(pathDir); err != nil {
|
||||
t.Fatal("Error removing folder: ", pathDir, err)
|
||||
}
|
||||
if err := os.MkdirAll(pathDir, 0755); err != nil {
|
||||
t.Fatal("Error creating folder: ", pathDir, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,18 +100,27 @@ func TestFsCsvInitDataDb(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFsCsvStartFs(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
exec.Command("pkill", "freeswitch").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it
|
||||
go func() {
|
||||
fs := exec.Command("/usr/share/cgrates/tutorials/fs_csv/freeswitch/etc/init.d/freeswitch", "start")
|
||||
out, _ := fs.CombinedOutput()
|
||||
engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsCsv: %s", out))
|
||||
}()
|
||||
time.Sleep(time.Duration(*waitFs) * time.Millisecond) // Give time to rater to fire up
|
||||
}
|
||||
|
||||
// Finds cgr-engine executable and starts it with default configuration
|
||||
func TestFsCsvStartEngine(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
enginePath, err := exec.LookPath("cgr-engine")
|
||||
if err != nil {
|
||||
t.Fatal("Cannot find cgr-engine executable")
|
||||
}
|
||||
exec.Command("pkill", "cgr-engine").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it
|
||||
go func() {
|
||||
eng := exec.Command(enginePath, "-config", fscsvCfgPath)
|
||||
eng := exec.Command("/usr/share/cgrates/tutorials/fs_json/cgrates/etc/init.d/cgrates", "start")
|
||||
out, _ := eng.CombinedOutput()
|
||||
engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsCsv: %s", out))
|
||||
}()
|
||||
@@ -267,5 +274,20 @@ func TestFsCsvStopEngine(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
exec.Command("pkill", "cgr-engine").Run()
|
||||
go func() {
|
||||
eng := exec.Command("/usr/share/cgrates/tutorials/fs_csv/cgrates/etc/init.d/cgrates", "stop")
|
||||
out, _ := eng.CombinedOutput()
|
||||
engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsCsv: %s", out))
|
||||
}()
|
||||
}
|
||||
|
||||
func TestFsCsvStopFs(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
fs := exec.Command("/usr/share/cgrates/tutorials/fs_csv/freeswitch/etc/init.d/freeswitch", "stop")
|
||||
out, _ := fs.CombinedOutput()
|
||||
engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsCsv: %s", out))
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package apier
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/rpc/jsonrpc"
|
||||
"os"
|
||||
@@ -36,22 +37,22 @@ import (
|
||||
var fsjsonCfgPath string
|
||||
var fsjsonCfg *config.CGRConfig
|
||||
|
||||
var waitFs = flag.Int("wait_fs", 1000, "Number of miliseconds to wait for FreeSWITCH to start")
|
||||
|
||||
func init() {
|
||||
fsjsonCfgPath = path.Join(*dataDir, "tutorials", "fs_json", "cgrates", "etc", "cgrates", "cgrates.cfg")
|
||||
fsjsonCfg, _ = config.NewCGRConfig(&fsjsonCfgPath)
|
||||
}
|
||||
|
||||
func TestFsJsonCreateDirs(t *testing.T) {
|
||||
// Remove here so they can be properly created by init script
|
||||
func TestFsJsonRemoveDirs(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
for _, pathDir := range []string{cfg.CdreDir, cfg.HistoryDir} {
|
||||
for _, pathDir := range []string{fsjsonCfg.CdreDir, fsjsonCfg.HistoryDir} {
|
||||
if err := os.RemoveAll(pathDir); err != nil {
|
||||
t.Fatal("Error removing folder: ", pathDir, err)
|
||||
}
|
||||
if err := os.MkdirAll(pathDir, 0755); err != nil {
|
||||
t.Fatal("Error creating folder: ", pathDir, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,18 +103,27 @@ func TestFsJsonInitDataDb(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFsJsonStartFs(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
exec.Command("pkill", "freeswitch").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it
|
||||
go func() {
|
||||
fs := exec.Command("/usr/share/cgrates/tutorials/fs_json/freeswitch/etc/init.d/freeswitch", "start")
|
||||
out, _ := fs.CombinedOutput()
|
||||
engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsJson: %s", out))
|
||||
}()
|
||||
time.Sleep(time.Duration(*waitFs) * time.Millisecond) // Give time to rater to fire up
|
||||
}
|
||||
|
||||
// Finds cgr-engine executable and starts it with default configuration
|
||||
func TestFsJsonStartEngine(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
enginePath, err := exec.LookPath("cgr-engine")
|
||||
if err != nil {
|
||||
t.Fatal("Cannot find cgr-engine executable")
|
||||
}
|
||||
exec.Command("pkill", "cgr-engine").Run() // Just to make sure another one is not running, bit brutal maybe we can fine tune it
|
||||
go func() {
|
||||
eng := exec.Command(enginePath, "-config", fsjsonCfgPath)
|
||||
eng := exec.Command("/usr/share/cgrates/tutorials/fs_json/cgrates/etc/init.d/cgrates", "start")
|
||||
out, _ := eng.CombinedOutput()
|
||||
engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsJson: %s", out))
|
||||
}()
|
||||
@@ -196,5 +206,20 @@ func TestFsJsonStopEngine(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
exec.Command("pkill", "cgr-engine").Run()
|
||||
go func() {
|
||||
eng := exec.Command("/usr/share/cgrates/tutorials/fs_json/cgrates/etc/init.d/cgrates", "stop")
|
||||
out, _ := eng.CombinedOutput()
|
||||
engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsJson: %s", out))
|
||||
}()
|
||||
}
|
||||
|
||||
func TestFsJsonStopFs(t *testing.T) {
|
||||
if !*testLocal {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
fs := exec.Command("/usr/share/cgrates/tutorials/fs_json/freeswitch/etc/init.d/freeswitch", "stop")
|
||||
out, _ := fs.CombinedOutput()
|
||||
engine.Logger.Info(fmt.Sprintf("CgrEngine-TestFsJson: %s", out))
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -14,18 +14,24 @@
|
||||
# Do NOT "set -e"
|
||||
|
||||
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
||||
RUNDIR=/tmp/$NAME/run
|
||||
PIDFILE=$RUNDIR/cgr-engine.pid
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="CGRateS real-time charging system"
|
||||
NAME=cgrates
|
||||
DAEMON=/usr/bin/cgr-engine
|
||||
USER=cgrates
|
||||
GROUP=cgrates
|
||||
TUTFOLDER=/usr/share/cgrates/tutorials/fs_csv/cgrates
|
||||
TUTFOLDER=/usr/share/cgrates/tutorials/fs_json/cgrates
|
||||
ENGINE_OPTS=-config=$TUTFOLDER/etc/cgrates/cgrates.cfg
|
||||
PIDFILE=/tmp/cgr-engine_tutfscsv.pid
|
||||
PIDFILE=/tmp/cgr-engine_tutfsjson.pid
|
||||
SCRIPTNAME=$TUTFOLDER/etc/init.d/$NAME
|
||||
DEFAULTS=$TUTFOLDER/etc/default/$NAME
|
||||
ENABLE=false
|
||||
HISTDIR=/tmp/$NAME/history
|
||||
CDREDIR=/tmp/$NAME/cdre
|
||||
CDRCINDIR=/tmp/$NAME/cdr/cdrc/in
|
||||
CDRCOUTDIR=/tmp/cgrates/cdr/cdrc/out
|
||||
|
||||
# Exit if the package is not installed
|
||||
[ -x "$DAEMON" ] || exit 0
|
||||
@@ -46,6 +52,30 @@ if [ "$ENABLE" != "true" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Install the run folder
|
||||
if [ ! -d $RUNDIR ]; then
|
||||
mkdir -p $RUNDIR
|
||||
chown $USER:$GROUP $RUNDIR
|
||||
fi
|
||||
# Install the cdre folder
|
||||
if [ ! -d $CDREDIR ]; then
|
||||
mkdir -p $CDREDIR
|
||||
chown $USER:$GROUP $CDREDIR
|
||||
fi
|
||||
# Install the history folder
|
||||
if [ ! -d $HISTDIR ]; then
|
||||
mkdir -p $HISTDIR
|
||||
chown $USER:$GROUP $HISTDIR
|
||||
fi
|
||||
if [ ! -d $CDRCINDIR ]; then
|
||||
mkdir -p $CDRCINDIR
|
||||
chown $USER:$GROUP $CDRCINDIR
|
||||
fi
|
||||
if [ ! -d $CDRCOUTDIR ]; then
|
||||
mkdir -p $CDRCOUTDIR
|
||||
chown $USER:$GROUP $CDRCOUTDIR
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Function that starts the daemon/service
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
# Do NOT "set -e"
|
||||
|
||||
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
||||
RUNDIR=/tmp/$NAME/run
|
||||
PIDFILE=$RUNDIR/cgr-engine.pid
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="CGRateS real-time charging system"
|
||||
NAME=cgrates
|
||||
@@ -26,6 +28,8 @@ PIDFILE=/tmp/cgr-engine_tutfsjson.pid
|
||||
SCRIPTNAME=$TUTFOLDER/etc/init.d/$NAME
|
||||
DEFAULTS=$TUTFOLDER/etc/default/$NAME
|
||||
ENABLE=false
|
||||
HISTDIR=/tmp/$NAME/history
|
||||
CDREDIR=/tmp/$NAME/cdre
|
||||
|
||||
# Exit if the package is not installed
|
||||
[ -x "$DAEMON" ] || exit 0
|
||||
@@ -46,6 +50,22 @@ if [ "$ENABLE" != "true" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Install the run folder
|
||||
if [ ! -d $RUNDIR ]; then
|
||||
mkdir -p $RUNDIR
|
||||
chown $USER:$GROUP $RUNDIR
|
||||
fi
|
||||
# Install the cdre folder
|
||||
if [ ! -d $CDREDIR ]; then
|
||||
mkdir -p $CDREDIR
|
||||
chown $USER:$GROUP $CDREDIR
|
||||
fi
|
||||
# Install the history folder
|
||||
if [ ! -d $HISTDIR ]; then
|
||||
mkdir -p $HISTDIR
|
||||
chown $USER:$GROUP $HISTDIR
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Function that starts the daemon/service
|
||||
|
||||
Reference in New Issue
Block a user