diff options
Diffstat (limited to 'test/cases/librechroot.bats')
-rw-r--r-- | test/cases/librechroot.bats | 179 |
1 files changed, 82 insertions, 97 deletions
diff --git a/test/cases/librechroot.bats b/test/cases/librechroot.bats index e476f6f..7e8504d 100644 --- a/test/cases/librechroot.bats +++ b/test/cases/librechroot.bats @@ -1,96 +1,85 @@ -#!/usr/bin/env roundup +load ../lib/common -describe librechroot -. ./test-common.sh - -it_creates_repo_for_new_chroots() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -l "$roundup_test_name" run test -r /repo/repo.db +@test "librechroot creates repo for new chroots" { + require network sudo || skip + testsudo librechroot -l "$BATS_TEST_NAME" run test -r /repo/repo.db } -it_cleans_the_local_repo_correctly() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -l "$roundup_test_name" make - testsudo librechroot -l "$roundup_test_name" clean-repo - testsudo librechroot -l "$roundup_test_name" run test -r /repo/repo.db +@test "librechroot cleans the local repo correctly" { + require network sudo || skip + testsudo librechroot -l "$BATS_TEST_NAME" make + testsudo librechroot -l "$BATS_TEST_NAME" clean-repo + testsudo librechroot -l "$BATS_TEST_NAME" run test -r /repo/repo.db # TODO: inspect /repo/* more } -it_respects_exit_status_if_out_isnt_a_tty() ( - require network sudo || return 0 +@test "librechroot respects exit status if out isnt a tty" ( + require network sudo || skip set -o pipefail - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - { testsudo librechroot -l "$roundup_test_name" run bash -c 'exit 3' | cat; } || status=$? + { testsudo librechroot -l "$BATS_TEST_NAME" run bash -c 'exit 3' | cat; } || status=$? [[ $status == 3 ]] ) -it_creates_ca_certificates() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -l "$roundup_test_name" run test -r /etc/ssl/certs/ca-certificates.crt +@test "librechroot creates ca certificates" { + require network sudo || skip + testsudo librechroot -l "$BATS_TEST_NAME" run test -r /etc/ssl/certs/ca-certificates.crt } -it_disables_networking_when_requested() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty +@test "librechroot disables networking when requested" { + require network sudo || skip - testsudo librechroot -l "$roundup_test_name" run curl https://repo.parabola.nu/ >/dev/null - not testsudo librechroot -l "$roundup_test_name" -N run curl https://repo.parabola.nu/ >/dev/null + testsudo librechroot -l "$BATS_TEST_NAME" run curl https://repo.parabola.nu/ >/dev/null + not testsudo librechroot -l "$BATS_TEST_NAME" -N run curl https://repo.parabola.nu/ >/dev/null } -it_handles_CHROOTEXTRAPKG_correctly() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty +@test "librechroot handles CHROOTEXTRAPKG correctly" { + require network sudo || skip - not testsudo librechroot -l "$roundup_test_name" run lsof + not testsudo librechroot -l "$BATS_TEST_NAME" run lsof echo "CHROOTEXTRAPKG=(lsof)" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf - testsudo librechroot -l "$roundup_test_name" install-name lsof - testsudo librechroot -l "$roundup_test_name" clean-pkgs - testsudo librechroot -l "$roundup_test_name" run lsof + testsudo librechroot -l "$BATS_TEST_NAME" install-name lsof + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + testsudo librechroot -l "$BATS_TEST_NAME" run lsof echo "CHROOTEXTRAPKG=()" >> "$XDG_CONFIG_HOME"/libretools/chroot.conf - testsudo librechroot -l "$roundup_test_name" clean-pkgs - not testsudo librechroot -l "$roundup_test_name" run lsof + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + not testsudo librechroot -l "$BATS_TEST_NAME" run lsof } -it_obeys_depends_in_PKGBUILD() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty +@test "librechroot obeys depends in PKGBUILD" { + require network sudo || skip # Make sure it's not in the base install - not testsudo librechroot -l "$roundup_test_name" run lsof + not testsudo librechroot -l "$BATS_TEST_NAME" run lsof # Make sure it removes it without the PKGBUILD - testsudo librechroot -l "$roundup_test_name" install-name lsof - testsudo librechroot -l "$roundup_test_name" run lsof - testsudo librechroot -l "$roundup_test_name" clean-pkgs - not testsudo librechroot -l "$roundup_test_name" run lsof + testsudo librechroot -l "$BATS_TEST_NAME" install-name lsof + testsudo librechroot -l "$BATS_TEST_NAME" run lsof + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + not testsudo librechroot -l "$BATS_TEST_NAME" run lsof # Make sure it leaves it with the PKGBUILD - testsudo librechroot -l "$roundup_test_name" install-name lsof - testsudo librechroot -l "$roundup_test_name" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat librechroot.d/PKGBUILD-arches)" + testsudo librechroot -l "$BATS_TEST_NAME" install-name lsof + testsudo librechroot -l "$BATS_TEST_NAME" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat fixtures/librechroot/PKGBUILD-arches)" # uid=99 is 'nobody', but we say '99' because sometimes 'nobody' is uid=65534. # https://bugs.archlinux.org/task/56828 - testsudo librechroot -l "$roundup_test_name" run chown -R 99:99 /startdir - testsudo librechroot -l "$roundup_test_name" clean-pkgs - testsudo librechroot -l "$roundup_test_name" run lsof + testsudo librechroot -l "$BATS_TEST_NAME" run chown -R 99:99 /startdir + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + testsudo librechroot -l "$BATS_TEST_NAME" run lsof } -it_can_install_libretools_with_chcleanup() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty +@test "librechroot can install libretools with chcleanup" { + require network sudo || skip - not testsudo librechroot -l "$roundup_test_name" run test -f /usr/bin/chcleanup - testsudo librechroot -l "$roundup_test_name" run mkdir /startdir - testsudo librechroot -l "$roundup_test_name" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat librechroot.d/PKGBUILD-libretools)" + not testsudo librechroot -l "$BATS_TEST_NAME" run test -f /usr/bin/chcleanup + testsudo librechroot -l "$BATS_TEST_NAME" run mkdir /startdir + testsudo librechroot -l "$BATS_TEST_NAME" run sh -c 'printf "%s\n" "$1" > /startdir/PKGBUILD' -- "$(cat fixtures/librechroot/PKGBUILD-libretools)" # uid=99 is 'nobody', but we say '99' because sometimes 'nobody' is uid=65534. # https://bugs.archlinux.org/task/56828 - testsudo librechroot -l "$roundup_test_name" run chown -R 99:99 /startdir - testsudo librechroot -l "$roundup_test_name" clean-pkgs - testsudo librechroot -l "$roundup_test_name" run test -f /usr/bin/chcleanup + testsudo librechroot -l "$BATS_TEST_NAME" run chown -R 99:99 /startdir + testsudo librechroot -l "$BATS_TEST_NAME" clean-pkgs + testsudo librechroot -l "$BATS_TEST_NAME" run test -f /usr/bin/chcleanup } -it_displays_help_as_normal_user() { +@test "librechroot displays help as normal user" { rm -rf "$XDG_CONFIG_HOME" LC_ALL=C librechroot help >$tmpdir/stdout 2>$tmpdir/stderr @@ -98,36 +87,35 @@ it_displays_help_as_normal_user() { empty $tmpdir/stderr } -it_otherwise_fails_as_normal_user() { - librechroot -l "$roundup_test_name" run true >$tmpdir/stdout 2>$tmpdir/stderr || status=$? +@test "librechroot otherwise fails as normal user" { + librechroot -l "$BATS_TEST_NAME" run true >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] empty $tmpdir/stdout not empty $tmpdir/stderr } -it_displays_help_and_fails_with_0_args() { - LC_ALL=C librechroot -l "$roundup_test_name" >$tmpdir/stdout 2>$tmpdir/stderr || status=$? +@test "librechroot displays help and fails with 0 args" { + LC_ALL=C librechroot -l "$BATS_TEST_NAME" >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] empty $tmpdir/stdout [[ "$(sed -n 2p $tmpdir/stderr)" =~ Usage:.* ]] } -it_obeys_the_n_flag() { - require network sudo || return 0 +@test "librechroot obeys the n flag" { + require network sudo || skip - not test -f "$chrootdir/$roundup_test_name/$roundup_test_name/$roundup_test_name.stamp" + not test -f "$chrootdir/$BATS_TEST_NAME/$BATS_TEST_NAME/$BATS_TEST_NAME.stamp" - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -n "$roundup_test_name" -l "$roundup_test_name" run touch /"$roundup_test_name.stamp" + testsudo librechroot -n "$BATS_TEST_NAME" -l "$BATS_TEST_NAME" run touch /"$BATS_TEST_NAME.stamp" - test -f "$chrootdir/$roundup_test_name/$roundup_test_name/$roundup_test_name.stamp" + test -f "$chrootdir/$BATS_TEST_NAME/$BATS_TEST_NAME/$BATS_TEST_NAME.stamp" } # requires sudo so we know it's not failing because it needs root -it_fails_for_unknown_commands() { - require sudo || return 0 +@test "librechroot fails for unknown commands" { + require sudo || skip testsudo librechroot phony >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -136,8 +124,8 @@ it_fails_for_unknown_commands() { } # requires sudo so we know it's not failing because it needs root -it_fails_for_unknown_flags() { - require sudo || return 0 +@test "librechroot fails for unknown flags" { + require sudo || skip testsudo librechroot -q >$tmpdir/stdout 2>$tmpdir/stderr || status=$? [[ $status != 0 ]] @@ -145,8 +133,8 @@ it_fails_for_unknown_flags() { not empty $tmpdir/stderr } -it_fails_when_syncing_a_copy_with_itself() { - require sudo || return 0 +@test "librechroot fails when syncing a copy with itself" { + require sudo || skip testsudo timeout 5 librechroot -l root sync || status=$? case $status in 0|124|137) # success|timeout+TERM|timeout+KILL @@ -156,36 +144,33 @@ it_fails_when_syncing_a_copy_with_itself() { esac } -it_deletes_copies() { - require network sudo || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -l "$roundup_test_name" make - test -d "$chrootdir/default/$roundup_test_name" - testsudo librechroot -l "$roundup_test_name" delete - not test -e "$chrootdir/default/$roundup_test_name" +@test "librechroot deletes copies" { + require network sudo || skip + testsudo librechroot -l "$BATS_TEST_NAME" make + test -d "$chrootdir/default/$BATS_TEST_NAME" + testsudo librechroot -l "$BATS_TEST_NAME" delete + not test -e "$chrootdir/default/$BATS_TEST_NAME" } -it_deletes_subvolumes_recursively() { - require network sudo btrfs || return 0 - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - testsudo librechroot -l "$roundup_test_name" make - testsudo librechroot -l "$roundup_test_name" install-name btrfs-progs - test -d "$chrootdir/default/$roundup_test_name" - not test -e "$chrootdir/default/$roundup_test_name/var/subvolume" - testsudo librechroot -l "$roundup_test_name" run btrfs subvolume create /var/subvolume - test -d "$chrootdir/default/$roundup_test_name/var/subvolume" - testsudo librechroot -l "$roundup_test_name" delete - not test -e "$chrootdir/default/$roundup_test_name" +@test "librechroot deletes subvolumes recursively" { + require network sudo btrfs || skip + testsudo librechroot -l "$BATS_TEST_NAME" make + testsudo librechroot -l "$BATS_TEST_NAME" install-name btrfs-progs + test -d "$chrootdir/default/$BATS_TEST_NAME" + not test -e "$chrootdir/default/$BATS_TEST_NAME/var/subvolume" + testsudo librechroot -l "$BATS_TEST_NAME" run btrfs subvolume create /var/subvolume + test -d "$chrootdir/default/$BATS_TEST_NAME/var/subvolume" + testsudo librechroot -l "$BATS_TEST_NAME" delete + not test -e "$chrootdir/default/$BATS_TEST_NAME" } -it_cleans_up_TMPDIR() { - require network sudo || return 0 +@test "librechroot cleans up TMPDIR" { + require network sudo || skip local dir="$tmpdir/tmp" mkdir -- "$dir" - libremessages msg 'Creating a chroot, may take a few minutes' &>/dev/tty - TMPDIR=$dir testsudo librechroot -l "$roundup_test_name" -A x86_64 make + TMPDIR=$dir testsudo librechroot -l "$BATS_TEST_NAME" -A x86_64 make # Make sure $dir is now empty rmdir -- "$dir" |