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
This commit is contained in:
Jonathan Lebon 2016-04-22 12:39:54 -04:00 committed by Colin Walters (automation)
parent b717fd2c18
commit 5ef4898afa
2 changed files with 99 additions and 39 deletions

View File

@ -134,6 +134,18 @@ assert_file_has_content () {
fi 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() { assert_file_empty() {
if test -s "$1"; then if test -s "$1"; then
sed -e 's/^/# /' < "$1" >&2 sed -e 's/^/# /' < "$1" >&2
@ -142,6 +154,15 @@ assert_file_empty() {
fi 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 () { setup_test_repository () {
mode=$1 mode=$1
shift shift

View File

@ -26,57 +26,95 @@ fi
. $(dirname $0)/libtest.sh . $(dirname $0)/libtest.sh
echo "1..7" echo "1..20"
setup_test_repository "bare" setup_test_repository "bare"
cd ${test_tmpdir} cd ${test_tmpdir}
mkdir foo mkdir foo
cd foo cd foo
echo hi > hi mkdir -p usr/bin
ln -s hi hello echo contents > usr/bin/foo
mkdir subdir touch usr/bin/foo0
echo contents > subdir/more ln usr/bin/foo usr/bin/bar
mkdir subdir/1 ln usr/bin/foo0 usr/bin/bar0
touch subdir/1/empty ln -s foo usr/bin/sl
mkdir subdir/2 mkdir -p usr/local/bin
touch subdir/2/empty ln usr/bin/foo usr/local/bin/baz
echo not > subdir/2/notempty 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 . tar -c -z -f ../foo.tar.gz .
find . | cpio -o -H newc > ../foo.cpio
cd .. cd ..
$OSTREE commit -s "from tar" -b test-tar --tree=tar=foo.tar.gz
cat > statoverride.txt <<EOF
2048 /usr/bin/setuidme
EOF
cat > skiplist.txt <<EOF
/usr/bin/skipme
EOF
$OSTREE commit -s "from tar" -b test-tar \
--statoverride=statoverride.txt \
--skip-list=skiplist.txt \
--tree=tar=foo.tar.gz
echo "ok tar commit" echo "ok tar commit"
$OSTREE commit -s "from cpio" -b test-cpio \
--statoverride=statoverride.txt \
--skip-list=skiplist.txt \
--tree=tar=foo.cpio
echo "ok cpio commit"
cd ${test_tmpdir} assert_valid_checkout () {
$OSTREE checkout test-tar test-tar-checkout cd ${test_tmpdir}
cd test-tar-checkout $OSTREE checkout test-$1 test-$1-checkout
assert_file_has_content hi hi cd test-$1-checkout
assert_file_has_content hello hi
assert_file_has_content subdir/more contents
assert_has_file subdir/1/empty
assert_has_file subdir/2/empty
cd ${test_tmpdir}
rm -rf test-tar-checkout
echo "ok tar contents"
cd ${test_tmpdir} # basic content check
mkdir hardlinktest assert_file_has_content usr/bin/foo contents
cd hardlinktest assert_file_has_content usr/bin/bar contents
echo other > otherfile assert_file_has_content usr/local/bin/baz contents
echo foo1 > foo assert_file_empty usr/bin/foo0
ln foo bar assert_file_empty usr/bin/bar0
tar czf ${test_tmpdir}/hardlinktest.tar.gz . assert_file_empty usr/local/bin/baz0
cd ${test_tmpdir} echo "ok $1 contents"
$OSTREE commit -s 'hardlinks' -b test-hardlinks --tree=tar=hardlinktest.tar.gz
rm -rf hardlinktest
echo "ok hardlink commit"
cd ${test_tmpdir} # hardlinks
$OSTREE checkout test-hardlinks test-hardlinks-checkout assert_files_hardlinked usr/bin/foo usr/bin/bar
cd test-hardlinks-checkout assert_files_hardlinked usr/bin/foo usr/local/bin/baz
assert_file_has_content foo foo1 echo "ok $1 hardlink"
assert_file_has_content bar foo1 assert_files_hardlinked usr/bin/foo0 usr/bin/bar0
echo "ok hardlink contents" 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} cd ${test_tmpdir}
mkdir multicommit-files mkdir multicommit-files
@ -115,3 +153,4 @@ cd ${test_tmpdir}
$OSTREE checkout partial partial-checkout $OSTREE checkout partial partial-checkout
cd partial-checkout cd partial-checkout
assert_file_has_content subdir/original "original" assert_file_has_content subdir/original "original"
echo "ok tar partial commit contents"