2024-09-24 16:33:26 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -o nounset
|
|
|
|
|
|
|
|
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
|
|
|
source "${GIT_ROOT}/_assets/scripts/colors.sh"
|
|
|
|
source "${GIT_ROOT}/_assets/scripts/codecov.sh"
|
|
|
|
|
2024-10-03 14:51:51 +01:00
|
|
|
echo -e "${GRN}Running functional tests${RST}"
|
2024-09-24 16:33:26 +01:00
|
|
|
|
2024-10-03 14:51:51 +01:00
|
|
|
root_path="${GIT_ROOT}/tests-functional"
|
2024-09-24 16:33:26 +01:00
|
|
|
coverage_reports_path="${root_path}/coverage"
|
|
|
|
binary_coverage_reports_path="${coverage_reports_path}/binary"
|
|
|
|
merged_coverage_reports_path="${coverage_reports_path}/merged"
|
|
|
|
test_results_path="${root_path}/reports"
|
|
|
|
|
|
|
|
# Cleanup any previous coverage reports
|
|
|
|
rm -rf "${coverage_reports_path}"
|
|
|
|
rm -rf "${test_results_path}"
|
|
|
|
|
|
|
|
# Create directories
|
|
|
|
mkdir -p "${binary_coverage_reports_path}"
|
|
|
|
mkdir -p "${merged_coverage_reports_path}"
|
|
|
|
mkdir -p "${test_results_path}"
|
|
|
|
|
|
|
|
all_compose_files="-f ${root_path}/docker-compose.anvil.yml -f ${root_path}/docker-compose.test.status-go.yml"
|
2024-12-19 14:18:40 +00:00
|
|
|
timestamp=$(python3 -c "import time; print(int(time.time() * 1000))") # Keep in sync with status_backend.py
|
|
|
|
project_name="status-go-func-tests-${timestamp}"
|
2024-09-24 16:33:26 +01:00
|
|
|
|
2024-11-21 15:21:53 +01:00
|
|
|
export STATUS_BACKEND_URLS=$(eval echo http://${project_name}-status-backend-{1..${STATUS_BACKEND_COUNT}}:3333 | tr ' ' ,)
|
|
|
|
|
2024-12-12 13:45:21 +01:00
|
|
|
# Remove orphans
|
|
|
|
docker ps -a --filter "name=status-go-func-tests-*-status-backend-*" --filter "status=exited" -q | xargs -r docker rm
|
|
|
|
|
|
|
|
# Run docker
|
2024-09-24 16:33:26 +01:00
|
|
|
echo -e "${GRN}Running tests${RST}, HEAD: $(git rev-parse HEAD)"
|
2024-12-12 13:45:21 +01:00
|
|
|
docker compose -p ${project_name} ${all_compose_files} up -d --build --remove-orphans
|
|
|
|
|
|
|
|
# Set up virtual environment
|
|
|
|
venv_path="${root_path}/.venv"
|
|
|
|
|
|
|
|
if [[ -d "${venv_path}" ]]; then
|
|
|
|
echo -e "${GRN}Using existing virtual environment${RST}"
|
|
|
|
else
|
|
|
|
echo -e "${GRN}Creating new virtual environment${RST}"
|
|
|
|
python3 -m venv "${venv_path}"
|
|
|
|
fi
|
2024-09-24 16:33:26 +01:00
|
|
|
|
2024-12-12 13:45:21 +01:00
|
|
|
source "${venv_path}/bin/activate"
|
|
|
|
|
|
|
|
# Upgrade pip and install requirements
|
|
|
|
echo -e "${GRN}Installing dependencies${RST}"
|
|
|
|
pip install --upgrade pip
|
|
|
|
pip install -r "${root_path}/requirements.txt"
|
|
|
|
|
|
|
|
# Run functional tests
|
|
|
|
pytest -m rpc --docker_project_name=${project_name} --codecov_dir=${binary_coverage_reports_path} --junitxml=${test_results_path}/report.xml
|
|
|
|
exit_code=$?
|
2024-09-24 16:33:26 +01:00
|
|
|
|
|
|
|
# Stop containers
|
|
|
|
echo -e "${GRN}Stopping docker containers${RST}"
|
2024-10-28 17:05:24 +01:00
|
|
|
docker compose -p ${project_name} ${all_compose_files} stop
|
2024-09-24 16:33:26 +01:00
|
|
|
|
|
|
|
# Save logs
|
|
|
|
echo -e "${GRN}Saving logs${RST}"
|
2024-10-28 17:05:24 +01:00
|
|
|
docker compose -p ${project_name} ${all_compose_files} logs status-go > "${root_path}/statusd.log"
|
|
|
|
docker compose -p ${project_name} ${all_compose_files} logs status-backend > "${root_path}/status-backend.log"
|
2024-10-28 14:02:30 +01:00
|
|
|
|
2024-09-24 16:33:26 +01:00
|
|
|
# Cleanup containers
|
|
|
|
echo -e "${GRN}Removing docker containers${RST}"
|
2024-10-28 17:05:24 +01:00
|
|
|
docker compose -p ${project_name} ${all_compose_files} down
|
2024-09-24 16:33:26 +01:00
|
|
|
|
|
|
|
# Collect coverage reports
|
|
|
|
echo -e "${GRN}Collecting code coverage reports${RST}"
|
|
|
|
full_coverage_profile="${coverage_reports_path}/coverage.out"
|
|
|
|
go tool covdata merge -i="${binary_coverage_reports_path}" -o="${merged_coverage_reports_path}"
|
|
|
|
go tool covdata textfmt -i="${merged_coverage_reports_path}" -o="${full_coverage_profile}"
|
|
|
|
convert_coverage_to_html "${full_coverage_profile}" "${coverage_reports_path}/coverage.html"
|
|
|
|
|
|
|
|
# Upload reports to Codecov
|
2024-10-03 14:51:51 +01:00
|
|
|
if [[ ${FUNCTIONAL_TESTS_REPORT_CODECOV} == 'true' ]]; then
|
2024-09-24 16:33:26 +01:00
|
|
|
report_to_codecov "${test_results_path}/*.xml" "${full_coverage_profile}" "functional"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -e "${GRN}Testing finished${RST}"
|
|
|
|
exit $exit_code
|