Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mockoon script failing silently #766

Merged
merged 5 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/mockoon-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- '!mocks/README.md'
- '.github/workflows/mockoon-tests.yml'
- 'Makefile'
- 'scripts/run-mockoon-tests'

pull_request:
paths:
Expand All @@ -15,6 +16,7 @@ on:
- '!mocks/README.md'
- '.github/workflows/mockoon-tests.yml'
- 'Makefile'
- 'scripts/run-mockoon-tests'

jobs:
integration-test:
Expand Down
30 changes: 12 additions & 18 deletions scripts/run-mockoon-tests
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
# be available or won't start.
#
# After this script runs created instance of mockoon container is
# removed from the system.
# removed from the system.

CONTAINER_ENGINE="podman"
MOCKOON_CONTAINER="mockoon/cli:1.5.1"
MOCKOON_CONTAINER="docker.io/mockoon/cli:2.2.1"
MOCKOON_PORT="3000"
MOCKOON_TIMEOUT=30

Expand All @@ -37,17 +37,17 @@ MOCK_JSON="${MOCK_JSON-"${SCRIPT_DIR}/../mocks/commitexporter_github.json"}"

if ! command -v "pytest" &> /dev/null
then
echo "No pytest found in the PATH"
exit 2
echo "No pytest found in the PATH"
exit 2
fi

if ! command -v "${CONTAINER_ENGINE}" &> /dev/null
then
CONTAINER_ENGINE="docker"
if ! command -v "${CONTAINER_ENGINE}" &> /dev/null
then
echo "No podman or docker found in the PATH"
exit 2
echo "No podman or docker found in the PATH"
exit 2
fi
fi

Expand All @@ -64,18 +64,16 @@ function cleanup_and_exit() {
echo "Exiting..."
cleanup_mockoon_pod
# Propagate exit value if was provided
[ -n "${exit_val}" ] && exit "$exit_val"
[ -n "${exit_val}" ] && echo "Exit code: ${exit_val}" && exit "$exit_val"
exit 0
}

trap 'cleanup_and_exit' INT TERM EXIT
trap 'cleanup_and_exit $?' INT TERM EXIT

# Check if test container already exists, if yes remove it

cleanup_mockoon_pod

# We need to check if port 3000 is used by other process

# We need to check if port MOCKOON_PORT is used by other process
if lsof -Pi :"${MOCKOON_PORT}" -sTCP:LISTEN -t >/dev/null ; then
echo "Can not run integration tests as other process uses port ${MOCKOON_PORT}"
exit 2
Expand All @@ -89,24 +87,20 @@ if [ "${RUNNING_ID}" == "" ]; then
echo "Mockoon is not working as expected."
echo "Logs from failing container:"
${CONTAINER_ENGINE} logs "${RUNNING_ID}"
exit 1
fi

counter=1
until curl -k https://localhost:3000/version
until curl -k https://localhost:"${MOCKOON_PORT}"/version
do
if [ $counter -gt $MOCKOON_TIMEOUT ]; then
echo "Timed out waiting for the mockoon service"
cleanup_and_exit
exit 1
fi
echo "Trying to reach mockoon: $counter out of $MOCKOON_TIMEOUT"
sleep 1
counter=$((counter+1))
done

# Remove exit trap, so we can propagate exit value from pytest
trap - EXIT

# Run mockoon tests
pytest -rap -m mockoon
pytest_exit=$?
cleanup_and_exit $pytest_exit