Merge pull request #221 from netbox-community/improve-test.sh
Improve test.sh
This commit is contained in:
commit
e16b009a7f
|
@ -1,3 +1,4 @@
|
||||||
*.sql.gz
|
*.sql.gz
|
||||||
.netbox
|
.netbox
|
||||||
|
.initializers
|
||||||
docker-compose.override.yml
|
docker-compose.override.yml
|
||||||
|
|
|
@ -9,7 +9,7 @@ services:
|
||||||
user: '101'
|
user: '101'
|
||||||
volumes:
|
volumes:
|
||||||
- ./startup_scripts:/opt/netbox/startup_scripts:z,ro
|
- ./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
|
- ./configuration:/etc/netbox/config:z,ro
|
||||||
- ./reports:/etc/netbox/reports:z,ro
|
- ./reports:/etc/netbox/reports:z,ro
|
||||||
- ./scripts:/etc/netbox/scripts:z,ro
|
- ./scripts:/etc/netbox/scripts:z,ro
|
||||||
|
|
37
test.sh
37
test.sh
|
@ -10,24 +10,31 @@ export IMAGE="${IMAGE-netboxcommunity/netbox:latest}"
|
||||||
# The docker compose command to use
|
# The docker compose command to use
|
||||||
doco="docker-compose -f docker-compose.test.yml"
|
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() {
|
test_netbox_unit_tests() {
|
||||||
echo "⏱ Running Netbox Unit Tests"
|
echo "⏱ Running Netbox Unit Tests"
|
||||||
$doco run --rm netbox ./manage.py test
|
$doco run --rm netbox ./manage.py test
|
||||||
}
|
}
|
||||||
|
|
||||||
test_initializers() {
|
test_initializers() {
|
||||||
echo "🏗 Testing Initializers"
|
echo "🏭 Testing Initializers"
|
||||||
|
export INITIALIZERS_DIR
|
||||||
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
|
|
||||||
|
|
||||||
$doco run --rm netbox ./manage.py check
|
$doco run --rm netbox ./manage.py check
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,9 +42,8 @@ test_cleanup() {
|
||||||
echo "💣 Cleaning Up"
|
echo "💣 Cleaning Up"
|
||||||
$doco down -v
|
$doco down -v
|
||||||
|
|
||||||
if [ -d initializers_original ]; then
|
if [ -d "${INITIALIZERS_DIR}" ]; then
|
||||||
rm -rf initializers
|
rm -rf "${INITIALIZERS_DIR}"
|
||||||
mv initializers_original initializers
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +51,7 @@ echo "🐳🐳🐳 Start testing '${IMAGE}'"
|
||||||
|
|
||||||
# Make sure the cleanup script is executed
|
# Make sure the cleanup script is executed
|
||||||
trap test_cleanup EXIT ERR
|
trap test_cleanup EXIT ERR
|
||||||
|
test_setup
|
||||||
|
|
||||||
test_netbox_unit_tests
|
test_netbox_unit_tests
|
||||||
test_initializers
|
test_initializers
|
||||||
|
|
Loading…
Reference in New Issue