From 5ef4898afa17653f45982b15554ae8a8d5e973f2 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 22 Apr 2016 12:39:54 -0400 Subject: [PATCH] tests/test-libarchive.sh: add more test - Test both tar and cpio archives - Test more hardlink corner cases - Test symlinks more rigorously - Test stat override - Test skip list Closes: #275 Approved by: cgwalters --- tests/libtest.sh | 21 +++++++ tests/test-libarchive.sh | 117 ++++++++++++++++++++++++++------------- 2 files changed, 99 insertions(+), 39 deletions(-) diff --git a/tests/libtest.sh b/tests/libtest.sh index 4d403a93..34976e23 100755 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -134,6 +134,18 @@ assert_file_has_content () { fi } +assert_symlink_has_content () { + if ! test -L "$1"; then + echo 1>&2 "File '$1' is not a symbolic link" + exit 1 + fi + if ! readlink "$1" | grep -q -e "$2"; then + sed -e 's/^/# /' < "$1" >&2 + echo 1>&2 "Symbolic link '$1' doesn't match regexp '$2'" + exit 1 + fi +} + assert_file_empty() { if test -s "$1"; then sed -e 's/^/# /' < "$1" >&2 @@ -142,6 +154,15 @@ assert_file_empty() { fi } +assert_files_hardlinked() { + f1=$(stat -c %i $1) + f2=$(stat -c %i $2) + if [ "$f1" != "$f2" ]; then + echo 1>&2 "Files '$1' and '$2' are not hardlinked" + exit 1 + fi +} + setup_test_repository () { mode=$1 shift diff --git a/tests/test-libarchive.sh b/tests/test-libarchive.sh index 7309ffd2..0c579459 100755 --- a/tests/test-libarchive.sh +++ b/tests/test-libarchive.sh @@ -26,57 +26,95 @@ fi . $(dirname $0)/libtest.sh -echo "1..7" +echo "1..20" setup_test_repository "bare" + cd ${test_tmpdir} mkdir foo cd foo -echo hi > hi -ln -s hi hello -mkdir subdir -echo contents > subdir/more -mkdir subdir/1 -touch subdir/1/empty -mkdir subdir/2 -touch subdir/2/empty -echo not > subdir/2/notempty +mkdir -p usr/bin +echo contents > usr/bin/foo +touch usr/bin/foo0 +ln usr/bin/foo usr/bin/bar +ln usr/bin/foo0 usr/bin/bar0 +ln -s foo usr/bin/sl +mkdir -p usr/local/bin +ln usr/bin/foo usr/local/bin/baz +ln usr/bin/foo0 usr/local/bin/baz0 +ln usr/bin/sl usr/local/bin/slhl +touch usr/bin/setuidme +touch usr/bin/skipme tar -c -z -f ../foo.tar.gz . +find . | cpio -o -H newc > ../foo.cpio + cd .. -$OSTREE commit -s "from tar" -b test-tar --tree=tar=foo.tar.gz + +cat > statoverride.txt < skiplist.txt < otherfile -echo foo1 > foo -ln foo bar -tar czf ${test_tmpdir}/hardlinktest.tar.gz . -cd ${test_tmpdir} -$OSTREE commit -s 'hardlinks' -b test-hardlinks --tree=tar=hardlinktest.tar.gz -rm -rf hardlinktest -echo "ok hardlink commit" + # basic content check + assert_file_has_content usr/bin/foo contents + assert_file_has_content usr/bin/bar contents + assert_file_has_content usr/local/bin/baz contents + assert_file_empty usr/bin/foo0 + assert_file_empty usr/bin/bar0 + assert_file_empty usr/local/bin/baz0 + echo "ok $1 contents" -cd ${test_tmpdir} -$OSTREE checkout test-hardlinks test-hardlinks-checkout -cd test-hardlinks-checkout -assert_file_has_content foo foo1 -assert_file_has_content bar foo1 -echo "ok hardlink contents" + # hardlinks + assert_files_hardlinked usr/bin/foo usr/bin/bar + assert_files_hardlinked usr/bin/foo usr/local/bin/baz + echo "ok $1 hardlink" + assert_files_hardlinked usr/bin/foo0 usr/bin/bar0 + assert_files_hardlinked usr/bin/foo0 usr/local/bin/baz0 + echo "ok $1 hardlink to empty files" + + # symlinks + assert_symlink_has_content usr/bin/sl foo + assert_file_has_content usr/bin/sl contents + echo "ok $1 symlink" + # ostree checkout doesn't care if two symlinks are actually hardlinked + # together (which is fine). checking that it's also a symlink is good enough. + assert_symlink_has_content usr/local/bin/slhl foo + echo "ok $1 hardlink to symlink" + + # stat override + test -u usr/bin/setuidme + echo "ok $1 setuid" + + # skip list + test ! -f usr/bin/skipme + echo "ok $1 file skip" + + cd ${test_tmpdir} + rm -rf test-$1-checkout +} + +assert_valid_checkout tar +assert_valid_checkout cpio cd ${test_tmpdir} mkdir multicommit-files @@ -115,3 +153,4 @@ cd ${test_tmpdir} $OSTREE checkout partial partial-checkout cd partial-checkout assert_file_has_content subdir/original "original" +echo "ok tar partial commit contents"