From 3b28dc75e097a719d2e080a0a955db7c44c3013e Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Mon, 27 Dec 2021 18:23:50 +0100 Subject: [PATCH] tests: add xbps-remove cache cleaning tests --- tests/xbps/xbps-remove/basic_test.sh | 93 ++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/tests/xbps/xbps-remove/basic_test.sh b/tests/xbps/xbps-remove/basic_test.sh index e83d7e2c..0f9fd577 100755 --- a/tests/xbps/xbps-remove/basic_test.sh +++ b/tests/xbps/xbps-remove/basic_test.sh @@ -46,7 +46,100 @@ remove_orphans_body() { atf_check_equal $? 2 } +atf_test_case clean_cache + +clean_cache_head() { + atf_set "descr" "xbps-remove(1): clean cache" +} + +clean_cache_body() { + mkdir -p repo pkg_A/B/C + touch pkg_A/ + cd repo + xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-create -A noarch -n A-1.0_2 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + mkdir -p root/etc/xbps.d root/var/db/xbps/https___localhost_ root/var/cache/xbps + cp repo/*-repodata root/var/db/xbps/https___localhost_ + atf_check_equal $? 0 + cp repo/*.xbps root/var/cache/xbps + atf_check_equal $? 0 + echo "repository=https://localhost/" >root/etc/xbps.d/localrepo.conf + xbps-remove -r root -C etc/xbps.d -dvO + atf_check_equal $? 0 + test -f root/var/cache/xbps/A-1.0_2.noarch.xbps + atf_check_equal $? 0 + test -f root/var/cache/xbps/A-1.0_1.noarch.xbps + atf_check_equal $? 1 +} + +atf_test_case clean_cache_dry_run + +clean_cache_dry_run_head() { + atf_set "descr" "xbps-remove(1): clean cache dry run" +} + +clean_cache_dry_run_body() { + mkdir -p repo pkg_A/B/C + touch pkg_A/ + cd repo + xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-create -A noarch -n A-1.0_2 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + mkdir -p root/etc/xbps.d root/var/db/xbps/https___localhost_ root/var/cache/xbps + cp repo/*-repodata root/var/db/xbps/https___localhost_ + atf_check_equal $? 0 + cp repo/*.xbps root/var/cache/xbps + atf_check_equal $? 0 + echo "repository=https://localhost/" >root/etc/xbps.d/localrepo.conf + ls -lsa root/var/cache/xbps + out="$(xbps-remove -r root -C etc/xbps.d -dvnO)" + atf_check_equal $? 0 + atf_check_equal "$out" "Removed A-1.0_1.noarch.xbps from cachedir (obsolete)" +} + +atf_test_case clean_cache_dry_run_perm + +clean_cache_dry_run_perm_head() { + atf_set "descr" "xbps-remove(1): clean cache dry run without read permissions" +} + +clean_cache_dry_run_perm_body() { + # this should print an error instead of dry deleting the files it can't read + mkdir -p repo pkg_A/B/C + touch pkg_A/ + cd repo + xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-create -A noarch -n A-1.0_2 -s "A pkg" ../pkg_A + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + mkdir -p root/etc/xbps.d root/var/db/xbps/https___localhost_ root/var/cache/xbps + cp repo/*-repodata root/var/db/xbps/https___localhost_ + atf_check_equal $? 0 + cp repo/*.xbps root/var/cache/xbps + atf_check_equal $? 0 + chmod 0000 root/var/cache/xbps/*.xbps + echo "repository=https://localhost/" >root/etc/xbps.d/localrepo.conf + out="$(xbps-remove -r root -C etc/xbps.d -dvnO)" + atf_check_equal $? 0 + atf_check_equal "$out" "Removed A-1.0_1.noarch.xbps from cachedir (obsolete)" +} + atf_init_test_cases() { atf_add_test_case remove_directory atf_add_test_case remove_orphans + atf_add_test_case clean_cache + atf_add_test_case clean_cache_dry_run + atf_add_test_case clean_cache_dry_run_perm }