Skip to content

Commit 9441be4

Browse files
committed
Improved testing
After the initializer scripts were removed, we didn't test the actual compose setup anymore. This adds new tests to run the database migrations.
1 parent 1779ba7 commit 9441be4

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

β€Ždocker-compose.test.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ services:
33
netbox:
44
image: ${IMAGE-netboxcommunity/netbox:latest}
55
depends_on:
6-
- postgres
7-
- redis
8-
- redis-cache
6+
postgres:
7+
condition: service_healthy
8+
redis:
9+
condition: service_started
10+
redis-cache:
11+
condition: service_started
912
env_file: env/netbox.env
10-
environment:
11-
SKIP_STARTUP_SCRIPTS: ${SKIP_STARTUP_SCRIPTS-false}
1213
user: 'unit:root'
1314
volumes:
1415
- ./configuration:/etc/netbox/config:z,ro
@@ -19,6 +20,11 @@ services:
1920
postgres:
2021
image: postgres:15-alpine
2122
env_file: env/postgres.env
23+
healthcheck:
24+
test: ["CMD-SHELL", "pg_isready"]
25+
interval: 10s
26+
timeout: 5s
27+
retries: 5
2228
redis:
2329
image: redis:7-alpine
2430
command:

β€Žtest.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,29 @@ if [ -z "${IMAGE}" ]; then
3535
fi
3636

3737
# The docker compose command to use
38-
doco="docker-compose --file docker-compose.test.yml --project-name netbox_docker_test_${1}"
38+
doco="docker compose --file docker-compose.test.yml --project-name netbox_docker_test"
3939

4040
test_setup() {
4141
echo "πŸ— Setup up test environment"
42+
$doco up --detach --quiet-pull --wait --force-recreate --renew-anon-volumes --no-start
43+
$doco start postgres
44+
$doco start redis
45+
$doco start redis-cache
4246
}
4347

4448
test_netbox_unit_tests() {
4549
echo "⏱ Running NetBox Unit Tests"
4650
$doco run --rm netbox /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py test
4751
}
4852

53+
test_compose_db_setup() {
54+
echo "⏱ Running NetBox DB migrations"
55+
$doco run --rm netbox /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py migrate
56+
}
57+
4958
test_cleanup() {
5059
echo "πŸ’£ Cleaning Up"
51-
$doco down -v
60+
$doco down --volumes
5261
}
5362

5463
echo "🐳🐳🐳 Start testing '${IMAGE}'"
@@ -58,5 +67,6 @@ trap test_cleanup EXIT ERR
5867
test_setup
5968

6069
test_netbox_unit_tests
70+
test_compose_db_setup
6171

6272
echo "🐳🐳🐳 Done testing '${IMAGE}'"

0 commit comments

Comments
Β (0)