#!/bin/sh

set -eu

# A mock of schroot(1) for the unit tests of pkgos-schroot-clean.
# SCHROOT_MOCK_LOG is the file where "-e" calls are appended.
# SCHROOT_MOCK_MODE may be set to:
#   list (default): return 2 fake sessions, "-e" succeeds
#   list-and-fail: same, but "-e" fails
#   no-sessions: no active session

LOG=${SCHROOT_MOCK_LOG:?SCHROOT_MOCK_LOG must be set}

case "${1:-}" in
--all-sessions)
	if [ "${SCHROOT_MOCK_MODE:-list}" = "no-sessions" ] ; then
		exit 0
	fi
	echo "session:unstable-amd64-sbuild-11111111-1111-1111-1111-111111111111"
	echo "session:trixie-amd64-sbuild-22222222-2222-2222-2222-222222222222"
	;;
-e)
	shift
	echo "$@" >>"${LOG}"
	if [ "${SCHROOT_MOCK_MODE:-list}" = "list-and-fail" ] ; then
		exit 1
	fi
	;;
esac
exit 0
