Added more tests (#965)
This commit is contained in:
parent
c001b88a81
commit
f2d070fc49
6
docker-compose.test.override.yml
Normal file
6
docker-compose.test.override.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
version: '3.4'
|
||||||
|
services:
|
||||||
|
netbox:
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8000:8080"
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
version: '3.4'
|
version: '3.4'
|
||||||
services:
|
services:
|
||||||
netbox:
|
netbox: &netbox
|
||||||
image: ${IMAGE-netboxcommunity/netbox:latest}
|
image: ${IMAGE-netboxcommunity/netbox:latest}
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
@ -12,11 +12,32 @@ services:
|
|||||||
env_file: env/netbox.env
|
env_file: env/netbox.env
|
||||||
user: 'unit:root'
|
user: 'unit:root'
|
||||||
volumes:
|
volumes:
|
||||||
- ./configuration:/etc/netbox/config:z,ro
|
|
||||||
- ./test-configuration/logging.py:/etc/netbox/config/logging.py:z,ro
|
- ./test-configuration/logging.py:/etc/netbox/config/logging.py:z,ro
|
||||||
- ./reports:/etc/netbox/reports:z,ro
|
healthcheck:
|
||||||
- ./scripts:/etc/netbox/scripts:z,ro
|
start_period: 120s
|
||||||
- netbox-media-files:/opt/netbox/netbox/media:z
|
timeout: 3s
|
||||||
|
interval: 15s
|
||||||
|
test: "curl -f http://localhost:8080/api/ || exit 1"
|
||||||
|
netbox-worker:
|
||||||
|
<<: *netbox
|
||||||
|
command:
|
||||||
|
- /opt/netbox/venv/bin/python
|
||||||
|
- /opt/netbox/netbox/manage.py
|
||||||
|
- rqworker
|
||||||
|
healthcheck:
|
||||||
|
start_period: 40s
|
||||||
|
timeout: 3s
|
||||||
|
interval: 15s
|
||||||
|
test: "ps -aux | grep -v grep | grep -q rqworker || exit 1"
|
||||||
|
netbox-housekeeping:
|
||||||
|
<<: *netbox
|
||||||
|
command:
|
||||||
|
- /opt/netbox/housekeeping.sh
|
||||||
|
healthcheck:
|
||||||
|
start_period: 40s
|
||||||
|
timeout: 3s
|
||||||
|
interval: 15s
|
||||||
|
test: "ps -aux | grep -v grep | grep -q housekeeping || exit 1"
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:15-alpine
|
image: postgres:15-alpine
|
||||||
env_file: env/postgres.env
|
env_file: env/postgres.env
|
||||||
|
49
test.sh
49
test.sh
@ -14,6 +14,8 @@
|
|||||||
# exit when a command exits with an exit code != 0
|
# exit when a command exits with an exit code != 0
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
source ./build-functions/gh-functions.sh
|
||||||
|
|
||||||
# IMAGE is used by `docker-compose.yml` do determine the tag
|
# IMAGE is used by `docker-compose.yml` do determine the tag
|
||||||
# of the Docker Image that is to be used
|
# of the Docker Image that is to be used
|
||||||
if [ "${1}x" != "x" ]; then
|
if [ "${1}x" != "x" ]; then
|
||||||
@ -35,29 +37,72 @@ if [ -z "${IMAGE}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# The docker compose command to use
|
# The docker compose command to use
|
||||||
doco="docker compose --file docker-compose.test.yml --project-name netbox_docker_test"
|
doco="docker compose --file docker-compose.test.yml --file docker-compose.test.override.yml --project-name netbox_docker_test"
|
||||||
|
|
||||||
test_setup() {
|
test_setup() {
|
||||||
|
gh_echo "::group:: Test setup"
|
||||||
echo "🏗 Setup up test environment"
|
echo "🏗 Setup up test environment"
|
||||||
$doco up --detach --quiet-pull --wait --force-recreate --renew-anon-volumes --no-start
|
$doco up --detach --quiet-pull --wait --force-recreate --renew-anon-volumes --no-start
|
||||||
$doco start postgres
|
$doco start postgres
|
||||||
$doco start redis
|
$doco start redis
|
||||||
$doco start redis-cache
|
$doco start redis-cache
|
||||||
|
gh_echo "::endgroup::"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_netbox_unit_tests() {
|
test_netbox_unit_tests() {
|
||||||
|
gh_echo "::group:: Netbox unit tests"
|
||||||
echo "⏱ Running NetBox Unit Tests"
|
echo "⏱ Running NetBox Unit Tests"
|
||||||
$doco run --rm netbox /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py test
|
$doco run --rm netbox /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py test
|
||||||
|
gh_echo "::endgroup::"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_compose_db_setup() {
|
test_compose_db_setup() {
|
||||||
|
gh_echo "::group:: Netbox DB migrations"
|
||||||
echo "⏱ Running NetBox DB migrations"
|
echo "⏱ Running NetBox DB migrations"
|
||||||
$doco run --rm netbox /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py migrate
|
$doco run --rm netbox /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py migrate
|
||||||
|
gh_echo "::endgroup::"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_netbox_start() {
|
||||||
|
gh_echo "::group:: Start Netbox service"
|
||||||
|
echo "⏱ Starting NetBox services"
|
||||||
|
$doco up --detach --wait
|
||||||
|
gh_echo "::endgroup::"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_netbox_web() {
|
||||||
|
gh_echo "::group:: Web service test"
|
||||||
|
echo "⏱ Starting web service test"
|
||||||
|
RESP_CODE=$(
|
||||||
|
curl \
|
||||||
|
--silent \
|
||||||
|
--output /dev/null \
|
||||||
|
--write-out '%{http_code}' \
|
||||||
|
--request GET \
|
||||||
|
--connect-timeout 5 \
|
||||||
|
--max-time 10 \
|
||||||
|
--retry 5 \
|
||||||
|
--retry-delay 0 \
|
||||||
|
--retry-max-time 40 \
|
||||||
|
http://127.0.0.1:8000/
|
||||||
|
)
|
||||||
|
if [ "$RESP_CODE" == "200" ]; then
|
||||||
|
echo "Webservice running"
|
||||||
|
else
|
||||||
|
echo "⚠️ Got response code '$RESP_CODE' but expected '200'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
gh_echo "::endgroup::"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_cleanup() {
|
test_cleanup() {
|
||||||
echo "💣 Cleaning Up"
|
echo "💣 Cleaning Up"
|
||||||
|
gh_echo "::group:: Docker compose logs"
|
||||||
|
$doco logs --no-color
|
||||||
|
gh_echo "::endgroup::"
|
||||||
|
gh_echo "::group:: Docker compose down"
|
||||||
$doco down --volumes
|
$doco down --volumes
|
||||||
|
gh_echo "::endgroup::"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "🐳🐳🐳 Start testing '${IMAGE}'"
|
echo "🐳🐳🐳 Start testing '${IMAGE}'"
|
||||||
@ -68,5 +113,7 @@ test_setup
|
|||||||
|
|
||||||
test_netbox_unit_tests
|
test_netbox_unit_tests
|
||||||
test_compose_db_setup
|
test_compose_db_setup
|
||||||
|
test_netbox_start
|
||||||
|
test_netbox_web
|
||||||
|
|
||||||
echo "🐳🐳🐳 Done testing '${IMAGE}'"
|
echo "🐳🐳🐳 Done testing '${IMAGE}'"
|
||||||
|
Loading…
Reference in New Issue
Block a user