#!/bin/sh
# Check the evaluation Redis target from a disposable Linux CI runner.
# Requires workload identity, alma, a TLS-capable client, and GNU timeout.
set -eu

: "${ALMA_PROXY:?Set the cluster proxy address}"
: "${ALMA_CLIENT_ID:?Set the workload token name}"
: "${ALMA_JOIN_METHOD:?Set the runner workload identity method}"

# Complete login before capturing the database reply.
timeout --kill-after=5s 30s alma login >/dev/null

reply=$(printf 'PING\n' | timeout --kill-after=5s 30s \
    alma exec db/redis --user=default)

if [ "${reply}" != PONG ]; then
    printf '%s\n' 'Redis check failed: expected PONG.' >&2
    exit 1
fi

printf '%s\n' PONG
