You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
9.2 KiB
172 lines
9.2 KiB
name: ChangeDetection.io App Test
|
|
|
|
# Triggers the workflow on push or pull request events
|
|
on: [push, pull_request]
|
|
|
|
jobs:
|
|
test-application:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
# Mainly just for link/flake8
|
|
- name: Set up Python 3.11
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: '3.11'
|
|
|
|
- name: Lint with flake8
|
|
run: |
|
|
pip3 install flake8
|
|
# stop the build if there are Python syntax errors or undefined names
|
|
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
|
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
|
|
|
- name: Spin up ancillary testable services
|
|
run: |
|
|
|
|
docker network create changedet-network
|
|
|
|
# Selenium+browserless
|
|
docker run --network changedet-network -d --hostname selenium -p 4444:4444 --rm --shm-size="2g" selenium/standalone-chrome:4
|
|
docker run --network changedet-network -d --name browserless --hostname browserless -e "FUNCTION_BUILT_INS=[\"fs\",\"crypto\"]" -e "DEFAULT_LAUNCH_ARGS=[\"--window-size=1920,1080\"]" --rm -p 3000:3000 --shm-size="2g" browserless/chrome:1.60-chrome-stable
|
|
|
|
# For accessing custom browser tests
|
|
docker run --network changedet-network -d --name browserless-custom-url --hostname browserless-custom-url -e "FUNCTION_BUILT_INS=[\"fs\",\"crypto\"]" -e "DEFAULT_LAUNCH_ARGS=[\"--window-size=1920,1080\"]" --rm --shm-size="2g" browserless/chrome:1.60-chrome-stable
|
|
|
|
- name: Build changedetection.io container for testing
|
|
run: |
|
|
# Build a changedetection.io container and start testing inside
|
|
docker build --build-arg LOGGER_LEVEL=TRACE -t test-changedetectionio .
|
|
# Debug info
|
|
docker run test-changedetectionio bash -c 'pip list'
|
|
|
|
- name: Spin up ancillary SMTP+Echo message test server
|
|
run: |
|
|
# Debug SMTP server/echo message back server
|
|
docker run --network changedet-network -d -p 11025:11025 -p 11080:11080 --hostname mailserver test-changedetectionio bash -c 'python changedetectionio/tests/smtp/smtp-test-server.py'
|
|
|
|
- name: Test built container with pytest
|
|
run: |
|
|
# Unit tests
|
|
echo "run test with unittest"
|
|
docker run test-changedetectionio bash -c 'python3 -m unittest changedetectionio.tests.unit.test_notification_diff'
|
|
docker run test-changedetectionio bash -c 'python3 -m unittest changedetectionio.tests.unit.test_watch_model'
|
|
|
|
# All tests
|
|
echo "run test with pytest"
|
|
# The default pytest logger_level is TRACE
|
|
# To change logger_level for pytest(test/conftest.py),
|
|
# append the docker option. e.g. '-e LOGGER_LEVEL=DEBUG'
|
|
docker run --network changedet-network test-changedetectionio bash -c 'cd changedetectionio && ./run_basic_tests.sh'
|
|
|
|
- name: Test built container selenium+browserless/playwright
|
|
run: |
|
|
|
|
# Selenium fetch
|
|
docker run --rm -e "WEBDRIVER_URL=http://selenium:4444/wd/hub" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest tests/fetchers/test_content.py && pytest tests/test_errorhandling.py'
|
|
|
|
# Playwright/Browserless fetch
|
|
docker run --rm -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest tests/fetchers/test_content.py && pytest tests/test_errorhandling.py && pytest tests/visualselector/test_fetch_data.py'
|
|
|
|
# Settings headers playwright tests - Call back in from Browserless, check headers
|
|
docker run --name "changedet" --hostname changedet --rm -e "FLASK_SERVER_NAME=changedet" -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000?dumpio=true" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio; pytest --live-server-host=0.0.0.0 --live-server-port=5004 tests/test_request.py'
|
|
docker run --name "changedet" --hostname changedet --rm -e "FLASK_SERVER_NAME=changedet" -e "WEBDRIVER_URL=http://selenium:4444/wd/hub" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio; pytest --live-server-host=0.0.0.0 --live-server-port=5004 tests/test_request.py'
|
|
docker run --name "changedet" --hostname changedet --rm -e "FLASK_SERVER_NAME=changedet" -e "USE_EXPERIMENTAL_PUPPETEER_FETCH=yes" -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000?dumpio=true" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio; pytest --live-server-host=0.0.0.0 --live-server-port=5004 tests/test_request.py'
|
|
|
|
# restock detection via playwright - added name=changedet here so that playwright/browserless can connect to it
|
|
docker run --rm --name "changedet" -e "FLASK_SERVER_NAME=changedet" -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest --live-server-port=5004 --live-server-host=0.0.0.0 tests/restock/test_restock.py'
|
|
|
|
- name: Test SMTP notification mime types
|
|
run: |
|
|
# SMTP content types - needs the 'Debug SMTP server/echo message back server' container from above
|
|
docker run --rm --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest tests/smtp/test_notification_smtp.py'
|
|
|
|
- name: Test with puppeteer fetcher and disk cache
|
|
run: |
|
|
docker run --rm -e "PUPPETEER_DISK_CACHE=/tmp/data/" -e "USE_EXPERIMENTAL_PUPPETEER_FETCH=yes" -e "PLAYWRIGHT_DRIVER_URL=ws://browserless:3000" --network changedet-network test-changedetectionio bash -c 'cd changedetectionio;pytest tests/fetchers/test_content.py && pytest tests/test_errorhandling.py && pytest tests/visualselector/test_fetch_data.py'
|
|
# Browserless would have had -e "FUNCTION_BUILT_INS=[\"fs\",\"crypto\"]" added above
|
|
|
|
- name: Test proxy interaction
|
|
run: |
|
|
cd changedetectionio
|
|
./run_proxy_tests.sh
|
|
# And again with PLAYWRIGHT_DRIVER_URL=..
|
|
cd ..
|
|
|
|
- name: Test custom browser URL
|
|
run: |
|
|
cd changedetectionio
|
|
./run_custom_browser_url_tests.sh
|
|
cd ..
|
|
|
|
- name: Test changedetection.io container starts+runs basically without error
|
|
run: |
|
|
docker run --name test-changedetectionio -p 5556:5000 -d test-changedetectionio
|
|
sleep 3
|
|
# Should return 0 (no error) when grep finds it
|
|
curl -s http://localhost:5556 |grep -q checkbox-uuid
|
|
|
|
# and IPv6
|
|
curl -s -g -6 "http://[::1]:5556"|grep -q checkbox-uuid
|
|
|
|
# Check whether TRACE log is enabled.
|
|
# Also, check whether TRACE is came from STDERR
|
|
docker logs test-changedetectionio 2>&1 1>/dev/null | grep 'TRACE log is enabled' || exit 1
|
|
# Check whether DEBUG is came from STDOUT
|
|
docker logs test-changedetectionio 2>/dev/null | grep 'DEBUG' || exit 1
|
|
|
|
docker kill test-changedetectionio
|
|
|
|
- name: Test changedetection.io SIGTERM and SIGINT signal shutdown
|
|
run: |
|
|
|
|
echo SIGINT Shutdown request test
|
|
docker run --name sig-test -d test-changedetectionio
|
|
sleep 3
|
|
echo ">>> Sending SIGINT to sig-test container"
|
|
docker kill --signal=SIGINT sig-test
|
|
sleep 3
|
|
# invert the check (it should be not 0/not running)
|
|
docker ps
|
|
# check signal catch(STDERR) log. Because of
|
|
# changedetectionio/__init__.py: logger.add(sys.stderr, level=logger_level)
|
|
docker logs sig-test 2>&1 | grep 'Shutdown: Got Signal - SIGINT' || exit 1
|
|
test -z "`docker ps|grep sig-test`"
|
|
if [ $? -ne 0 ]
|
|
then
|
|
echo "Looks like container was running when it shouldnt be"
|
|
docker ps
|
|
exit 1
|
|
fi
|
|
|
|
# @todo - scan the container log to see the right "graceful shutdown" text exists
|
|
docker rm sig-test
|
|
|
|
echo SIGTERM Shutdown request test
|
|
docker run --name sig-test -d test-changedetectionio
|
|
sleep 3
|
|
echo ">>> Sending SIGTERM to sig-test container"
|
|
docker kill --signal=SIGTERM sig-test
|
|
sleep 3
|
|
# invert the check (it should be not 0/not running)
|
|
docker ps
|
|
# check signal catch(STDERR) log. Because of
|
|
# changedetectionio/__init__.py: logger.add(sys.stderr, level=logger_level)
|
|
docker logs sig-test 2>&1 | grep 'Shutdown: Got Signal - SIGTERM' || exit 1
|
|
test -z "`docker ps|grep sig-test`"
|
|
if [ $? -ne 0 ]
|
|
then
|
|
echo "Looks like container was running when it shouldnt be"
|
|
docker ps
|
|
exit 1
|
|
fi
|
|
|
|
# @todo - scan the container log to see the right "graceful shutdown" text exists
|
|
docker rm sig-test
|
|
|
|
#export WEBDRIVER_URL=http://localhost:4444/wd/hub
|
|
#pytest tests/fetchers/test_content.py
|
|
#pytest tests/test_errorhandling.py
|