From caaea0d7aea34551277da0f9937a26f51ec87a84 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Sun, 18 Dec 2022 23:43:07 +0200 Subject: [PATCH] add integration test --- dump.rdb | Bin 88 -> 0 bytes test/integration_test.sh | 78 +++++++++++++++++++++++++++++++++++++++ test/main.go | 22 +++++++++++ 3 files changed, 100 insertions(+) delete mode 100644 dump.rdb create mode 100755 test/integration_test.sh create mode 100644 test/main.go diff --git a/dump.rdb b/dump.rdb deleted file mode 100644 index 861732cf51915fb2305b55e9410090cd09a3ec8e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 88 zcmWG?b@2=~FfcUu#aWb^l3A=> /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) + } +}