2019-12-11 11:48:29 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# exit when a command exits with an exit code != 0
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# version is used by `docker-compose.yml` do determine the tag
|
|
|
|
# of the Docker Image that is to be used
|
2019-12-23 17:53:19 +01:00
|
|
|
export IMAGE="${IMAGE-netboxcommunity/netbox:latest}"
|
|
|
|
|
|
|
|
# The docker compose command to use
|
|
|
|
doco="docker-compose -f docker-compose.test.yml"
|
2019-12-11 11:48:29 +01:00
|
|
|
|
|
|
|
test_netbox_unit_tests() {
|
|
|
|
echo "⏱ Running Netbox Unit Tests"
|
2019-12-23 17:53:19 +01:00
|
|
|
$doco run --rm netbox ./manage.py test
|
2019-12-11 11:48:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-12-23 17:53:19 +01:00
|
|
|
$doco run --rm netbox ./manage.py check
|
2019-12-11 11:48:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
test_cleanup() {
|
|
|
|
echo "💣 Cleaning Up"
|
2019-12-23 17:53:19 +01:00
|
|
|
$doco down -v
|
|
|
|
|
|
|
|
if [ -d initializers_original ]; then
|
|
|
|
rm -rf initializers
|
|
|
|
mv initializers_original initializers
|
|
|
|
fi
|
2019-12-11 11:48:29 +01:00
|
|
|
}
|
|
|
|
|
2019-12-23 17:53:19 +01:00
|
|
|
echo "🐳🐳🐳 Start testing '${IMAGE}'"
|
2019-12-11 11:48:29 +01:00
|
|
|
|
|
|
|
# Make sure the cleanup script is executed
|
|
|
|
trap test_cleanup EXIT ERR
|
|
|
|
|
|
|
|
test_netbox_unit_tests
|
|
|
|
test_initializers
|
|
|
|
|
2019-12-23 17:53:19 +01:00
|
|
|
echo "🐳🐳🐳 Done testing '${IMAGE}'"
|