Admin: Simplify dependency test (#5827)
This commit is contained in:
parent
27a2e42d9b
commit
4165aa8ae7
20
.github/workflows/dependency_test.yml
vendored
20
.github/workflows/dependency_test.yml
vendored
@ -6,12 +6,23 @@ on:
|
||||
- cron: '0 0 * * *' # every day at midnight
|
||||
|
||||
jobs:
|
||||
prepare_list:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- id: set-matrix
|
||||
run: echo "matrix=[$(ls -A1 moto | grep -v '.py' | awk '{ printf "%s\047%s\047", (NR==1?"":", "), $0 } END{ print "" }')]" >> $GITHUB_OUTPUT
|
||||
- run: echo "matrix=[$(ls -A1 moto | grep -v '.py' | awk '{ printf "%s\047%s\047", (NR==1?"":", "), $0 } END{ print "" }')]"
|
||||
outputs:
|
||||
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
||||
runtest:
|
||||
name: Run Dependency Test
|
||||
runs-on: ubuntu-latest
|
||||
needs: prepare_list
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [ 3.8 ]
|
||||
service: ${{ fromJson(needs.prepare_list.outputs.matrix) }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
@ -25,11 +36,4 @@ jobs:
|
||||
AWS_ACCESS_KEY_ID: key
|
||||
AWS_SECRET_ACCESS_KEY: secret
|
||||
run: |
|
||||
scripts/dependency_test.sh
|
||||
- name: Archive logs
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: buildfolder-${{ matrix.python-version }}
|
||||
path: |
|
||||
test_results_*.log
|
||||
scripts/dependency_test.sh ${{ matrix.service }}
|
||||
|
@ -33,7 +33,7 @@ valid_service() {
|
||||
# Verify whether this is a valid service
|
||||
# We'll ignore metadata folders, and folders that test generic Moto behaviour
|
||||
# We'll also ignore CloudFormation, as it will always depend on other services
|
||||
local ignore_moto_folders="core instance_metadata __pycache__ templates cloudformation moto_api resourcegroupstaggingapi packages utilities s3bucket_path"
|
||||
local ignore_moto_folders="core instance_metadata __pycache__ templates cloudformation moto_api moto_server resourcegroupstaggingapi packages utilities s3bucket_path"
|
||||
if echo $ignore_moto_folders | grep -q "$1"; then
|
||||
return 1
|
||||
else
|
||||
@ -46,53 +46,43 @@ test_service() {
|
||||
path_to_test_file=$2
|
||||
venv_path="test_venv_${service}"
|
||||
overwrite "Running tests for ${service}.."
|
||||
python -m venv ${venv_path} > /dev/null
|
||||
source ${venv_path}/bin/activate > /dev/null
|
||||
python -m venv ${venv_path}
|
||||
source ${venv_path}/bin/activate
|
||||
pip install --upgrade pip setuptools
|
||||
# Can't just install requirements-file, as it points to all dependencies
|
||||
pip install -r requirements-tests.txt > /dev/null
|
||||
pip install .[$service] > /dev/null 2>&1
|
||||
pip install boto > /dev/null 2>&1
|
||||
pip install -r requirements-tests.txt
|
||||
pip install .[$service]
|
||||
pip install boto
|
||||
if [[ $service != "xray" ]]; then
|
||||
pip uninstall setuptools pkg_resources -y > /dev/null 2>&1
|
||||
pip uninstall setuptools pkg_resources -y
|
||||
fi
|
||||
# Restart venv - ensure these deps are loaded
|
||||
deactivate
|
||||
source ${venv_path}/bin/activate > /dev/null
|
||||
source ${venv_path}/bin/activate
|
||||
# Run tests for this service
|
||||
test_result_filename="test_results_${service}.log"
|
||||
touch $test_result_filename
|
||||
pytest -sv --ignore-glob="**/test_server.py" --ignore-glob="**/test_*_cloudformation.py" --ignore-glob="**/test_*_integration.py" $path_to_test_file >$test_result_filename 2>&1
|
||||
pytest -sv --ignore-glob="**/test_server.py" --ignore-glob="**/test_*_cloudformation.py" --ignore-glob="**/test_*_integration.py" $path_to_test_file
|
||||
RESULT=$?
|
||||
if [[ $RESULT != 0 ]]; then
|
||||
echo -e "Tests for ${service} have failed!\n"
|
||||
else
|
||||
rm $test_result_filename
|
||||
fi
|
||||
deactivate
|
||||
rm -rf ${venv_path}
|
||||
if [[ $RESULT != 0 ]]; then
|
||||
echo -e "Tests for ${service} have failed!\n"
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
echo "Running Dependency tests..."
|
||||
ITER=0
|
||||
for file in moto/*
|
||||
do
|
||||
if [[ -d $file ]]; then
|
||||
service=${file:5}
|
||||
path_to_test_file="tests/test_${service}"
|
||||
if valid_service $service && [[ -d $path_to_test_file ]]; then
|
||||
test_service $service $path_to_test_file &
|
||||
elif valid_service $service; then
|
||||
service=$1
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
echo 'Please add the name of the service you want to test as the first argument:'
|
||||
echo ' scripts/dependency_test.sh acm'
|
||||
exit 0
|
||||
fi
|
||||
echo "Running Dependency tests for {$1}..."
|
||||
path_to_test_file="tests/test_${service}"
|
||||
if valid_service $service && [[ -d $path_to_test_file ]]; then
|
||||
test_service $service $path_to_test_file
|
||||
if [[ $? != 0 ]]; then
|
||||
exit -1
|
||||
fi
|
||||
elif valid_service $service; then
|
||||
echo -e "No tests for ${service} can be found on ${path_to_test_file}!\n"
|
||||
fi
|
||||
if (( $ITER % 4 == 0 )); then
|
||||
# Ensure we're only processing 4 services at the time
|
||||
wait
|
||||
fi
|
||||
fi
|
||||
ITER=$(expr $ITER + 1)
|
||||
done
|
||||
wait
|
||||
|
||||
nr_of_failed_services=$(ls -1q test_results*.log 2>/dev/null | wc -l)
|
||||
echo "Nr of failed services: ${nr_of_failed_services}"
|
||||
exit $((nr_of_failed_services))
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user