diff --git a/forgecheck/test_tests.sh b/forgecheck/test_tests.sh index 45cc706..660b382 100755 --- a/forgecheck/test_tests.sh +++ b/forgecheck/test_tests.sh @@ -27,7 +27,7 @@ function testVariousScenarios() { cd forgecheck testOrError "bin/test.sh from specs/forgecheck folder" ../../bin/test.sh testOrError "forgecheck/test.sh from specs/forgecheck folder with implicit ../../bin/cli" ./test.sh - testOrError "forgecheck/test.sh from specs/forgecheck folder with explicit result from ../../bin.cli" ./test.sh "$(../../bin/cli)" + testOrError "forgecheck/test.sh from specs/forgecheck folder with explicit result from ../../bin/cli" ./test.sh "$(../../bin/cli)" cd tests testOrError "bin/test.sh from specs/forgecheck/tests" ../../../bin/test.sh testOrError "forgecheck/test.sh from specs/forgecheck/tests" ../test.sh diff --git a/forgehook/test.sh b/forgehook/test.sh index 74289e0..04fd634 100755 --- a/forgehook/test.sh +++ b/forgehook/test.sh @@ -4,14 +4,14 @@ SCRIPTDIR="$(dirname "$0")" ORIGDIR="$(pwd)" cd "$SCRIPTDIR" -source tests/helper.bash -export FORGEHOOK="$(pwd)/tests/mock-forgehook.sh" +source ../shared/helper.bash +export FORGEHOOK="$(pwd)/../shared/mock-forgehook.sh" # TODO: FORGEHOOKNOTIFY is currently unused export FORGEHOOKNOTIFY=/bin/true if [ -z "$1" ]; then - output="$(findBin "$ORIGDIR"/bin/server ../bin/server)" + output="$(findBin "$ORIGDIR"/bin/server ../bin/server ../../bin/server)" if [ $? -eq 0 ]; then if [[ "$(echo "$output" | wc -l)" == "1" ]]; then export FIND_SERVER="$output" @@ -43,7 +43,8 @@ if [ -z "$2" ]; then # Or try build script from ../whck folder (called from this submodule) output="$(findBin \ whck/bin/cli \ - ../whck/bin/cli + ../whck/bin/cli \ + ../../whck/bin/cli )" if [ $? -eq 0 ]; then if [[ "$(echo "$output" | wc -l)" == "1" ]]; then @@ -72,7 +73,7 @@ else fi -bats tests/web/*.bats +bats tests/*.bats status=$? cd "$ORIGDIR" diff --git a/forgehook/test_tests.sh b/forgehook/test_tests.sh index b676e86..6f1e7ab 100755 --- a/forgehook/test_tests.sh +++ b/forgehook/test_tests.sh @@ -2,18 +2,36 @@ # If you give first argument it will be a path to already cloned endpoint +function testOrError() { + message="$1" + shift + bin="$1" + shift + output="$("$bin" "$@" 2>&1)" + if [ ! $? -eq 0 ]; then + echo "FAILURE: "$message"" + echo "$output" | sed 's/^/ /g' + return 1 + fi + echo "SUCCESS: "$message"" +} + # TODO: save exit codes of various tests so we can know how many failed function testVariousScenarios() { echo "Running various tests from "$(pwd)"" - ./bin/test.sh || echo "ERROR running from repo" - cd spec - ./test_web.sh || echo "ERROR test_web.sh failed with implicit ../bin/server" - ./test_web.sh "$(../bin/server)" || echo "ERROR test_cli with explicit result from ../bin/server" - ../bin/test.sh || echo "ERROR bin/test.sh failed called from spec submodule" + testOrError "bin/test.sh running from repo" bin/test.sh + cd specs + testOrError "forgehook/test.sh with implicit ../bin/server" forgehook/test.sh + testOrError "forgehook/test.sh with explicit result from ../bin/server" forgehook/test.sh "$(../bin/server)" + testOrError "test.sh called from specs submodule" ../bin/test.sh + cd forgehook + testOrError "bin/test.sh from specs/forgehook folder" ../../bin/test.sh + testOrError "forgehook/test.sh from specs/forgehook folder with implicit ../../bin/server" ./test.sh + testOrError "forgehook/test.sh from specs/forgehook folder with explicit result from ../../bin/server" ./test.sh "$(../../bin/server)" cd tests - ../../bin/test.sh || echo "ERROR bin/test.sh failed from spec/tests folder" - ../test_web.sh || echo "ERROR test_web.sh failed from spec/tests folder with implicit ../../bin/server" - ../test_web.sh "$(../../bin/server)" || echo "ERROR test_web.sh failed from spec/tests folder with explicit result from ../../bin/server" + testOrError "bin/test.sh from specs/forgehook/tests" ../../../bin/test.sh + testOrError "forgehook/test.sh from specs/forgehook/tests" ../test.sh + testOrError "forgehook/test.sh from specs/forgehook/tests folder with explicit result from ../../../bin/server" ../test.sh "$(../../../bin/server)" } ORIGDIR="$(pwd)" @@ -24,6 +42,9 @@ if [ -z "$1" ]; then elif [ -x ../bin/server ]; then cd .. testVariousScenarios + elif [ -x ../../bin/server ]; then + cd ../.. + testVariousScenarios else TMPDIR="$(mktemp -d)" cd "$TMPDIR" @@ -43,3 +64,5 @@ else fi cd "$ORIGDIR" + + diff --git a/forgehook/tests/gitea.bats b/forgehook/tests/gitea.bats index 2d61993..c1f6887 100644 --- a/forgehook/tests/gitea.bats +++ b/forgehook/tests/gitea.bats @@ -2,7 +2,7 @@ function setup { # Load helper functions - load ../helper + load ../../shared/helper # Which forgehook implementation to use? if [ -z "$FORGEHOOK" ]; then FORGEHOOK="forgehook"; fi port=$(find_free_port) @@ -30,7 +30,7 @@ function teardown { @test "gitea: correct signature works" { repo="https://tildegit.org/forge/hook.sh" id="$(echo -n "$repo" | base64)" - webhook="$(gen_webhook ../gitea.json "$repo")" + webhook="$(gen_webhook ../../shared/gitea.json "$repo")" secret="$($FORGEHOOK secret $repo)" echo -n "$secret" > "$WHCK_DIR"/"$id" sig="$(hash_hmac sha256 "$webhook" "$secret")" @@ -43,7 +43,7 @@ function teardown { @test "gitea: incorrect signature fails" { repo="https://tildegit.org/forge/hook.sh" id="$(echo -n "$repo" | base64)" - webhook="$(gen_webhook ../gitea.json "$repo")" + webhook="$(gen_webhook ../../shared/gitea.json "$repo")" # Calculate wrong signature secret="$($FORGEHOOK secret $repo)" echo -n "$secret" > "$WHCK_DIR"/"$id" diff --git a/forgehook/tests/github.bats b/forgehook/tests/github.bats index e58a6a9..ad5f3d4 100644 --- a/forgehook/tests/github.bats +++ b/forgehook/tests/github.bats @@ -2,7 +2,7 @@ function setup { # Load helper functions - load ../helper + load ../../shared/helper # Which forgehook implementation to use? if [ -z "$FORGEHOOK" ]; then FORGEHOOK="forgehook"; fi port=$(find_free_port) @@ -30,7 +30,7 @@ function teardown { @test "github: correct signature works" { repo="https://tildegit.org/forge/hook.sh" id="$(echo -n "$repo" | base64)" - webhook="$(gen_webhook ../github.json "$repo")" + webhook="$(gen_webhook ../../shared/github.json "$repo")" secret="$($FORGEHOOK secret $repo)" echo -n "$secret" > "$WHCK_DIR"/"$id" sig="$(hash_hmac sha256 "$webhook" "$secret")" @@ -43,7 +43,7 @@ function teardown { @test "github: incorrect signature fails" { repo="https://tildegit.org/forge/hook.sh" id="$(echo -n "$repo" | base64)" - webhook="$(gen_webhook ../github.json "$repo")" + webhook="$(gen_webhook ../../shared/github.json "$repo")" # Calculate wrong signature secret="$($FORGEHOOK secret $repo)" echo -n "$secret" > "$WHCK_DIR"/"$id" diff --git a/forgehook/tests/gitlab.bats b/forgehook/tests/gitlab.bats index 3d5d1ef..88281a1 100644 --- a/forgehook/tests/gitlab.bats +++ b/forgehook/tests/gitlab.bats @@ -2,7 +2,7 @@ function setup { # Load helper functions - load ../helper + load ../../shared/helper # Which forgehook implementation to use? if [ -z "$FORGEHOOK" ]; then FORGEHOOK="forgehook"; fi port=$(find_free_port) @@ -30,7 +30,7 @@ function teardown { @test "gitlab: correct signature works" { repo="https://tildegit.org/forge/hook.sh" id="$(echo -n "$repo" | base64)" - webhook="$(gen_webhook ../gitlab.json "$repo")" + webhook="$(gen_webhook ../../shared/gitlab.json "$repo")" secret="$($FORGEHOOK secret $repo)" echo -n "$secret" > "$WHCK_DIR"/"$id" sig="$secret" @@ -43,7 +43,7 @@ function teardown { @test "gitlab: incorrect signature fails" { repo="https://tildegit.org/forge/hook.sh" id="$(echo -n "$repo" | base64)" - webhook="$(gen_webhook ../gitlab.json "$repo")" + webhook="$(gen_webhook ../../shared/gitlab.json "$repo")" # Calculate wrong signature secret="$($FORGEHOOK secret $repo)" echo -n "$secret" > "$WHCK_DIR"/"$id"