2024-09-24 15:33:26 +00: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 13:51:51 +00:00
|
|
|
echo -e "${GRN}Running functional tests${RST}"
|
2024-09-24 15:33:26 +00:00
|
|
|
|
2024-10-03 13:51:51 +00:00
|
|
|
root_path="${GIT_ROOT}/tests-functional"
|
2024-09-24 15:33:26 +00: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-10-28 16:05:24 +00:00
|
|
|
project_name="status-go-func-tests-$(date +%s)"
|
2024-09-24 15:33:26 +00:00
|
|
|
|
2024-10-03 13:51:51 +00:00
|
|
|
# Run functional tests
|
2024-09-24 15:33:26 +00:00
|
|
|
echo -e "${GRN}Running tests${RST}, HEAD: $(git rev-parse HEAD)"
|
2024-10-28 16:05:24 +00:00
|
|
|
docker compose -p ${project_name} ${all_compose_files} up -d --build --remove-orphans
|
2024-09-24 15:33:26 +00:00
|
|
|
|
|
|
|
echo -e "${GRN}Running tests-rpc${RST}" # Follow the logs, wait for them to finish
|
2024-10-28 16:05:24 +00:00
|
|
|
docker compose -p ${project_name} ${all_compose_files} logs -f tests-rpc > "${root_path}/tests-rpc.log"
|
2024-09-24 15:33:26 +00:00
|
|
|
|
|
|
|
# Stop containers
|
|
|
|
echo -e "${GRN}Stopping docker containers${RST}"
|
2024-10-28 16:05:24 +00:00
|
|
|
docker compose -p ${project_name} ${all_compose_files} stop
|
2024-09-24 15:33:26 +00:00
|
|
|
|
|
|
|
# Save logs
|
|
|
|
echo -e "${GRN}Saving logs${RST}"
|
2024-10-28 16:05:24 +00: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 13:02:30 +00:00
|
|
|
|
2024-09-24 15:33:26 +00:00
|
|
|
# Retrieve exit code
|
2024-11-15 12:29:21 +00:00
|
|
|
exit_code=$(docker inspect ${project_name}-tests-rpc-1 -f '{{.State.ExitCode}}');
|
2024-09-24 15:33:26 +00:00
|
|
|
|
|
|
|
# Cleanup containers
|
|
|
|
echo -e "${GRN}Removing docker containers${RST}"
|
2024-10-28 16:05:24 +00:00
|
|
|
docker compose -p ${project_name} ${all_compose_files} down
|
2024-09-24 15:33:26 +00: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 13:51:51 +00:00
|
|
|
if [[ ${FUNCTIONAL_TESTS_REPORT_CODECOV} == 'true' ]]; then
|
2024-09-24 15:33:26 +00:00
|
|
|
report_to_codecov "${test_results_path}/*.xml" "${full_coverage_profile}" "functional"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -e "${GRN}Testing finished${RST}"
|
|
|
|
exit $exit_code
|