pm2/test/bash/cli2.sh
2015-11-24 15:18:18 +01:00

108 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
SRC=$(cd $(dirname "$0"); pwd)
source "${SRC}/include.sh"
cd $file_path
############# TEST
echo -e "\033[1mRunning tests:\033[0m"
$pm2 kill
spec "kill daemon"
echo "---- Start an app, stop it, if state stopped and started, restart stopped app"
$pm2 start echo.js
spec "Should start an app by script.js"
$pm2 stop echo.js
spec "Should stop an app by script.js"
$pm2 restart echo.js
spec "Should restart an app by script.js (TRANSITIONAL STATE)"
###############
$pm2 delete all
echo "Start application with filename starting with a numeric"
$pm2 start 001-test.js
should 'should app be online' 'online' 1
$pm2 stop 001-test
should 'should app be stopped' 'stopped' 1
$pm2 restart 001-test
should 'should app be online once restart called' 'online' 1
$pm2 delete all
###############
echo "Start application with filename starting with a numeric"
$pm2 start throw-string.js -l err-string.log --merge-logs --no-automation
>err-string.log
sleep 2
grep 'throw-string.js' err-string.log
spec "Should have written raw stack when throwing a string"
$pm2 delete all
####
$pm2 start echo.js --name gege
should 'should app be online' 'online' 1
$pm2 stop gege
should 'should app be stopped' 'stopped' 1
$pm2 restart gege
should 'should app be online once restart called' 'online' 1
###############
$pm2 delete all
echo "---- BY_NAME Start an app, stop it, if state stopped and started, restart stopped app"
$pm2 start echo.js --name gege
should 'should app be online' 'online' 1
$pm2 stop gege
should 'should app be stopped' 'stopped' 1
$pm2 restart gege
should 'should app be online once restart called' 'online' 1
###############
$pm2 delete all
echo "Start an app, start it one more time, if started, throw message"
$pm2 start echo.js
$pm2 start echo.js
ispec "Should not re start app"
########### DELETED STUFF BY ID
$pm2 kill
$pm2 start echo.js
$pm2 delete 0
should 'should has been deleted process by id' "name: 'echo'" 0
########### DELETED STUFF BY NAME
$pm2 delete all
$pm2 start echo.js --name test
$pm2 delete test
should 'should has been deleted process by name' "name: 'test'" 0
########### DELETED STUFF BY SCRIPT
$pm2 delete all
$pm2 start echo.js
$pm2 delete echo.js
$pm2 list
should 'should has been deleted process by script' "name: 'echo'" 0
########### OPTIONS OUTPUT FILES
$pm2 kill
$pm2 start echo.js -o outech.log -e errech.log --name gmail -i 10
sleep 1
cat outech-0.log > /dev/null
spec "file outech-0.log exist"
cat errech-0.log > /dev/null
spec "file errech-0.log exist"