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

Unit testing - add env var-based options for managing which run #332

Merged
merged 2 commits into from
Jun 16, 2021
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
5 changes: 5 additions & 0 deletions config/unit-test-js-only.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Optional env file to include for running only js unit tests in lab
# Gets picked up in tests/unit/unit_test_runner.sh
# e.g. docker-compose --env-file ./config/unit-test-js-only.env -f .\docker-compose-unit-test.yml up --abort-on-container-exit

PENNAI_UNIT_TESTS_JS_ONLY=1
5 changes: 5 additions & 0 deletions config/unit-test-py-only.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Optional env file to include for running only python unit tests in lab
# Gets picked up in tests/unit/unit_test_runner.sh
# e.g. docker-compose --env-file ./config/unit-test-py-only.env -f .\docker-compose-unit-test.yml up --abort-on-container-exit

PENNAI_UNIT_TESTS_PY_ONLY=1
4 changes: 3 additions & 1 deletion docker-compose-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ services:
context: .
dockerfile: tests/unit/Dockerfile
working_dir: /appsrc
command: bash -c "dos2unix tests/unit/unit_test_runner.sh && sh tests/unit/unit_test_runner.sh"
command: bash -c "dos2unix tests/unit/unit_test_runner.sh && export PENNAI_UNIT_TESTS_JS_ONLY=$PENNAI_UNIT_TESTS_JS_ONLY && export PENNAI_UNIT_TESTS_PY_ONLY=$PENNAI_UNIT_TESTS_PY_ONLY && sh tests/unit/unit_test_runner.sh"
tty: true
stdin_open: true
volumes:
- "./:/appsrc"
- "/appsrc/lab/webapp/node_modules"
- "/appsrc/lab/node_modules"


31 changes: 25 additions & 6 deletions tests/unit/unit_test_runner.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
#!/bin/bash

# NOTE
# To run only the python tests (py_tests.sh) or only the web/javascript tests
# (js_tests.sh), set the appropriate env var, as used below.
# With docker-compose, use the --env-file param and pass either of
# config/unit-test-js-only.env, or
# config/unit-test-py-only.env

dos2unix /appsrc/tests/unit/py_tests.sh
dos2unix /appsrc/tests/unit/js_tests.sh

# initialize
pyres=0
jsres=0

# run via sh to avoid permissions problem
sh /appsrc/tests/unit/py_tests.sh
pyres=$?
# echo "==== py_tests unit tests result "$pyres
if [ -z "${PENNAI_UNIT_TESTS_JS_ONLY}" ]; then
sh /appsrc/tests/unit/py_tests.sh
pyres=$?
# echo "==== py_tests unit tests result "$pyres
else
echo "$0 - skipped py_tests"
fi

# run via sh to avoid permissions problem
sh /appsrc/tests/unit/js_tests.sh
jsres=$?
# echo "==== js_tests unit tests result "$jsres
if [ -z "${PENNAI_UNIT_TESTS_PY_ONLY}" ]; then
sh /appsrc/tests/unit/js_tests.sh
jsres=$?
# echo "==== js_tests unit tests result "$jsres
else
echo "$0 - skipped js_tests"
fi

# exit with code 1 if either test fails
# If we don't exit with a non-zero value, github actions won't catch the error
Expand Down