]> git.saurik.com Git - apt.git/commitdiff
autorun permission tests for all apt-get update calls
authorDavid Kalnischkies <david@kalnischkies.de>
Sat, 18 Oct 2014 18:00:25 +0000 (20:00 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Mon, 20 Oct 2014 08:37:46 +0000 (10:37 +0200)
Adds some infrastructure to run tests automatically for certain
commands. The first command being 'apt-get update' (and 'apt update')
which check for correct permission and owner of the files in lists/.

Git-Dch: Ignore

test/integration/framework
test/integration/test-apt-get-download
test/integration/test-apt-update-ims
test/integration/test-apt-update-transactions

index d692f62a985701fca8c1c3ecf6805a882d87d3d5..8ccbe7f6db9bd78284a7a91c24dd177183858ca5 100644 (file)
@@ -1081,12 +1081,13 @@ testfileequal() {
 testempty() {
        msgtest "Test for no output of" "$*"
        local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
-       if $* >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
+       if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
                msgpass
        else
                cat $COMPAREFILE
                msgfail
        fi
+       aptautotest 'testempty' "$@"
 }
 
 testequal() {
@@ -1103,7 +1104,8 @@ testequal() {
        if [ -n "$MSG" ]; then
                msgtest "$MSG" "$*"
        fi
-       $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
+       "$@" 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
+       aptautotest 'testequal' "$@"
 }
 
 testequalor2() {
@@ -1114,7 +1116,7 @@ testequalor2() {
        echo "$2" > $COMPAREFILE2
        shift 2
        msgtest "Test for equality OR of" "$*"
-       $* >$COMPAREAGAINST 2>&1 || true
+       "$@" >$COMPAREAGAINST 2>&1 || true
        if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \
                checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1
        then
@@ -1126,6 +1128,7 @@ testequalor2() {
                checkdiff $COMPAREFILE2 $COMPAREAGAINST || true
                msgfail
        fi
+       aptautotest 'testequalor2' "$@"
 }
 
 testshowvirtual() {
@@ -1210,6 +1213,7 @@ testsuccess() {
                cat >&2 $OUTPUT
                msgfail "exitcode $EXITCODE"
        fi
+       aptautotest 'testsuccess' "$@"
 }
 
 testfailure() {
@@ -1227,6 +1231,7 @@ testfailure() {
        else
                msgpass
        fi
+       aptautotest 'testfailure' "$@"
 }
 
 testfilestats() {
@@ -1271,3 +1276,34 @@ pause() {
        local IGNORE
        read IGNORE
 }
+
+### The following tests are run by most test methods automatically to check
+### general things about commands executed without writing the test every time.
+
+aptautotest() {
+       local TESTCALL="$1"
+       local CMD="$2"
+       local FIRSTOPT="$3"
+       local AUTOTEST="aptautotest_$(basename "$CMD" | tr -d '-')_$(echo "$FIRSTOPT" | tr -d '-')"
+       if command -v $AUTOTEST >/dev/null; then
+               shift 3
+               # save and restore the *.output files from other tests
+               # as we might otherwise override them in these automatic tests
+               rm -rf rootdir/tmp-before
+               mv rootdir/tmp rootdir/tmp-before
+               mkdir rootdir/tmp
+               $AUTOTEST "$TESTCALL" "$@"
+               rm -rf rootdir/tmp-aptautotest
+               mv rootdir/tmp rootdir/tmp-aptautotest
+               mv rootdir/tmp-before rootdir/tmp
+       fi
+}
+
+aptautotest_aptget_update() {
+       if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi
+       # all copied files are properly chmodded
+       find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -maxdepth 1 -type f | while read file; do
+               testfilestats "$file" '%U:%G:%a' '=' "${USER}:${USER}:644"
+       done
+}
+aptautotest_apt_update() { aptautotest_aptget_update "$@"; }
index 9a154e5fb99ce9e38977078d4157501ce9d7d5bf..48086d808883cea281b8a239d848975629a71e52 100755 (executable)
@@ -32,11 +32,6 @@ done
 
 testsuccess aptget update
 
-# all copied files are properly chmodded
-find rootdir/var/lib/apt/lists -type f | while read file; do
-       testaccessrights "$file" '644'
-done
-
 testdownload() {
        local APT="$2"
        if [ -n "$3" ]; then
index c74058c5d537366624660520b5b78a5aedd6be99..6746837a4ab2555b4aba882f7a14bbb1bdfd5a9a 100755 (executable)
@@ -54,7 +54,7 @@ Hit http://localhost:8080 unstable/main amd64 Packages
 Hit http://localhost:8080 unstable/main Translation-en
 Reading package lists..."
 
-find aptarchive -name "InRelease" | xargs rm -f
+find aptarchive -name 'InRelease' -delete
 
 echo "Acquire::GzipIndexes "0";" > rootdir/etc/apt/apt.conf.d/02compressindex
 runtest
@@ -78,9 +78,8 @@ Hit http://localhost:8080 unstable/main Translation-en
 Reading package lists...
 W: The data from 'http://localhost:8080 unstable Release.gpg' is not signed. Packages from that repository can not be authenticated."
 
-find aptarchive -name "Release.gpg" | xargs rm -f
+find aptarchive -name 'Release.gpg' -delete
 
-echo 'Acquire::AllowInsecureRepositories "1";' > rootdir/etc/apt/apt.conf.d/insecure.conf
 echo "Acquire::GzipIndexes "0";" > rootdir/etc/apt/apt.conf.d/02compressindex
 runtest
 
index 2d5d9e721d7a32cd23f20c7fb6194199bacf9cd8..2fc5f1dadfbfd589ecfe7f7584a0142a75126268 100755 (executable)
@@ -27,11 +27,6 @@ restorefile() {
 
 listscheck() {
        testequal "$(cat $1)" ls rootdir/var/lib/apt/lists
-       # all copied files are properly chmodded
-       find rootdir/var/lib/apt/lists -maxdepth 1 -type f | while read file; do
-               testaccessrights "$file" '644'
-               testfilestats "$file" '%U' '!=' '_apt'
-       done
 }
 
 testrun() {