From b3026da9e793aa1755563a7148d05f58860f1b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= Date: Wed, 8 Sep 2021 22:26:19 +0200 Subject: [PATCH] tests: add test for conf_files links --- tests/xbps/libxbps/shell/conf_files_test.sh | 393 ++++++++++++++++++++ 1 file changed, 393 insertions(+) diff --git a/tests/xbps/libxbps/shell/conf_files_test.sh b/tests/xbps/libxbps/shell/conf_files_test.sh index 1c87d27f..1aef7ce8 100644 --- a/tests/xbps/libxbps/shell/conf_files_test.sh +++ b/tests/xbps/libxbps/shell/conf_files_test.sh @@ -456,6 +456,388 @@ tc10_body() { atf_check_equal $? 0 } +# 1st link test: modified configuration link on disk, unmodified on upgrade. +# result: keep link as is on disk. +atf_test_case tcl1 + +tcl1_head() { + atf_set "descr" "Tests for configuration link handling: on-disk modified, upgrade unmodified" +} + +tcl1_body() { + atf_expect_fail "not implemented" + mkdir repo + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + xbps-install -C null.conf -r rootdir --repository=$PWD -yvd a + atf_check_equal $? 0 + + ln -sf custom rootdir/cf1.conf + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.2_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + rm -rf pkg_a + atf_check_equal $? 0 + xbps-install -C null.conf -r rootdir --repository=$PWD -yuvd + atf_check_equal $? 0 + atf_check_equal "$(readlink rootdir/cf1.conf)" custom +} + +# 2nd test: modified configuration link on disk, modified on upgrade. +# result: install new link as ".new-". +atf_test_case tcl2 + +tcl2_head() { + atf_set "descr" "Tests for configuration link handling: on-disk modified, upgrade modified" +} + +tcl2_body() { + atf_expect_fail "not implemented" + mkdir repo + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + xbps-install -C null.conf -r rootdir --repository=$PWD -yvd a + atf_check_equal $? 0 + + ln -sf custom rootdir/cf1.conf + mkdir pkg_a + ln -s updated pkg_a/cf1.conf + xbps-create -A noarch -n a-0.2_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + rm -rf pkg_a + atf_check_equal $? 0 + xbps-install -C null.conf -r rootdir --repository=$PWD -yuvd + atf_check_equal $? 0 + atf_check_equal "$(readlink rootdir/cf1.conf)" custom + test -h rootdir/cf1.conf.new-0.2_1 + atf_check_equal $? 0 +} + +# 3rd test: modified configuration link on disk, unmodified on upgrade. +# result: keep link on disk as is. +atf_test_case tcl3 + +tcl3_head() { + atf_set "descr" "Tests for configuration link handling: on-disk modified, upgrade unmodified" +} + +tcl3_body() { + atf_expect_fail "not implemented" + mkdir repo + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + xbps-install -C null.conf -r rootdir --repository=$PWD -yvd a + atf_check_equal $? 0 + + ln -sf custom rootdir/cf1.conf + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.2_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + rm -rf pkg_a + atf_check_equal $? 0 + xbps-install -C null.conf -r rootdir --repository=$PWD -yuvd + atf_check_equal $? 0 + atf_check_equal "$(readlink rootdir/cf1.conf)" custom +} + +# 4th test: existent link on disk; new package defines configuration link. +# result: keep on-disk link as is, install new conf link as file.new-. +atf_test_case tcl4 + +tcl4_head() { + atf_set "descr" "Tests for configuration link handling: existent on-disk, new install" +} + +tcl4_body() { + atf_expect_fail "not implemented" + mkdir repo + cd repo + mkdir -p pkg_a/etc + ln -s original pkg_a/etc/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/etc/cf1.conf" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + mkdir -p rootdir/etc + ln -s custom rootdir/etc/cf1.conf + xbps-install -C null.conf -r rootdir --repository=$PWD -yvd a + atf_check_equal $? 0 + atf_check_equal "$(readlink rootdir/etc/cf1.conf)" custom + atf_check_equal "$(readlink rootdir/etc/cf1.conf.new-0.1_1)" original +} + +# 5th test: configuration link replaced with regular file on disk, modified on upgrade. +# result: install new link as ".new-". +atf_test_case tcl5 + +tcl5_head() { + atf_set "descr" "Tests for configuration link handling: on-disk replaced with symlink, upgrade modified" +} + +tcl5_body() { + atf_expect_fail "not implemented" + mkdir repo + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $?a 0a + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $?b 0b + xbps-install -C null.conf -r rootdir --repository=$PWD -yvd a + atf_check_equal $?c 0c + + rm rootdir/cf1.conf + echo 'key=value' > rootdir/cf1.conf + + mkdir pkg_a + ln -s updated pkg_a/cf1.conf + xbps-create -A noarch -n a-0.2_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $?d 0d + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $?e 0e + rm -rf pkg_a + + xbps-install -C null.conf -r rootdir --repository=$PWD -yuvd + atf_check_equal $?f 0f + + atf_check_equal "$(cat rootdir/cf1.conf)" "key=value" + test -f rootdir/cf1.conf + atf_check_equal $?g 0g + test -h rootdir/cf1.conf.new-0.2_1 + atf_check_equal $?h 0h +} + +# 6th test: unmodified configuration link on disk, keepconf=true, modified on upgrade. +# result: install new link as ".new-". +atf_test_case tcl6 + +tcl6_head() { + atf_set "descr" "Tests for configuration link handling: on-disk unmodified, keepconf=true, upgrade modified" +} + +tcl6_body() { + atf_expect_fail "not implemented" + mkdir repo + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + mkdir -p rootdir/xbps.d + echo "keepconf=true" > rootdir/xbps.d/keepconf.conf + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yvd a + atf_check_equal $? 0 + + cd repo + mkdir pkg_a + ln -s updated pkg_a/cf1.conf + xbps-create -A noarch -n a-0.2_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + rm -rf pkg_a + atf_check_equal $? 0 + cd .. + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yuvd + atf_check_equal $? 0 + atf_check_equal "$(readlink rootdir/cf1.conf)" original + atf_check_equal "$(readlink rootdir/cf1.conf.new-0.2_1)" updated +} + +# 7th test: unmodified configuration link on disk, modified on upgrade. +# result: update link +atf_test_case tcl7 + +tcl7_head() { + atf_set "descr" "Tests for configuration link handling: on-disk unmodified, upgrade modified" +} + +tcl7_body() { + mkdir repo + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yvd a + atf_check_equal $? 0 + + cd repo + mkdir pkg_a + ln -s updated pkg_a/cf1.conf + xbps-create -A noarch -n a-0.2_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + rm -rf pkg_a + atf_check_equal $? 0 + cd .. + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yuvd + atf_check_equal $? 0 + atf_check_equal "$(readlink rootdir/cf1.conf)" updated +} + +# 8th test: modified configuration link on disk to same as updated, modified on upgrade. +# result: keep on-disk link as is, don't install new conf link as file.new-. +atf_test_case tcl8 + +tcl8_head() { + atf_set "descr" "Tests for configuration link handling: on-disk modified, matches upgrade" +} + +tcl8_body() { + mkdir repo + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yvd a + atf_check_equal $? 0 + ln -sf improved rootdir/cf1.conf + + cd repo + mkdir pkg_a + ln -s improved pkg_a/cf1.conf + xbps-create -A noarch -n a-0.2_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + rm -rf pkg_a + atf_check_equal $? 0 + cd .. + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yuvd + atf_check_equal $? 0 + atf_check_equal "$(readlink rootdir/cf1.conf)" improved + test '!' -e rootdir/cf1.conf.new-0.2_1 + atf_check_equal $? 0 +} + +# 9th test: removed configuration link on disk, unmodified on upgrade. +# result: install link, don't install new conf link as file.new-. +atf_test_case tcl9 + +tcl9_head() { + atf_set "descr" "Tests for configuration link handling: on-disk removed, upgrade unmodified" +} + +tcl9_body() { + mkdir repo + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yvd a + atf_check_equal $? 0 + rm rootdir/cf1.conf + + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.2_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + rm -rf pkg_a + atf_check_equal $? 0 + cd .. + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yuvd + atf_check_equal $? 0 + atf_check_equal "$(readlink rootdir/cf1.conf)" original + test '!' -e rootdir/cf1.conf.new-0.2_1 + atf_check_equal $? 0 +} + + +# 10th test: removed configuration link on disk, modified on upgrade. +# result: install link, don't install new conf link as file.new-. +atf_test_case tcl10 + +tcl10_head() { + atf_set "descr" "Tests for configuration link handling: on-disk removed, upgrade modified" +} + +tcl10_body() { + mkdir repo + cd repo + mkdir pkg_a + ln -s original pkg_a/cf1.conf + xbps-create -A noarch -n a-0.1_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + rm -rf pkg_a + xbps-rindex -d -a $PWD/*.xbps + atf_check_equal $? 0 + cd .. + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yvd a + atf_check_equal $? 0 + rm rootdir/cf1.conf + + cd repo + mkdir pkg_a + ln -s updated pkg_a/cf1.conf + xbps-create -A noarch -n a-0.2_1 -s "pkg a" --config-files "/cf1.conf" pkg_a + atf_check_equal $? 0 + xbps-rindex -d -a $PWD/*.xbps + rm -rf pkg_a + atf_check_equal $? 0 + cd .. + + xbps-install -C xbps.d -r rootdir --repository=$PWD/repo -yuvd + atf_check_equal $? 0 + atf_check_equal "$(readlink rootdir/cf1.conf)" updated + test '!' -e rootdir/cf1.conf.new-0.2_1 + atf_check_equal $? 0 +} + atf_init_test_cases() { atf_add_test_case tc1 atf_add_test_case tc2 @@ -467,4 +849,15 @@ atf_init_test_cases() { atf_add_test_case tc8 atf_add_test_case tc9 atf_add_test_case tc10 + + atf_add_test_case tcl1 + atf_add_test_case tcl2 + atf_add_test_case tcl3 + atf_add_test_case tcl4 + atf_add_test_case tcl5 + atf_add_test_case tcl6 + atf_add_test_case tcl7 + atf_add_test_case tcl8 + atf_add_test_case tcl9 + atf_add_test_case tcl10 }