From 9648be4a265fa59c715c4c274d8aea82c2f39151 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 8 Dec 2025 01:40:36 +0100 Subject: [PATCH] Refactor test pipeline: introduce separate unit/e2e workflows, fix Dockerfile, update Makefile test targets, and move integration tests to tests/e2e. Conversation reference: https://chatgpt.com/share/69361e70-4d74-800f-acd7-51548ac3fa37 --- .github/workflows/test-e2e.yml | 25 +++++++ .github/workflows/{test.yml => test-unit.yml} | 8 +-- Dockerfile | 20 +++--- Makefile | 70 +++++++++++-------- tests/{integration => e2e}/__init__.py | 0 ...ed_test_integration_install_all_shallow.py | 0 ...test_integration_install_pkgmgr_shallow.py | 0 7 files changed, 77 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/test-e2e.yml rename .github/workflows/{test.yml => test-unit.yml} (67%) rename tests/{integration => e2e}/__init__.py (100%) rename tests/{integration => e2e}/deactivated_test_integration_install_all_shallow.py (100%) rename tests/{integration => e2e}/test_integration_install_pkgmgr_shallow.py (100%) diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml new file mode 100644 index 0000000..65ff794 --- /dev/null +++ b/.github/workflows/test-e2e.yml @@ -0,0 +1,25 @@ +name: Test package-manager (e2e) + +on: + push: + branches: + - main + - master + - develop + - "*" + pull_request: + +jobs: + test-e2e: + runs-on: ubuntu-latest + timeout-minutes: 60 # E2E + all distros can be heavier + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Show Docker version + run: docker version + + - name: Run E2E tests via make (all distros) + run: make test-e2e diff --git a/.github/workflows/test.yml b/.github/workflows/test-unit.yml similarity index 67% rename from .github/workflows/test.yml rename to .github/workflows/test-unit.yml index 209723e..9c8154c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test-unit.yml @@ -1,4 +1,4 @@ -name: Test package-manager +name: Test package-manager (unit) on: push: @@ -10,7 +10,7 @@ on: pull_request: jobs: - test: + test-unit: runs-on: ubuntu-latest timeout-minutes: 30 @@ -21,5 +21,5 @@ jobs: - name: Show Docker version run: docker version - - name: Run tests via make (builds Docker image and runs unit + integration tests) - run: make test + - name: Run unit tests via make (Arch container) + run: make test-unit diff --git a/Dockerfile b/Dockerfile index ae3f8a8..4cbd173 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,8 @@ RUN set -e; \ base-devel \ git \ nix \ - rsync && \ + rsync \ + python && \ pacman -Scc --noconfirm; \ \ # -------------------------------------------------------- @@ -118,25 +119,23 @@ RUN set -e; \ echo "Installing Nix on CentOS (single-user, as root, no build-users-group)..." && \ HOME=/root NIX_INSTALLER_NO_MODIFY_PROFILE=1 sh /tmp/nix-install --no-daemon && \ rm -f /tmp/nix-install; \ - \ - # -------------------------------------------------------- - # Unknown distro - # -------------------------------------------------------- else \ echo "Unsupported base image: ${ID}" && exit 1; \ fi -# Nix CLI behavior (used later in tests) +# ------------------------------------------------------------ +# Nix environment defaults +# ------------------------------------------------------------ ENV NIX_CONFIG="experimental-features = nix-command flakes" ENV PATH="/root/.nix-profile/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" # ------------------------------------------------------------ -# Create unprivileged build user (used on Arch for makepkg) +# Unprivileged user for building Arch packages # ------------------------------------------------------------ RUN useradd -m builder # ------------------------------------------------------------ -# Build stage — only active on Arch +# Build stage (for Arch) — optional, installs package-manager inside image # ------------------------------------------------------------ WORKDIR /build COPY . . @@ -154,13 +153,10 @@ RUN set -e; \ rm -rf /build # ------------------------------------------------------------ -# Runtime working directory for the mounted repository +# Runtime working directory and dev entrypoint # ------------------------------------------------------------ WORKDIR /src -# ------------------------------------------------------------ -# Development entry script -# ------------------------------------------------------------ COPY scripts/docker-entry-dev.sh /usr/local/bin/docker-entry-dev.sh RUN chmod +x /usr/local/bin/docker-entry-dev.sh diff --git a/Makefile b/Makefile index 4c5dab0..37554e9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: install setup uninstall aur_builder_setup \ - test build build-no-cache + test build build-no-cache test-unit test-e2e # ------------------------------------------------------------ # Local Nix cache directories in the repo @@ -72,22 +72,47 @@ build: done # ------------------------------------------------------------ -# Test target: run tests in all three images +# Test targets # ------------------------------------------------------------ -test: build + +# Unit tests: only in Arch container (fastest feedback) +test-unit: build + @echo "============================================================" + @echo ">>> Running UNIT tests in Arch container" + @echo "============================================================" + docker run --rm \ + -v "$$(pwd):/src" \ + --workdir /src \ + --entrypoint bash \ + "package-manager-test-arch" \ + -c '\ + set -e; \ + if [ -f /etc/os-release ]; then . /etc/os-release; fi; \ + echo "Detected container distro: $${ID:-unknown} (like: $${ID_LIKE:-})"; \ + echo "Running Python unit tests (tests/unit)..."; \ + git config --global --add safe.directory /src || true; \ + cd /src; \ + export PYTHONPATH=/src:$${PYTHONPATH}; \ + python -m unittest discover \ + -s tests/unit \ + -t /src \ + -p "test_*.py"; \ + ' + +# End-to-end tests: run in all distros via Nix devShell (tests/e2e) +test-e2e: build @echo "Ensuring Docker Nix volumes exist (auto-created if missing)..." - @echo "Running tests inside Nix devShell with cached store for all distros: $(DISTROS)" + @echo "Running E2E tests inside Nix devShell with cached store for all distros: $(DISTROS)" @for distro in $(DISTROS); do \ echo "============================================================"; \ - echo ">>> Running tests in container for distro: $$distro"; \ + echo ">>> Running E2E tests in container for distro: $$distro"; \ echo "============================================================"; \ - # Nur für Arch /nix als Volume mounten, bei anderen Distros nicht, \ - # damit die im Image installierte Nix-Installation sichtbar bleibt. \ + # Only for Arch: mount /nix as volume, for others use image-installed Nix \ if [ "$$distro" = "arch" ]; then \ - NIX_STORE_MOUNT='-v $(NIX_STORE_VOLUME):/nix'; \ + NIX_STORE_MOUNT="-v $(NIX_STORE_VOLUME):/nix"; \ else \ - NIX_STORE_MOUNT=''; \ + NIX_STORE_MOUNT=""; \ fi; \ docker run --rm \ -v "$$(pwd):/src" \ @@ -100,20 +125,6 @@ test: build set -e; \ if [ -f /etc/os-release ]; then . /etc/os-release; fi; \ echo "Detected container distro: $${ID:-unknown} (like: $${ID_LIKE:-})"; \ - \ - # Arch-only: rebuild Arch package inside the container \ - if [ "$${ID}" = "arch" ]; then \ - echo "Remove existing Arch package-manager (if any)..."; \ - pacman -Rns --noconfirm package-manager || true; \ - echo "Rebuild Arch package from /src..."; \ - rm -f /src/package-manager-*.pkg.tar.* || true; \ - chown -R builder:builder /src; \ - su builder -c "cd /src && makepkg -sf --noconfirm --clean"; \ - pacman -U --noconfirm /src/package-manager-*.pkg.tar.*; \ - else \ - echo "Non-Arch distro – skipping Arch package rebuild."; \ - fi; \ - \ echo "Preparing Nix environment..."; \ 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"; \ @@ -125,7 +136,6 @@ test: build export PATH; \ echo "PATH is now:"; \ echo "$$PATH"; \ - \ NIX_CMD=""; \ if command -v nix >/dev/null 2>&1; then \ echo "Found nix on PATH:"; \ @@ -141,26 +151,26 @@ test: build fi; \ done; \ fi; \ - \ if [ -z "$$NIX_CMD" ]; then \ echo "ERROR: nix binary not found anywhere – cannot run devShell"; \ exit 1; \ fi; \ - \ echo "Using Nix command: $$NIX_CMD"; \ - echo "Run tests inside Nix devShell..."; \ - git config --global --add safe.directory /src; \ + echo "Run E2E tests inside Nix devShell (tests/e2e)..."; \ + git config --global --add safe.directory /src || true; \ cd /src; \ "$$NIX_CMD" develop .#default --no-write-lock-file -c \ python3 -m unittest discover \ - -s /src/tests \ + -s /src/tests/e2e \ -p "test_*.py"; \ ' || exit $$?; \ done +# Combined test target for local + CI (unit + e2e) +test: build test-unit test-e2e # ------------------------------------------------------------ -# Installer for host systems (your original logic) +# Installer for host systems (original logic) # ------------------------------------------------------------ install: @if [ -n "$$IN_NIX_SHELL" ]; then \ diff --git a/tests/integration/__init__.py b/tests/e2e/__init__.py similarity index 100% rename from tests/integration/__init__.py rename to tests/e2e/__init__.py diff --git a/tests/integration/deactivated_test_integration_install_all_shallow.py b/tests/e2e/deactivated_test_integration_install_all_shallow.py similarity index 100% rename from tests/integration/deactivated_test_integration_install_all_shallow.py rename to tests/e2e/deactivated_test_integration_install_all_shallow.py diff --git a/tests/integration/test_integration_install_pkgmgr_shallow.py b/tests/e2e/test_integration_install_pkgmgr_shallow.py similarity index 100% rename from tests/integration/test_integration_install_pkgmgr_shallow.py rename to tests/e2e/test_integration_install_pkgmgr_shallow.py