Merge pull request #20 from kevinveenbirkenbach/chore/test-scripts-no-inline
chore(test): run the container test bodies from files instead of inline bash
This commit is contained in:
10 files changed
+116
-127
No files matched your search
Executable
+33
@@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if [ -f /etc/os-release ]; then
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. /etc/os-release
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Running tests inside distro: ${ID:-unknown}"
|
||||||
|
|
||||||
|
if [ -f "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]; then
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PATH="/nix/var/nix/profiles/default/bin:$HOME/.nix-profile/bin:$PATH"
|
||||||
|
|
||||||
|
command -v nix >/dev/null || {
|
||||||
|
echo "ERROR: nix not found."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
bash scripts/test/container/safe-directory.sh
|
||||||
|
|
||||||
|
nix develop .#default --no-write-lock-file -c \
|
||||||
|
python3 -m unittest discover \
|
||||||
|
-s /opt/src/pkgmgr/tests/e2e \
|
||||||
|
-p "$TEST_PATTERN"
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Param: IMAGE ($1) - the image name shown in the missing-nix error.
|
||||||
|
# Param: PKGMGR_DISTRO ($2) - the distro shown in the missing-nix error.
|
||||||
|
IMAGE="$1"
|
||||||
|
PKGMGR_DISTRO="$2"
|
||||||
|
|
||||||
|
bash scripts/test/container/safe-directory.sh
|
||||||
|
|
||||||
|
echo ">>> preflight: nix must exist in image"
|
||||||
|
if ! command -v nix >/dev/null 2>&1; then
|
||||||
|
echo "NO_NIX"
|
||||||
|
echo "ERROR: nix not found in image ${IMAGE} (PKGMGR_DISTRO=${PKGMGR_DISTRO})"
|
||||||
|
echo "HINT: Ensure Nix is installed during image build for this distro."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ">>> nix version"
|
||||||
|
nix --version
|
||||||
|
|
||||||
|
if [[ -f /opt/src/pkgmgr/scripts/nix/lib/retry_403.sh ]]; then
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source /opt/src/pkgmgr/scripts/nix/lib/retry_403.sh
|
||||||
|
elif [[ -f ./scripts/nix/lib/retry_403.sh ]]; then
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source ./scripts/nix/lib/retry_403.sh
|
||||||
|
else
|
||||||
|
echo "ERROR: retry helper not found: scripts/nix/lib/retry_403.sh"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ">>> nix flake show"
|
||||||
|
run_with_github_403_retry nix flake show . --no-write-lock-file >/dev/null
|
||||||
|
|
||||||
|
echo ">>> nix build .#default"
|
||||||
|
run_with_github_403_retry nix build .#default --no-link --no-write-lock-file
|
||||||
|
|
||||||
|
echo ">>> nix run .#pkgmgr -- --help"
|
||||||
|
run_with_github_403_retry nix run .#pkgmgr -- --help --no-write-lock-file
|
||||||
|
|
||||||
|
echo ">>> OK: Nix flake-only test succeeded."
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo "[test-env-virtual] Installing pkgmgr (distro package)..."
|
||||||
|
make install
|
||||||
|
|
||||||
|
echo "[test-env-virtual] Setting up Python venv..."
|
||||||
|
make setup-venv
|
||||||
|
|
||||||
|
echo "[test-env-virtual] Activating venv..."
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$HOME/.venvs/pkgmgr/bin/activate"
|
||||||
|
|
||||||
|
echo "[test-env-virtual] Using pkgmgr from:"
|
||||||
|
command -v pkgmgr
|
||||||
|
pkgmgr --help
|
||||||
Executable
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if command -v git >/dev/null 2>&1; then
|
||||||
|
git config --global --add safe.directory /opt/src/pkgmgr || true
|
||||||
|
git config --global --add safe.directory /opt/src/pkgmgr/.git || true
|
||||||
|
git config --global --add safe.directory "*" || true
|
||||||
|
fi
|
||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Param: suite ($1) - the test folder to discover, tests/unit or tests/integration.
|
||||||
|
suite="$1"
|
||||||
|
|
||||||
|
git config --global --add safe.directory /opt/src/pkgmgr || true
|
||||||
|
nix develop .#default --no-write-lock-file -c \
|
||||||
|
python3 -m unittest discover \
|
||||||
|
-s "$suite" \
|
||||||
|
-t /opt/src/pkgmgr \
|
||||||
|
-p "$TEST_PATTERN"
|
||||||
@@ -14,48 +14,4 @@ docker run --rm \
|
|||||||
-e NIX_CONFIG="${NIX_CONFIG}" \
|
-e NIX_CONFIG="${NIX_CONFIG}" \
|
||||||
--workdir /opt/src/pkgmgr \
|
--workdir /opt/src/pkgmgr \
|
||||||
"pkgmgr-${PKGMGR_DISTRO}" \
|
"pkgmgr-${PKGMGR_DISTRO}" \
|
||||||
bash -lc '
|
bash -l scripts/test/container/e2e.sh
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Load distro info
|
|
||||||
if [ -f /etc/os-release ]; then
|
|
||||||
. /etc/os-release
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Running tests inside distro: ${ID:-unknown}"
|
|
||||||
|
|
||||||
# Load Nix environment if available
|
|
||||||
if [ -f "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]; then
|
|
||||||
. "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
|
|
||||||
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
PATH="/nix/var/nix/profiles/default/bin:$HOME/.nix-profile/bin:$PATH"
|
|
||||||
|
|
||||||
command -v nix >/dev/null || {
|
|
||||||
echo "ERROR: nix not found."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Mark the mounted repository as safe to avoid Git ownership errors.
|
|
||||||
# Newer Git (e.g. on Ubuntu) complains about the gitdir (/opt/src/pkgmgr/.git),
|
|
||||||
# older versions about the worktree (/opt/src/pkgmgr). Nix turns "." into the
|
|
||||||
# flake input "git+file:///opt/src/pkgmgr", which then uses Git under the hood.
|
|
||||||
if command -v git >/dev/null 2>&1; then
|
|
||||||
# Worktree path
|
|
||||||
git config --global --add safe.directory /opt/src/pkgmgr || true
|
|
||||||
# Gitdir path shown in the "dubious ownership" error
|
|
||||||
git config --global --add safe.directory /opt/src/pkgmgr/.git || true
|
|
||||||
# Ephemeral CI containers: allow all paths as a last resort
|
|
||||||
git config --global --add safe.directory "*" || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run the E2E tests inside the Nix development shell
|
|
||||||
nix develop .#default --no-write-lock-file -c \
|
|
||||||
python3 -m unittest discover \
|
|
||||||
-s /opt/src/pkgmgr/tests/e2e \
|
|
||||||
-p "$TEST_PATTERN"
|
|
||||||
'
|
|
||||||
@@ -16,48 +16,4 @@ docker run --rm \
|
|||||||
-e REINSTALL_PKGMGR=1 \
|
-e REINSTALL_PKGMGR=1 \
|
||||||
-e NIX_CONFIG="${NIX_CONFIG}" \
|
-e NIX_CONFIG="${NIX_CONFIG}" \
|
||||||
"${IMAGE}" \
|
"${IMAGE}" \
|
||||||
bash -lc '
|
bash -l scripts/test/container/env/nix.sh "${IMAGE}" "${PKGMGR_DISTRO}"
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
if command -v git >/dev/null 2>&1; then
|
|
||||||
git config --global --add safe.directory /opt/src/pkgmgr || true
|
|
||||||
git config --global --add safe.directory /opt/src/pkgmgr/.git || true
|
|
||||||
git config --global --add safe.directory "*" || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ">>> preflight: nix must exist in image"
|
|
||||||
if ! command -v nix >/dev/null 2>&1; then
|
|
||||||
echo "NO_NIX"
|
|
||||||
echo "ERROR: nix not found in image '"${IMAGE}"' (PKGMGR_DISTRO='"${PKGMGR_DISTRO}"')"
|
|
||||||
echo "HINT: Ensure Nix is installed during image build for this distro."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ">>> nix version"
|
|
||||||
nix --version
|
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
|
||||||
# Retry helper for GitHub API rate-limit (HTTP 403)
|
|
||||||
# ------------------------------------------------------------
|
|
||||||
if [[ -f /opt/src/pkgmgr/scripts/nix/lib/retry_403.sh ]]; then
|
|
||||||
# shellcheck source=./scripts/nix/lib/retry_403.sh
|
|
||||||
source /opt/src/pkgmgr/scripts/nix/lib/retry_403.sh
|
|
||||||
elif [[ -f ./scripts/nix/lib/retry_403.sh ]]; then
|
|
||||||
# shellcheck source=./scripts/nix/lib/retry_403.sh
|
|
||||||
source ./scripts/nix/lib/retry_403.sh
|
|
||||||
else
|
|
||||||
echo "ERROR: retry helper not found: scripts/nix/lib/retry_403.sh"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ">>> nix flake show"
|
|
||||||
run_with_github_403_retry nix flake show . --no-write-lock-file >/dev/null
|
|
||||||
|
|
||||||
echo ">>> nix build .#default"
|
|
||||||
run_with_github_403_retry nix build .#default --no-link --no-write-lock-file
|
|
||||||
|
|
||||||
echo ">>> nix run .#pkgmgr -- --help"
|
|
||||||
run_with_github_403_retry nix run .#pkgmgr -- --help --no-write-lock-file
|
|
||||||
|
|
||||||
echo ">>> OK: Nix flake-only test succeeded."
|
|
||||||
'
|
|
||||||
@@ -12,31 +12,13 @@ echo "[test-env-virtual] Inspect image metadata:"
|
|||||||
docker image inspect "${IMAGE}" | sed -n '1,40p'
|
docker image inspect "${IMAGE}" | sed -n '1,40p'
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
|
||||||
# Run VENV-based pkgmgr test inside container
|
|
||||||
# ------------------------------------------------------------
|
|
||||||
if OUTPUT=$(docker run --rm \
|
if OUTPUT=$(docker run --rm \
|
||||||
-e REINSTALL_PKGMGR=1 \
|
-e REINSTALL_PKGMGR=1 \
|
||||||
-v "$(pwd):/opt/src/pkgmgr" \
|
-v "$(pwd):/opt/src/pkgmgr" \
|
||||||
-w /opt/src/pkgmgr \
|
-w /opt/src/pkgmgr \
|
||||||
-e NIX_CONFIG="${NIX_CONFIG}" \
|
-e NIX_CONFIG="${NIX_CONFIG}" \
|
||||||
"${IMAGE}" \
|
"${IMAGE}" \
|
||||||
bash -lc '
|
bash -l scripts/test/container/env/virtual.sh 2>&1); then
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
echo "[test-env-virtual] Installing pkgmgr (distro package)..."
|
|
||||||
make install
|
|
||||||
|
|
||||||
echo "[test-env-virtual] Setting up Python venv..."
|
|
||||||
make setup-venv
|
|
||||||
|
|
||||||
echo "[test-env-virtual] Activating venv..."
|
|
||||||
. "$HOME/.venvs/pkgmgr/bin/activate"
|
|
||||||
|
|
||||||
echo "[test-env-virtual] Using pkgmgr from:"
|
|
||||||
command -v pkgmgr
|
|
||||||
pkgmgr --help
|
|
||||||
' 2>&1); then
|
|
||||||
|
|
||||||
echo "$OUTPUT"
|
echo "$OUTPUT"
|
||||||
echo
|
echo
|
||||||
|
|||||||
@@ -14,12 +14,4 @@ docker run --rm \
|
|||||||
-e TEST_PATTERN="${TEST_PATTERN}" \
|
-e TEST_PATTERN="${TEST_PATTERN}" \
|
||||||
-e NIX_CONFIG="${NIX_CONFIG}" \
|
-e NIX_CONFIG="${NIX_CONFIG}" \
|
||||||
"pkgmgr-${PKGMGR_DISTRO}" \
|
"pkgmgr-${PKGMGR_DISTRO}" \
|
||||||
bash -lc '
|
bash -l scripts/test/container/unittest.sh tests/integration
|
||||||
set -e;
|
|
||||||
git config --global --add safe.directory /opt/src/pkgmgr || true;
|
|
||||||
nix develop .#default --no-write-lock-file -c \
|
|
||||||
python3 -m unittest discover \
|
|
||||||
-s tests/integration \
|
|
||||||
-t /opt/src/pkgmgr \
|
|
||||||
-p "$TEST_PATTERN";
|
|
||||||
'
|
|
||||||
@@ -14,12 +14,4 @@ docker run --rm \
|
|||||||
-e TEST_PATTERN="${TEST_PATTERN}" \
|
-e TEST_PATTERN="${TEST_PATTERN}" \
|
||||||
-e NIX_CONFIG="${NIX_CONFIG}" \
|
-e NIX_CONFIG="${NIX_CONFIG}" \
|
||||||
"pkgmgr-${PKGMGR_DISTRO}" \
|
"pkgmgr-${PKGMGR_DISTRO}" \
|
||||||
bash -lc '
|
bash -l scripts/test/container/unittest.sh tests/unit
|
||||||
set -e;
|
|
||||||
git config --global --add safe.directory /opt/src/pkgmgr || true;
|
|
||||||
nix develop .#default --no-write-lock-file -c \
|
|
||||||
python3 -m unittest discover \
|
|
||||||
-s tests/unit \
|
|
||||||
-t /opt/src/pkgmgr \
|
|
||||||
-p "$TEST_PATTERN";
|
|
||||||
'
|
|
||||||
Reference in new issue
Block a user