diff --git a/dump.rdb b/dump.rdb deleted file mode 100644 index 861732c..0000000 Binary files a/dump.rdb and /dev/null differ diff --git a/test/integration_test.sh b/test/integration_test.sh new file mode 100755 index 0000000..36984f1 --- /dev/null +++ b/test/integration_test.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +TestRestartAfterTermination() { + ./foreman >> /dev/null & + sleep 0.2 + + pid=$(ps | grep "sleep" | awk '{print $1}') + [[ ! -z $pid ]] && kill -SIGINT $pid + sleep 0.2 + + restartPid=$(ps | grep "sleep" | awk '{print $1}') + if [[ -z $restartPid ]]; then + echo "TestRestartAfterTermination: TEST FAILED" + Clean + rm ./foreman + exit 1 + else + echo "TestRestartAfterTermination: TEST PASSED" + fi + + Clean +} + +TestTerminateRunOnceService() { + ./foreman >> /dev/null & + sleep 0.2 + + pid=$(ps | grep "redis-server" | awk '{print $1}') + [[ ! -z $pid ]] && kill -SIGINT $pid + sleep 0.2 + + restartPid=$(ps | grep "redis-server" | awk '{print $1}') + if [[ -z $restartPid ]]; then + echo "TestTerminateRunOnceService: TEST PASSED" + else + echo "TestTerminateRunOnceService: TEST FAILED" + Clean + exit 1 + fi + + Clean +} + +TestTerminationOnBrockenDependency() { + ./foreman >> /dev/null & + sleep 0.2 + + pid=$(ps | grep "redis-server" | awk '{print $1}') + [[ ! -z $pid ]] && kill -SIGINT $pid + sleep 0.2 + + pingPid=$(ps | grep "ping" | awk '{print $1}') + if [[ -z $sleepPid ]]; then + echo "TestTerminationOnBrockenDependency: TEST PASSED" + else + echo "TestTerminationOnBrockenDependency: TEST FAILED" + Clean + exit 1 + fi + + Clean +} + +Clean() { + foreman=$(ps | grep "foreman" | awk '{print $1}') + kill -SIGINT $foreman +} + +go build -o foreman main.go +TestRestartAfterTermination +TestTerminateRunOnceService +TestTerminationOnBrockenDependency + +rm ./foreman +rm dump.rdb + +echo "status ok: TEST PASSED" +exit 0 diff --git a/test/main.go b/test/main.go new file mode 100644 index 0000000..315a8ce --- /dev/null +++ b/test/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "os" + + "github.com/Eslam-Nawara/foreman" +) + +func main() { + foreman, err := foreman.New("../test-procfiles/Procfile", false) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + err = foreman.Start() + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +}