diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml index 6edc9b5..6c82be0 100644 --- a/.github/workflows/pr_check.yml +++ b/.github/workflows/pr_check.yml @@ -6,6 +6,7 @@ on: branches: - "main" pull_request: + workflow_dispatch: jobs: ci: @@ -51,17 +52,27 @@ jobs: - uses: docker/setup-buildx-action@v2 - - name: Build openSUSE Tumbleweed image + name: Build openSUSE Tumbleweed image with zypper uses: docker/build-push-action@v4 with: cache-from: type=gha cache-to: type=gha,mode=max context: test/ - file: test/Dockerfile + file: test/zypper.dockerfile load: true push: false - tags: local/cnf-ci:latest - + tags: local/cnf-ci-zypper:latest + - + name: Build openSUSE Tumbleweed image with dnf5 + uses: docker/build-push-action@v4 + with: + cache-from: type=gha + cache-to: type=gha,mode=max + context: test/ + file: test/dnf5.dockerfile + load: true + push: false + tags: local/cnf-ci-dnf5:latest - name: Integration test run: ./test/bats/bin/bats ./test diff --git a/README.md b/README.md index 7b6e200..13ca679 100644 --- a/README.md +++ b/README.md @@ -77,30 +77,48 @@ cmake ## **Integration tests** -Integration tests runs inside docker image tagged `local/cnf-ci`. It is built as a part of Github Action and can be built locally as `cd test; docker build -t local/cnf-ci:latest .` +Integration tests runs inside docker images tagged `local/cnf-ci-zypper` and `local/cnf-ci-dnf5`. these are built as a part of Github Action and can be built locally with: -The testing itself is wrapped in [bats](https://github.com/bats-core/bats-core) and in order to make it run, one needs to initialize the git submodules (`git submodule init`). Then tests can be executed using a following command +```.sh +for pm in zypper dnf5; do + docker build -t local/cnf-ci-$pm:latest -f test/$pm.dockerfile test +done +``` + +The testing itself is wrapped in [bats](https://github.com/bats-core/bats-core) and in order to make it run, one needs to initialize the git submodules (`git submodule update --init`). Then tests can be executed using a following command ```.sh ./test/bats/bin/bats ./test/ ``` > ```.log > test.bats -> ✓ root: installed /usr/bin/rpm -> > ✓ root: installed /usr/sbin/sysctl -> ✓ root: not installed xnake -> ✓ root: not installed make -> ✓ root: not installed cmake -> ✓ nonroot: not installed cmake -> ✓ nonroot: bash without handler: not installed cmake -> ✓ nonroot: bash handler: not installed cmake -> ✓ nonroot: zsh without handler: not installed cmake -> ✓ nonroot: zsh handler: not installed cmake -> ✓ nonroot: fish handler: not installed cmake -> ✓ issue26: do not list not installable files -> -> 12 tests, 0 failures -> ``` +> ✓ zypper root: installed /usr/bin/rpm +> ✓ zypper root: installed /usr/sbin/sysctl +> ✓ zypper root: not installed xnake +> ✓ zypper root: not installed make +> ✓ zypper root: not installed cmake +> ✓ zypper nonroot: not installed cmake +> ✓ zypper nonroot: bash without handler: not installed cmake +> ✓ zypper nonroot: bash handler: not installed cmake +> ✓ zypper nonroot: zsh without handler: not installed cmake +> ✓ zypper nonroot: zsh handler: not installed cmake +> ✓ zypper nonroot: fish handler: not installed cmake +> ✓ zypper issue26: do not list not installable files +> ✓ dnf5 root: installed /usr/bin/rpm +> ✓ dnf5 root: installed /usr/sbin/sysctl +> ✓ dnf5 root: not installed xnake +> ✓ dnf5 root: not installed make +> ✓ dnf5 root: not installed cmake +> ✓ dnf5 nonroot: not installed cmake +> ✓ dnf5 nonroot: bash without handler: not installed cmake +> ✓ dnf5 nonroot: bash handler: not installed cmake +> ✓ dnf5 nonroot: zsh without handler: not installed cmake +> ✓ dnf5 nonroot: zsh handler: not installed cmake +> ✓ dnf5 nonroot: fish handler: not installed cmake +> ✓ dnf5 issue26: do not list not installable files +> +> 24 tests, 0 failures +``` Every test can be executed on a command line. The `root.sh` wrapper mounts the binary to `/usr/bin/cnf` and bash/fish integrations. diff --git a/test/bats b/test/bats index 360c1ea..5da6687 160000 --- a/test/bats +++ b/test/bats @@ -1 +1 @@ -Subproject commit 360c1ea5371622132ab669e9cb9687d21298699b +Subproject commit 5da66876b8b619235aee1eb3e54954eaca88059b diff --git a/test/dnf5.dockerfile b/test/dnf5.dockerfile new file mode 100644 index 0000000..cca43b9 --- /dev/null +++ b/test/dnf5.dockerfile @@ -0,0 +1,25 @@ +# Tumbleweed based CI image for cnf integration testing with dnf5 +FROM registry.opensuse.org/opensuse/tumbleweed + +ADD passwd /etc/passwd +ADD group /etc/group +ADD --chown=65532:65532 nonroot /home/nonroot/whoami + +RUN zypper refresh +# dnf5 completely fails to work without the libcurl4 package, yet it isn't transitvely required, recommended, or suggested +RUN zypper --non-interactive install --no-recommends dnf5 libcurl4 rpm-repos-openSUSE-Tumbleweed +RUN dnf5 --assumeyes remove zypper libzypp +# Ensure zypper's cache and settings aren't installed +RUN rm -rf /etc/zypp /var/cache/zypp/ /var/lib/zypp + +# The rest here is the equivalent of Zypper-Dockerfile, but changed to use dnf5 +# Equivelent to zypper addlock +RUN echo excludepkgs=busybox dbus diffutils pam-config perl-base systemd groff man >> /etc/dnf/dnf.conf +# --setopt install_weak_deps=False is equivalent to to zypper --no-recommends +RUN dnf5 --setopt install_weak_deps=False --assumeyes install zsh fish libsolv1 +# Equivalent of zypper addrepo +RUN curl -O https://download.opensuse.org/repositories/GNOME:/Next/openSUSE_Factory/GNOME:Next.repo --output-dir /etc/dnf/repos.d/ +# Equivalent of zypper refresh (note that the default dnf5 settings don't check GPG-keys) +RUN dnf5 makecache + +WORKDIR /src diff --git a/test/root.sh b/test/root.sh index be93c76..a554dcb 100755 --- a/test/root.sh +++ b/test/root.sh @@ -26,10 +26,12 @@ VOLUMES[1]="--volume ${CNF_SRC}:/usr/bin/command-not-found:ro" VOLUMES[2]="--volume ${BASH_CNF}:/usr/etc/bash_command_not_found:ro" VOLUMES[3]="--volume ${ZSH_CNF}:/usr/etc/zsh_command_not_found:ro" +PM=$1 +shift docker \ run \ --tty \ --rm \ --user "${USER}" \ ${VOLUMES[*]} \ - local/cnf-ci:latest "${@}" + local/cnf-ci-$PM:latest "${@}" \ No newline at end of file diff --git a/test/test.bats b/test/test.bats index eba419c..2e6b8c1 100644 --- a/test/test.bats +++ b/test/test.bats @@ -2,7 +2,7 @@ setup() { load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' - bats_require_minimum_version 1.5.0 + bats_require_minimum_version 1.11.0 # get the containing directory of this file # use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0, @@ -12,65 +12,85 @@ setup() { PATH="$DIR/../test:$PATH" } -@test "root: installed /usr/bin/rpm" { - run root.sh '/usr/bin/cnf' 'rpm' - assert_output --partial "Absolute path to 'rpm' is '/usr/bin/rpm'. Please check your \$PATH variable to see whether it contains the mentioned path." +last_id=0 +# Dynamically make a test: the description is $1, and the body is stdin +function make_test { + name=test_$last_id + last_id=$((last_id + 1)) + eval function "$name" $'{\n' $(cat) $'\n}' + bats_test_function --description "$1" -- "$name" } -@test "root: installed /usr/sbin/sysctl" { - run root.sh '/usr/bin/cnf' 'sysctl' +for PM in zypper dnf5; do + +make_test "$PM root: installed /usr/bin/rpm" <