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
This commit is contained in:
25
.github/workflows/test-e2e.yml
vendored
Normal file
25
.github/workflows/test-e2e.yml
vendored
Normal file
@@ -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
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Test package-manager
|
name: Test package-manager (unit)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -10,7 +10,7 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test-unit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
|
|
||||||
@@ -21,5 +21,5 @@ jobs:
|
|||||||
- name: Show Docker version
|
- name: Show Docker version
|
||||||
run: docker version
|
run: docker version
|
||||||
|
|
||||||
- name: Run tests via make (builds Docker image and runs unit + integration tests)
|
- name: Run unit tests via make (Arch container)
|
||||||
run: make test
|
run: make test-unit
|
||||||
20
Dockerfile
20
Dockerfile
@@ -20,7 +20,8 @@ RUN set -e; \
|
|||||||
base-devel \
|
base-devel \
|
||||||
git \
|
git \
|
||||||
nix \
|
nix \
|
||||||
rsync && \
|
rsync \
|
||||||
|
python && \
|
||||||
pacman -Scc --noconfirm; \
|
pacman -Scc --noconfirm; \
|
||||||
\
|
\
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
@@ -118,25 +119,23 @@ RUN set -e; \
|
|||||||
echo "Installing Nix on CentOS (single-user, as root, no build-users-group)..." && \
|
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 && \
|
HOME=/root NIX_INSTALLER_NO_MODIFY_PROFILE=1 sh /tmp/nix-install --no-daemon && \
|
||||||
rm -f /tmp/nix-install; \
|
rm -f /tmp/nix-install; \
|
||||||
\
|
|
||||||
# --------------------------------------------------------
|
|
||||||
# Unknown distro
|
|
||||||
# --------------------------------------------------------
|
|
||||||
else \
|
else \
|
||||||
echo "Unsupported base image: ${ID}" && exit 1; \
|
echo "Unsupported base image: ${ID}" && exit 1; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Nix CLI behavior (used later in tests)
|
# ------------------------------------------------------------
|
||||||
|
# Nix environment defaults
|
||||||
|
# ------------------------------------------------------------
|
||||||
ENV NIX_CONFIG="experimental-features = nix-command flakes"
|
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"
|
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
|
RUN useradd -m builder
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# Build stage — only active on Arch
|
# Build stage (for Arch) — optional, installs package-manager inside image
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
COPY . .
|
COPY . .
|
||||||
@@ -154,13 +153,10 @@ RUN set -e; \
|
|||||||
rm -rf /build
|
rm -rf /build
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# Runtime working directory for the mounted repository
|
# Runtime working directory and dev entrypoint
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
|
||||||
# Development entry script
|
|
||||||
# ------------------------------------------------------------
|
|
||||||
COPY scripts/docker-entry-dev.sh /usr/local/bin/docker-entry-dev.sh
|
COPY scripts/docker-entry-dev.sh /usr/local/bin/docker-entry-dev.sh
|
||||||
RUN chmod +x /usr/local/bin/docker-entry-dev.sh
|
RUN chmod +x /usr/local/bin/docker-entry-dev.sh
|
||||||
|
|
||||||
|
|||||||
70
Makefile
70
Makefile
@@ -1,5 +1,5 @@
|
|||||||
.PHONY: install setup uninstall aur_builder_setup \
|
.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
|
# Local Nix cache directories in the repo
|
||||||
@@ -72,22 +72,47 @@ build:
|
|||||||
done
|
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 "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 \
|
@for distro in $(DISTROS); do \
|
||||||
echo "============================================================"; \
|
echo "============================================================"; \
|
||||||
echo ">>> Running tests in container for distro: $$distro"; \
|
echo ">>> Running E2E tests in container for distro: $$distro"; \
|
||||||
echo "============================================================"; \
|
echo "============================================================"; \
|
||||||
# Nur für Arch /nix als Volume mounten, bei anderen Distros nicht, \
|
# Only for Arch: mount /nix as volume, for others use image-installed Nix \
|
||||||
# damit die im Image installierte Nix-Installation sichtbar bleibt. \
|
|
||||||
if [ "$$distro" = "arch" ]; then \
|
if [ "$$distro" = "arch" ]; then \
|
||||||
NIX_STORE_MOUNT='-v $(NIX_STORE_VOLUME):/nix'; \
|
NIX_STORE_MOUNT="-v $(NIX_STORE_VOLUME):/nix"; \
|
||||||
else \
|
else \
|
||||||
NIX_STORE_MOUNT=''; \
|
NIX_STORE_MOUNT=""; \
|
||||||
fi; \
|
fi; \
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
-v "$$(pwd):/src" \
|
-v "$$(pwd):/src" \
|
||||||
@@ -100,20 +125,6 @@ test: build
|
|||||||
set -e; \
|
set -e; \
|
||||||
if [ -f /etc/os-release ]; then . /etc/os-release; fi; \
|
if [ -f /etc/os-release ]; then . /etc/os-release; fi; \
|
||||||
echo "Detected container distro: $${ID:-unknown} (like: $${ID_LIKE:-})"; \
|
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..."; \
|
echo "Preparing Nix environment..."; \
|
||||||
if [ -f "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]; then \
|
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"; \
|
. "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"; \
|
||||||
@@ -125,7 +136,6 @@ test: build
|
|||||||
export PATH; \
|
export PATH; \
|
||||||
echo "PATH is now:"; \
|
echo "PATH is now:"; \
|
||||||
echo "$$PATH"; \
|
echo "$$PATH"; \
|
||||||
\
|
|
||||||
NIX_CMD=""; \
|
NIX_CMD=""; \
|
||||||
if command -v nix >/dev/null 2>&1; then \
|
if command -v nix >/dev/null 2>&1; then \
|
||||||
echo "Found nix on PATH:"; \
|
echo "Found nix on PATH:"; \
|
||||||
@@ -141,26 +151,26 @@ test: build
|
|||||||
fi; \
|
fi; \
|
||||||
done; \
|
done; \
|
||||||
fi; \
|
fi; \
|
||||||
\
|
|
||||||
if [ -z "$$NIX_CMD" ]; then \
|
if [ -z "$$NIX_CMD" ]; then \
|
||||||
echo "ERROR: nix binary not found anywhere – cannot run devShell"; \
|
echo "ERROR: nix binary not found anywhere – cannot run devShell"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi; \
|
fi; \
|
||||||
\
|
|
||||||
echo "Using Nix command: $$NIX_CMD"; \
|
echo "Using Nix command: $$NIX_CMD"; \
|
||||||
echo "Run tests inside Nix devShell..."; \
|
echo "Run E2E tests inside Nix devShell (tests/e2e)..."; \
|
||||||
git config --global --add safe.directory /src; \
|
git config --global --add safe.directory /src || true; \
|
||||||
cd /src; \
|
cd /src; \
|
||||||
"$$NIX_CMD" develop .#default --no-write-lock-file -c \
|
"$$NIX_CMD" develop .#default --no-write-lock-file -c \
|
||||||
python3 -m unittest discover \
|
python3 -m unittest discover \
|
||||||
-s /src/tests \
|
-s /src/tests/e2e \
|
||||||
-p "test_*.py"; \
|
-p "test_*.py"; \
|
||||||
' || exit $$?; \
|
' || exit $$?; \
|
||||||
done
|
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:
|
install:
|
||||||
@if [ -n "$$IN_NIX_SHELL" ]; then \
|
@if [ -n "$$IN_NIX_SHELL" ]; then \
|
||||||
|
|||||||
Reference in New Issue
Block a user