Files
2026-10-10 10:37:53 +02:00

24 lines
1021 B
Bash

# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2026 Bryan Joshua Pedini
# tests/unit/fakes/fakelib.bash - shared by the fake package-manager commands.
# Every fake logs its invocation ("<name> <args...>") to $FAKE_LOG and keeps its mutable
# state (holds, purged packages, ...) under $FAKE_DIR. Replayed outputs live in
# tests/unit/data/<backend>/ and are copied from the samples recorded in discovery/*.md.
# shellcheck shell=bash
FAKE_NAME=${FAKE_AS:-${0##*/}}
: "${FAKE_LOG:?FAKE_LOG not set}" "${FAKE_DIR:?FAKE_DIR not set}" "${FAKE_DATA:?FAKE_DATA not set}"
fake_log() { printf '%s %s\n' "$FAKE_NAME" "$*" >>"$FAKE_LOG"; }
# fake_rc VAR DEFAULT: exit code override from the environment (e.g. FAKE_APT_UPGRADE_RC=100)
fake_rc() {
local v=${!1:-}
printf '%s' "${v:-$2}"
}
# fake_purged NAME: was NAME removed by an earlier fake purge in this test?
fake_purged() { [[ -f $FAKE_DIR/purged ]] && grep -qxF -- "$1" "$FAKE_DIR/purged"; }
fake_mark_purged() { printf '%s\n' "$@" >>"$FAKE_DIR/purged"; }