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}"
|
|
|
|
|
2020-01-17 18:10:36 +01:00
|
|
|
if [ -z "${IMAGE}" ]; then
|
|
|
|
echo "⚠️ No image defined"
|
|
|
|
|
|
|
|
if [ -z "${DEBUG}" ]; then
|
|
|
|
exit 1;
|
|
|
|
else
|
|
|
|
echo "⚠️ Would 'exit 1' here, but DEBUG is '${DEBUG}'."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-12-23 17:53:19 +01:00
|
|
|
# The docker compose command to use
|
|
|
|
doco="docker-compose -f docker-compose.test.yml"
|
2019-12-11 11:48:29 +01:00
|
|
|
|
2020-01-17 17:21:47 +01:00
|
|
|
INITIALIZERS_DIR=".initializers"
|
2019-12-11 11:48:29 +01:00
|
|
|
|
2020-01-17 17:21:47 +01:00
|
|
|
test_setup() {
|
|
|
|
echo "🏗 Setup up test environment"
|
|
|
|
if [ -d "${INITIALIZERS_DIR}" ]; then
|
|
|
|
rm -rf "${INITIALIZERS_DIR}"
|
|
|
|
fi
|
2019-12-11 11:48:29 +01:00
|
|
|
|
2020-01-17 17:21:47 +01:00
|
|
|
mkdir "${INITIALIZERS_DIR}"
|
2019-12-11 11:48:29 +01:00
|
|
|
(
|
|
|
|
cd initializers
|
|
|
|
for script in *.yml; do
|
2020-01-17 17:21:47 +01:00
|
|
|
sed -E 's/^# //' "${script}" > "../${INITIALIZERS_DIR}/${script}"
|
2019-12-11 11:48:29 +01:00
|
|
|
done
|
|
|
|
)
|
2020-01-17 17:21:47 +01:00
|
|
|
}
|
2019-12-11 11:48:29 +01:00
|
|
|
|
2020-01-17 17:21:47 +01:00
|
|
|
test_netbox_unit_tests() {
|
|
|
|
echo "⏱ Running Netbox Unit Tests"
|
|
|
|
$doco run --rm netbox ./manage.py test
|
|
|
|
}
|
|
|
|
|
|
|
|
test_initializers() {
|
|
|
|
echo "🏭 Testing Initializers"
|
|
|
|
export INITIALIZERS_DIR
|
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
|
|
|
|
|
2020-01-17 17:21:47 +01:00
|
|
|
if [ -d "${INITIALIZERS_DIR}" ]; then
|
|
|
|
rm -rf "${INITIALIZERS_DIR}"
|
2019-12-23 17:53:19 +01:00
|
|
|
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
|
2020-01-17 17:21:47 +01:00
|
|
|
test_setup
|
2019-12-11 11:48:29 +01:00
|
|
|
|
2020-01-20 08:37:18 +01:00
|
|
|
test_netbox_unit_tests
|
2019-12-11 11:48:29 +01:00
|
|
|
test_initializers
|
|
|
|
|
2019-12-23 17:53:19 +01:00
|
|
|
echo "🐳🐳🐳 Done testing '${IMAGE}'"
|