#!/bin/sh

# Smoke-test the packaged artefacts without starting any service or touching the
# network: every shipped binary must be present and executable, report its
# version and help text, and the manual pages must be installed.

set -e

. debian/tests/helper-functions

for bin in "${NTPD_RS_DAEMON_BIN}" "${NTPD_RS_CTL_BIN}" "${NTPD_RS_METRICS_BIN}"; do
    name=$(basename "${bin}")

    printf "Checking that %s is installed and executable: " "${bin}"
    test -x "${bin}" && __test_ok || __test_fail

    printf "Checking that '%s --version' reports its name: " "${name}"
    "${bin}" --version 2>&1 | grep -q "${name}" && __test_ok || __test_fail

    printf "Checking that '%s --help' prints usage: " "${name}"
    "${bin}" --help 2>&1 | grep -qi "usage" && __test_ok || __test_fail
done

for page in ntp-ctl.8 ntp-daemon.8 ntp-metrics-exporter.8 ntp.toml.5; do
    printf "Checking that the %s man page is installed: " "${page}"
    ls /usr/share/man/man*/"${page}"* >/dev/null 2>&1 && __test_ok || __test_fail
done

exit 0
