#!/bin/sh
# Every fake in this directory is a symlink to this file. It records the call
# and succeeds, so the installer can be driven end to end without a single
# package being installed, on this machine or in a container.
#
# `sudo` is faked too, and deliberately does NOT exec its argument: a run as
# root in a container would otherwise reach the real `rm -rf /opt/nvim`.
printf '%s %s\n' "${0##*/}" "$*" >> "${DOTUP_TEST_LOG:?DOTUP_TEST_LOG unset}"

case ${0##*/} in
apt-cache)
	# Stand in for a real apt cache: everything is known except `gh`, which is
	# genuinely absent from stock Ubuntu and is the manifest's real example of a
	# name that has to fall through to brew.
	case $2 in gh) exit 100 ;; esac
	printf 'Package: %s\n' "$2"; exit 0 ;;
curl)
	# Enough shape for the two bespoke handlers that parse a response.
	for a in "$@"; do
		case $a in
		*go.dev/VERSION*) echo go1.99.0; exit 0 ;;
		*api.github.com*) echo '  "browser_download_url": "https://example.invalid/fake_amd64.deb"'; exit 0 ;;
		esac
	done
	prev=
	for a in "$@"; do
		[ "$prev" = "-o" ] && { : > "$a"; exit 0; }
		prev=$a
	done
	exit 0 ;;
esac
exit 0
