diff --git a/services/package.json b/services/package.json --- a/services/package.json +++ b/services/package.json @@ -7,23 +7,17 @@ "build-all": "./scripts/build_base_image.sh && docker-compose build", "build-base-image": "./scripts/build_base_image.sh", "run-tunnelbroker-service": "./scripts/run_server_image.sh tunnelbroker", - "test-tunnelbroker-service": "./scripts/test_service.sh tunnelbroker", "run-tunnelbroker-service-dev-mode": "COMM_SERVICES_DEV_MODE=1 ./scripts/run_server_image.sh tunnelbroker", - "test-tunnelbroker-service-dev-mode": "COMM_SERVICES_DEV_MODE=1 ./scripts/test_service.sh tunnelbroker", "build-backup-base": "./scripts/build_base_image.sh && docker-compose build backup-base", "run-backup-service": "./scripts/run_server_image.sh backup", - "test-backup-service": "./scripts/test_service.sh backup", "run-backup-service-dev-mode": "COMM_SERVICES_DEV_MODE=1 ./scripts/run_server_image.sh backup", - "test-backup-service-dev-mode": "COMM_SERVICES_DEV_MODE=1 ./scripts/test_service.sh backup", "build-blob-base": "./scripts/build_base_image.sh && docker-compose build blob-base", "run-blob-service": "./scripts/run_server_image.sh blob", - "test-blob-service": "./scripts/test_service.sh blob", "run-blob-service-dev-mode": "COMM_SERVICES_DEV_MODE=1 ./scripts/run_server_image.sh blob", - "test-blob-service-dev-mode": "COMM_SERVICES_DEV_MODE=1 ./scripts/test_service.sh blob", "run-all-services": "./scripts/run_all_services.sh", - "test-all-services": "./scripts/test_all_services.sh", - "test-all-services-dev-mode": "COMM_SERVICES_DEV_MODE=1 ./scripts/test_all_services.sh", + "run-unit-tests": "./scripts/run_unit_tests.sh", + "run-integration-tests": "./scripts/run_integration_tests.sh", "run-all-services-dev-mode": "COMM_SERVICES_DEV_MODE=1 ./scripts/run_all_services.sh", "init-local-cloud": "./scripts/init_local_cloud.sh" } -} \ No newline at end of file +} diff --git a/services/scripts/list_services.sh b/services/scripts/list_services.sh --- a/services/scripts/list_services.sh +++ b/services/scripts/list_services.sh @@ -2,4 +2,5 @@ set -e -ls | grep -vE 'base-image|docker.compose.yml|package.json|scripts' +find . -maxdepth 1 ! -name "base-image" ! -name "docker-compose.yml" ! -name "package.json" ! -name "scripts" ! -name "node_modules" ! -name "commtest" ! -name "lib" ! -name "terraform" ! -name ".*" -execdir echo {} ';' + diff --git a/services/scripts/run_integration_tests.sh b/services/scripts/run_integration_tests.sh new file mode 100755 --- /dev/null +++ b/services/scripts/run_integration_tests.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -e + +export COMM_TEST_SERVICES=1 +export COMM_SERVICES_DEV_MODE=1 + +SERVICES=$(./scripts/list_services.sh) + +run_integration_test () { + echo "integration tests tests will be run for the $1 service" + # add -- --nocapture in the end to enable logs + cargo test "$1"_test --test '*' --manifest-path=commtest/Cargo.toml #-- --nocapture +} + +list_expected () { + echo "Expected one of these:"; + echo "$SERVICES"; + echo "all"; +} + +if [[ -z "$1" ]]; then + echo "No service specified"; + list_expected; + exit 1; +fi + +if [[ "$1" == "all" ]]; then + for SERVICE in "$SERVICES"; do + run_integration_test "$SERVICE" + done + exit 0; +fi; + +SERVICE=$(grep "$1" <<< "$SERVICES") + +if [[ "$SERVICE" != "$1" ]]; then + echo "No such service: $1"; + list_expected; + exit 1; +fi; + +run_integration_test "$SERVICE" diff --git a/services/scripts/run_unit_tests.sh b/services/scripts/run_unit_tests.sh new file mode 100755 --- /dev/null +++ b/services/scripts/run_unit_tests.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -e + +export COMM_TEST_SERVICES=1 +export COMM_SERVICES_DEV_MODE=1 + +SERVICES=$(./scripts/list_services.sh) + +run_unit_test () { + echo "unit tests will be run for the $1 service" + + docker-compose build "$1"-server + docker-compose run "$1"-server +} + +list_expected () { + echo "Expected one of these:"; + echo "$SERVICES"; +} + +if [[ -z "$1" ]]; then + echo "No service specified"; + list_expected; + exit 1; +fi + +if [[ "$1" == "all" ]]; then + for SERVICE in $SERVICES; do + run_unit_test "$SERVICE" + done + exit 0; +fi; + +SERVICE=$(grep "$1" <<< "$SERVICES") + +if [[ "$SERVICE" != "$1" ]]; then + echo "No such service: $1"; + list_expected; + exit 1; +fi; + +run_unit_test "$SERVICE" diff --git a/services/scripts/test_all_services.sh b/services/scripts/test_all_services.sh deleted file mode 100755 --- a/services/scripts/test_all_services.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -set -e - -SERVICES=`./scripts/list_services.sh` - -for SERVICE in $SERVICES; do - ./scripts/test_service.sh $SERVICE -done diff --git a/services/scripts/test_service.sh b/services/scripts/test_service.sh deleted file mode 100755 --- a/services/scripts/test_service.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -e - -SERVICES=`./scripts/list_services.sh` -SERVICE=`echo "$SERVICES" | grep $1` || echo "No such service: $1" - -if [ "$SERVICE" != "$1" ]; then - echo "Expected one of these:" - echo "$SERVICES" - exit 1; -fi; - -export COMM_TEST_SERVICES=1 - -echo "${SERVICE} service will be tested" - -docker-compose build ${SERVICE}-server -docker-compose run ${SERVICE}-server