Skip to content

Commit daaf729

Browse files
committed
Adds a test that validates the initializer yml files
1 parent bf2a21d commit daaf729

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

β€Žhooks/test

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22

33
. hooks/common
44

5-
run_test() {
6-
echo "🐳🐳🐳 Testing '${1}'"
7-
VERSION="${1}" docker-compose run netbox ./manage.py test
8-
docker-compose down -v
9-
echo "🐳🐳🐳 Done testing '${1}'"
10-
}
11-
125
# test on builds of 'branches'
136
if [ "${BUILD}" == "branches" ] \
147
|| [ "${DEBUG}" == "true" ]; then
15-
run_test latest
16-
run_test snapshot
8+
./test.sh latest
9+
./test.sh snapshot
1710
# test on bulds of 'this' (i.e. pull request)
1811
elif [ "${BUILD}" == "this" ]; then
19-
run_test latest
12+
./test.sh latest
2013
else
2114
echo "🐳🐳🐳 No tests are implemented for build '${BUILD}'."
2215
fi

β€Žtest.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# exit when a command exits with an exit code != 0
4+
set -e
5+
6+
# version is used by `docker-compose.yml` do determine the tag
7+
# of the Docker Image that is to be used
8+
export VERSION=${VERSION-latest}
9+
10+
test_netbox_unit_tests() {
11+
echo "⏱ Running Netbox Unit Tests"
12+
docker-compose run --rm netbox ./manage.py test
13+
}
14+
15+
test_initializers() {
16+
echo "πŸ— Testing Initializers"
17+
18+
mkdir initializers_test
19+
(
20+
cd initializers
21+
for script in *.yml; do
22+
sed -E 's/^# //' "${script}" > "../initializers_test/${script}"
23+
done
24+
)
25+
mv initializers initializers_original
26+
mv initializers_test initializers
27+
28+
docker-compose run --rm netbox ./manage.py check
29+
}
30+
31+
test_cleanup() {
32+
echo "πŸ’£ Cleaning Up"
33+
docker-compose down -v
34+
rm -rf initializers
35+
mv initializers_original initializers
36+
}
37+
38+
echo "🐳🐳🐳 Start testing '${VERSION}'"
39+
40+
# Make sure the cleanup script is executed
41+
trap test_cleanup EXIT ERR
42+
43+
test_netbox_unit_tests
44+
test_initializers
45+
46+
echo "🐳🐳🐳 Done testing '${VERSION}'"

0 commit comments

Comments
Β (0)