1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#!/bin/sh
set -e
set -x
pkg=orthanc-python
service_name=orthanc
CUR_DIR=`pwd`
export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi
cp -a ${CUR_DIR}/debian/tests/rest.py "${AUTOPKGTEST_TMP}"
cp -a ${CUR_DIR}/debian/tests/configuration.json "${AUTOPKGTEST_TMP}"
cp -a /usr/share/doc/${pkg}/ "${AUTOPKGTEST_TMP}"
cd "${AUTOPKGTEST_TMP}"
ln -s /usr/share/orthanc/plugins/libOrthancPython.so "${AUTOPKGTEST_TMP}"/libOrthancPython.so
echo "Running Tests"
# Check if user 'orthanc' exists
if getent passwd orthanc > /dev/null 2>&1; then
echo "User 'orthanc' exists."
else
adduser --system --group orthanc
echo "User 'orthanc' added."
fi
# Stop running instance of orthanc
sudo systemctl stop orthanc
sudo pkill Orthanc || true
sudo /usr/sbin/Orthanc ./configuration.json --verbose &
# Try for 15 times to find the system REST API of Orthanc up and running
URL=http://localhost:8042/system
tries=15
set +e # Thanks Etienne Mollier - https://lists.debian.org/debian-mentors/2025/04/msg00176.html
while true
do
STATUSCODE=$(curl --silent --output /dev/stderr --write-out "%{http_code}" ${URL})
test "$STATUSCODE" -eq 200 && echo "Orthanc initialized!" && break
tries=$(expr "$tries" - 1)
test "$tries" -le 0 && echo "Unable to initialize Orthanc" && exit 1
sleep 1
done
set -e
# Use curl to hit the REST API endpoint introduced by the Python plugin
result=$(curl -s http://localhost:8042/toto)
# Stop orthanc
sudo systemctl stop orthanc
sudo pkill Orthanc || true
# Check the result
if [ "$result" = "ok" ]; then
echo "Test passed"
exit 0
else
echo "Test failed with $result"
exit 1
fi
|