#!/usr/bin/env bash
# Mock `id`. Only supports the two forms linux.sh uses. Mocked for
# determinism, same reasoning as the `getent` mock beside it: the real machine
# running this suite may or may not actually have this user in `sonomos-proxy`,
# and a test must not depend on that ambient fact either way.
#
# `id -nG <user>` prints the names in $SONOMOS_TEST_ID_GROUPS (space-separated),
# or nothing.
#
# `id -u` prints $SONOMOS_TEST_ID_UID, default 1000: never root unless a test
# says so, whoever is running the suite.
if [ "$1" = "-nG" ]; then
  printf '%s\n' "${SONOMOS_TEST_ID_GROUPS:-}"
  exit 0
fi
if [ "$1" = "-u" ] && [ "$#" -eq 1 ]; then
  printf '%s\n' "${SONOMOS_TEST_ID_UID:-1000}"
  exit 0
fi
echo "MOCK-id: unsupported invocation: $*" >&2
exit 97
