Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- "main"
pull_request:
workflow_dispatch:

jobs:
ci:
Expand Down Expand Up @@ -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
Expand Down
52 changes: 35 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/bats
Submodule bats updated 50 files
+1 −1 .github/workflows/codespell.yml
+2 −2 .github/workflows/dependency-review.yml
+4 −4 .github/workflows/release.yml
+7 −7 .github/workflows/release_dockerhub.yml
+3 −3 .github/workflows/scorecard.yml
+46 −28 .github/workflows/tests.yml
+6 −2 .readthedocs.yml
+2 −2 Dockerfile
+23 −15 README.md
+13 −0 bin/bats
+1 −1 contrib/rpm/bats.spec
+19 −1 docs/CHANGELOG.md
+4 −0 docs/list-links.py
+24 −0 docs/source/assets/README.md
+55 −0 docs/source/assets/dark_mode_bat.svg
+98 −0 docs/source/assets/dark_mode_cube.svg
+75 −0 docs/source/assets/dark_mode_wordmark_lowercase.svg
+80 −0 docs/source/assets/dark_mode_wordmark_uppercase.svg
+99 −0 docs/source/assets/light_mode_bat.svg
+90 −0 docs/source/assets/light_mode_cube.svg
+79 −0 docs/source/assets/light_mode_wordmark_lowercase.svg
+48 −0 docs/source/assets/light_mode_wordmark_uppercase.svg
+4 −2 docs/source/conf.py
+3 −1 docs/source/faq.rst
+1 −1 docs/source/installation.rst
+2 −2 docs/source/warnings/BW02.rst
+2 −2 docs/source/warnings/BW03.rst
+1 −1 install.sh
+2 −1 lib/bats-core/preprocessing.bash
+40 −17 lib/bats-core/test_functions.bash
+50 −28 lib/bats-core/tracing.bash
+1 −1 libexec/bats-core/bats
+7 −1 libexec/bats-core/bats-exec-file
+21 −184 libexec/bats-core/bats-exec-suite
+19 −5 libexec/bats-core/bats-exec-test
+5 −1 libexec/bats-core/bats-format-junit
+310 −0 libexec/bats-core/bats-gather-tests
+14 −10 libexec/bats-core/bats-preprocess
+1 −1 package.json
+66 −148 test/bats.bats
+136 −0 test/filter.bats
+28 −0 test/fixtures/bats/dynamic_test_registration.bats
+8 −0 test/fixtures/bats/preserve_IFS/helper.bash
+11 −0 test/fixtures/bats/preserve_IFS/setup_suite.bash
+15 −0 test/fixtures/bats/preserve_IFS/test.bats
+1 −1 test/fixtures/bats/test_with_slash.bats
+5 −5 test/junit-formatter.bats
+7 −5 test/tagging.bats
+3 −0 test/test_helper.bash
+1 −0 test/timeout.bats
25 changes: 25 additions & 0 deletions test/dnf5.dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion test/root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "${@}"
94 changes: 57 additions & 37 deletions test/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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" <<EOF
run root.sh $PM '/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."
EOF

make_test "$PM root: installed /usr/sbin/sysctl" <<EOF
run root.sh $PM '/usr/bin/cnf' 'sysctl'
assert_output --partial "Absolute path to 'sysctl' is '/usr/sbin/sysctl', so running it may require superuser privileges (eg. root)."
}
EOF

@test "root: not installed xnake" {
run -127 root.sh '/usr/bin/cnf' 'xnake'
make_test "$PM root: not installed xnake" <<EOF
run -127 root.sh $PM '/usr/bin/cnf' 'xnake'
assert_output --partial " xnake: command not found"
}
EOF

@test "root: not installed make" {
run root.sh '/usr/bin/cnf' 'make'
make_test "$PM root: not installed make" <<EOF
run root.sh $PM '/usr/bin/cnf' 'make'
assert_output --partial "The program 'make' can be found in the following package:"
}
assert_output --partial "sudo $PM install"
EOF

@test "root: not installed cmake" {
run root.sh '/usr/bin/cnf' 'cmake'
make_test "$PM root: not installed cmake" <<EOF
run root.sh $PM '/usr/bin/cnf' 'cmake'
assert_output --partial "The program 'cmake' can be found in following packages:"
}
assert_output --partial "sudo $PM install"
EOF

@test "nonroot: not installed cmake" {
run nonroot.sh '/usr/bin/cnf' 'cmake'
make_test "$PM nonroot: not installed cmake" <<EOF
run nonroot.sh $PM '/usr/bin/cnf' 'cmake'
assert_output --partial "The program 'cmake' can be found in following packages:"
}
assert_output --partial "sudo $PM install"
EOF

@test "nonroot: bash without handler: not installed cmake" {
run -127 nonroot.sh bash -c "cmake"
make_test "$PM nonroot: bash without handler: not installed cmake" <<EOF
run -127 nonroot.sh $PM bash -c "cmake"
assert_output --partial "bash: line 1: cmake: command not found"
}
EOF

@test "nonroot: bash handler: not installed cmake" {
run -127 nonroot.sh bash -c "source /usr/etc/bash_command_not_found; cmake"
make_test "$PM nonroot: bash handler: not installed cmake" <<EOF
run -127 nonroot.sh $PM bash -c "source /usr/etc/bash_command_not_found; cmake"
assert_output --partial "The program 'cmake' can be found in following packages:"
}
assert_output --partial "sudo $PM install"
EOF

@test "nonroot: zsh without handler: not installed cmake" {
run -127 nonroot.sh zsh -c "cmake"
make_test "$PM nonroot: zsh without handler: not installed cmake" <<EOF
run -127 nonroot.sh $PM zsh -c "cmake"
assert_output --partial "zsh:1: command not found: cmake"
}
EOF

@test "nonroot: zsh handler: not installed cmake" {
run -0 nonroot.sh zsh -c "source /usr/etc/zsh_command_not_found; cmake"
make_test "$PM nonroot: zsh handler: not installed cmake" <<EOF
run -0 nonroot.sh $PM zsh -c "source /usr/etc/zsh_command_not_found; cmake"
assert_output --partial "The program 'cmake' can be found in following packages:"
}
assert_output --partial "sudo $PM install"
EOF

@test "nonroot: fish handler: not installed cmake" {
run -127 nonroot.sh fish -c 'source /usr/share/fish/functions/fish_command_not_found.fish; cmake'
make_test "$PM nonroot: fish handler: not installed cmake" <<EOF
run -127 nonroot.sh $PM fish -c 'source /usr/share/fish/functions/fish_command_not_found.fish; cmake'
assert_output --partial "The program 'cmake' can be found in following packages:"
}
assert_output --partial "sudo $PM install"
EOF

@test "issue26: do not list not installable files" {
run root.sh '/usr/bin/cnf' 'fractal'
make_test "$PM issue26: do not list not installable files" <<EOF
run root.sh $PM '/usr/bin/cnf' 'fractal'
assert_output --partial "sudo $PM install"
pkg_lines="$(printf '%s\n' "$output" | grep -c -E '^ \*')"
[ "$pkg_lines" -eq 2 ]
}
EOF

# TODO: install i18n

done
2 changes: 1 addition & 1 deletion test/Dockerfile → test/zypper.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Tumbleweed based CI image for cnf integration testing
# Tumbleweed based CI image for cnf integration testing with zypper
FROM registry.opensuse.org/opensuse/tumbleweed

ADD passwd /etc/passwd
Expand Down