#!/bin/sh

[ -d /run/systemd/system ] || exit 77

debian/tests/genworkercode
debian/tests/genbuildcode

( cd "$AUTOPKGTEST_TMP" ; busybox httpd -p 5252 )

echo OBS_REPO_SERVERS="127.0.0.1:5252" >> /etc/default/obsworker

set -e

systemctl enable obsworker@1
systemctl start obsworker@1
sleep 10
systemctl status obsworker@1

PORT=$(systemctl status obsworker@1 | grep -o "worker started on port .*" | cut -d' ' -f5)

echo Detected: $PORT
curl -v http://0.0.0.0:$PORT/worker

systemctl stop obsworker@1
journalctl -xeu obsworker@1

