From 3b56c827f95bd5cda2a3895f0521c9fd97942f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=A4der?= Date: Fri, 17 Jan 2020 17:21:47 +0100 Subject: [PATCH] Improve test.sh Don't move the original initializers directory, but rather use the one with the modified initializers in it. --- .gitignore | 1 + docker-compose.test.yml | 2 +- test.sh | 39 +++++++++++++++++++++++---------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 4b029d7..97aa1b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.sql.gz .netbox +.initializers docker-compose.override.yml diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 534a025..9420617 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -9,7 +9,7 @@ services: user: '101' volumes: - ./startup_scripts:/opt/netbox/startup_scripts:z,ro - - ./initializers:/opt/netbox/initializers:z,ro + - ./${INITIALIZERS_DIR-initializers}:/opt/netbox/initializers:z,ro - ./configuration:/etc/netbox/config:z,ro - ./reports:/etc/netbox/reports:z,ro - ./scripts:/etc/netbox/scripts:z,ro diff --git a/test.sh b/test.sh index 627eef1..2b74847 100755 --- a/test.sh +++ b/test.sh @@ -10,24 +10,31 @@ export IMAGE="${IMAGE-netboxcommunity/netbox:latest}" # The docker compose command to use doco="docker-compose -f docker-compose.test.yml" +INITIALIZERS_DIR=".initializers" + +test_setup() { + echo "🏗 Setup up test environment" + if [ -d "${INITIALIZERS_DIR}" ]; then + rm -rf "${INITIALIZERS_DIR}" + fi + + mkdir "${INITIALIZERS_DIR}" + ( + cd initializers + for script in *.yml; do + sed -E 's/^# //' "${script}" > "../${INITIALIZERS_DIR}/${script}" + done + ) +} + test_netbox_unit_tests() { echo "⏱ Running Netbox Unit Tests" $doco run --rm netbox ./manage.py test } test_initializers() { - echo "🏗 Testing Initializers" - - mkdir initializers_test - ( - cd initializers - for script in *.yml; do - sed -E 's/^# //' "${script}" > "../initializers_test/${script}" - done - ) - mv initializers initializers_original - mv initializers_test initializers - + echo "🏭 Testing Initializers" + export INITIALIZERS_DIR $doco run --rm netbox ./manage.py check } @@ -35,9 +42,8 @@ test_cleanup() { echo "💣 Cleaning Up" $doco down -v - if [ -d initializers_original ]; then - rm -rf initializers - mv initializers_original initializers + if [ -d "${INITIALIZERS_DIR}" ]; then + rm -rf "${INITIALIZERS_DIR}" fi } @@ -45,8 +51,9 @@ echo "🐳🐳🐳 Start testing '${IMAGE}'" # Make sure the cleanup script is executed trap test_cleanup EXIT ERR +test_setup -test_netbox_unit_tests +# test_netbox_unit_tests test_initializers echo "🐳🐳🐳 Done testing '${IMAGE}'"