]> git.saurik.com Git - apt.git/blame_incremental - test/test-indexes.sh
apt-pkg/contrib/fileutl.cc: Revert WriteEmpty to old behavior (LP: #613211)
[apt.git] / test / test-indexes.sh
... / ...
CommitLineData
1#!/bin/sh -e
2
3# Test behaviour of index retrieval and usage, in particular with uncompressed
4# and gzip compressed indexes.
5# Author: Martin Pitt <martin.pitt@ubuntu.com>
6# (C) 2010 Canonical Ltd.
7
8BUILDDIR=$(readlink -f $(dirname $0)/../build)
9
10TEST_SOURCE="http://ftp.debian.org/debian unstable contrib"
11GPG_KEYSERVER=gpg-keyserver.de
12# should be a small package with dependencies satisfiable in TEST_SOURCE, i. e.
13# ideally no depends at all
14TEST_PKG="python-psyco-doc"
15
16export LD_LIBRARY_PATH=$BUILDDIR/bin
17
18OPTS="-qq -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true"
19DEBUG=""
20#DEBUG="-o Debug::pkgCacheGen=true"
21#DEBUG="-o Debug::pkgAcquire=true"
22APT_GET="$BUILDDIR/bin/apt-get $OPTS $DEBUG"
23APT_CACHE="$BUILDDIR/bin/apt-cache $OPTS $DEBUG"
24APT_FTPARCHIVE="$BUILDDIR/bin/apt-ftparchive"
25
26[ -x "$BUILDDIR/bin/apt-get" ] || {
27 echo "please build the tree first" >&2
28 exit 1
29}
30
31check_update() {
32 echo "--- apt-get update $@ (no trusted keys)"
33
34 rm -f etc/apt/trusted.gpg etc/apt/secring.gpg
35 touch etc/apt/trusted.gpg etc/apt/secring.gpg
36 find var/lib/apt/lists/ -type f | xargs -r rm
37
38 # first attempt should fail, no trusted GPG key
39 out=$($APT_GET "$@" update 2>&1)
40 echo "$out" | grep -q NO_PUBKEY
41 key=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$/\1/; p}')
42
43 # get keyring
44 gpg -q --no-options --no-default-keyring --secret-keyring etc/apt/secring.gpg --trustdb-name etc/apt/trustdb.gpg --keyring etc/apt/trusted.gpg --primary-keyring etc/apt/trusted.gpg --keyserver $GPG_KEYSERVER --recv-keys $key
45
46 # now it should work
47 echo "--- apt-get update $@ (with trusted keys)"
48 find var/lib/apt/lists/ -type f | xargs -r rm
49 $APT_GET "$@" update
50}
51
52# if $1 == "compressed", check that we have compressed indexes, otherwise
53# uncompressed ones
54check_indexes() {
55 echo "--- only ${1:-uncompressed} index files present"
56 local F
57 if [ "$1" = "compressed" ]; then
58 ! test -e var/lib/apt/lists/*_Packages || F=1
59 ! test -e var/lib/apt/lists/*_Sources || F=1
60 test -e var/lib/apt/lists/*_Packages.gz || F=1
61 test -e var/lib/apt/lists/*_Sources.gz || F=1
62 else
63 test -e var/lib/apt/lists/*_Packages || F=1
64 test -e var/lib/apt/lists/*_Sources || F=1
65 ! test -e var/lib/apt/lists/*_Packages.gz || F=1
66 ! test -e var/lib/apt/lists/*_Sources.gz || F=1
67 fi
68
69 if [ -n "$F" ]; then
70 ls -laR var/lib/apt/lists/
71 exit 1
72 fi
73}
74
75# test apt-cache commands
76check_cache() {
77 echo "--- apt-cache commands"
78
79 $APT_CACHE show $TEST_PKG | grep -q ^Version:
80 # again (with cache)
81 $APT_CACHE show $TEST_PKG | grep -q ^Version:
82 rm var/cache/apt/*.bin
83 $APT_CACHE policy $TEST_PKG | egrep -q '500 (http://|file:/)'
84 # again (with cache)
85 $APT_CACHE policy $TEST_PKG | egrep -q '500 (http://|file:/)'
86
87 TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
88 rm var/cache/apt/*.bin
89 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
90 # again (with cache)
91 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
92}
93
94# test apt-get install
95check_install() {
96 echo "--- apt-get install"
97
98 $APT_GET install -d $TEST_PKG
99 test -e var/cache/apt/archives/$TEST_PKG*.deb
100 $APT_GET clean
101 ! test -e var/cache/apt/archives/$TEST_PKG*.deb
102}
103
104# test apt-get source
105check_get_source() {
106 echo "--- apt-get source"
107 # quiesce: it'll complain about not being able to verify the signature
108 $APT_GET source $TEST_PKG >/dev/null 2>&1
109 test -f $TEST_SRC_*.dsc
110 test -d $TEST_SRC-*
111 rm -r $TEST_SRC*
112}
113
114############################################################################
115# main
116############################################################################
117
118echo "===== building sandbox ====="
119WORKDIR=$(mktemp -d)
120trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
121cd $WORKDIR
122
123rm -fr etc var
124rm -f home
125ln -s /home home
126mkdir -p etc/apt/preferences.d etc/apt/trusted.gpg.d etc/apt/apt.conf.d var/cache/apt/archives/partial var/lib/apt/lists/partial var/lib/dpkg
127cp /etc/apt/trusted.gpg etc/apt
128touch var/lib/dpkg/status
129echo "deb $TEST_SOURCE" > etc/apt/sources.list
130echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list
131
132# specifying -o RootDir at the command line does not work for
133# etc/apt/apt.conf.d/ since it is parsed after pkgInitConfig(); $APT_CONFIG is
134# checked first, so this works
135echo "RootDir \"$WORKDIR\";" > apt_config
136export APT_CONFIG=`pwd`/apt_config
137
138echo "===== uncompressed indexes ====="
139check_update
140check_indexes
141check_cache
142check_install
143check_get_source
144
145echo "--- apt-get update with preexisting indexes"
146$APT_GET update
147check_indexes
148check_cache
149
150echo "--- apt-get update with preexisting indexes and pdiff mode"
151$APT_GET -o Acquire::PDiffs=true update
152check_indexes
153check_cache
154
155echo "===== compressed indexes (CLI option) ====="
156check_update -o Acquire::GzipIndexes=true
157check_indexes compressed
158check_cache
159check_install
160check_get_source
161
162echo "--- apt-get update with preexisting indexes"
163$APT_GET -o Acquire::GzipIndexes=true update
164check_indexes compressed
165check_cache
166
167echo "--- apt-get update with preexisting indexes and pdiff mode"
168$APT_GET -o Acquire::GzipIndexes=true -o Acquire::PDiffs=true update
169check_indexes compressed
170check_cache
171
172echo "===== compressed indexes (apt.conf.d option) ====="
173cat <<EOF > etc/apt/apt.conf.d/02compress-indexes
174Acquire::GzipIndexes "true";
175Acquire::CompressionTypes::Order:: "gz";
176EOF
177
178check_update
179check_indexes compressed
180check_cache
181check_install
182check_get_source
183
184echo "--- apt-get update with preexisting indexes"
185$APT_GET update
186check_indexes compressed
187check_cache
188
189echo "--- apt-get update with preexisting indexes and pdiff mode"
190$APT_GET -o Acquire::PDiffs=true update
191check_indexes compressed
192check_cache
193
194rm etc/apt/apt.conf.d/02compress-indexes
195
196echo "==== apt-ftparchive ===="
197mkdir arch
198$APT_GET install -d $TEST_PKG
199cp var/cache/apt/archives/$TEST_PKG*.deb arch/
200cd arch
201$APT_GET source -d $TEST_PKG >/dev/null 2>&1
202$APT_FTPARCHIVE packages . | gzip -9 > Packages.gz
203$APT_FTPARCHIVE sources . | gzip -9 > Sources.gz
204cd ..
205
206echo "deb file://$WORKDIR/arch /
207deb-src file://$WORKDIR/arch /" > etc/apt/sources.list
208$APT_GET clean
209
210echo "==== uncompressed indexes from local file:// archive ===="
211echo "--- apt-get update"
212$APT_GET update
213check_indexes
214check_cache
215check_get_source
216
217echo "==== compressed indexes from local file:// archive ===="
218echo "--- apt-get update"
219$APT_GET -o Acquire::GzipIndexes=true update
220# EXFAIL: file:/ URIs currently decompress even with above option
221#check_indexes compressed
222check_indexes
223check_cache
224check_get_source
225
226echo "===== ALL TESTS PASSED ====="