]> git.saurik.com Git - apt.git/blame - test/test-indexes.sh
pkgAcqIndex::Done(): If we have an IMS-Hit, also rename the destination file in GzipI...
[apt.git] / test / test-indexes.sh
CommitLineData
31e1187b 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
f4782b42 10TEST_SOURCE="http://ftp.debian.org/debian unstable contrib"
31e1187b 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
81563bc1 18OPTS="-qq -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true"
31e1187b 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"
24
25[ -x "$BUILDDIR/bin/apt-get" ] || {
26 echo "please build the tree first" >&2
27 exit 1
28}
29
2aab191f 30check_update() {
31 echo "--- apt-get update $@ (no trusted keys)"
32
33 rm -f etc/apt/trusted.gpg etc/apt/secring.gpg
34 touch etc/apt/trusted.gpg etc/apt/secring.gpg
08abac55 35 find var/lib/apt/lists/ -type f | xargs -r rm
2aab191f 36 out=$($APT_GET "$@" update 2>&1)
37 echo "$out" | grep -q NO_PUBKEY
38 key=$(echo "$out" | sed -n '/NO_PUBKEY/ { s/^.*NO_PUBKEY \([[:alnum:]]\+\)$/\1/; p}')
39 # get keyring
40 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
41
42 echo "--- apt-get update $@ (with trusted keys)"
08abac55 43 find var/lib/apt/lists/ -type f | xargs -r rm
2aab191f 44 $APT_GET "$@" update
45}
46
8d60bef0 47# if $1 == "compressed", check that we have compressed indexes, otherwise
48# uncompressed ones
49check_indexes() {
2aab191f 50 echo "--- only ${1:-uncompressed} index files present"
8d60bef0 51 local F
52 if [ "$1" = "compressed" ]; then
53 ! test -e var/lib/apt/lists/*_Packages || F=1
54 ! test -e var/lib/apt/lists/*_Sources || F=1
55 test -e var/lib/apt/lists/*_Packages.gz || F=1
56 test -e var/lib/apt/lists/*_Sources.gz || F=1
57 else
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 fi
63
64 if [ -n "$F" ]; then
2aab191f 65 ls -laR var/lib/apt/lists/
8d60bef0 66 exit 1
67 fi
68}
69
2aab191f 70# test apt-cache commands
71check_cache() {
72 echo "--- apt-cache commands"
73
74 $APT_CACHE show $TEST_PKG | grep -q ^Version:
75 # again (with cache)
76 $APT_CACHE show $TEST_PKG | grep -q ^Version:
77 rm var/cache/apt/*.bin
78 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
79 # again (with cache)
80 $APT_CACHE policy $TEST_PKG | grep -q '500 http://'
81
82 TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
83 rm var/cache/apt/*.bin
84 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
85 # again (with cache)
86 $APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
87}
88
89# test apt-get install
90check_install() {
91 echo "--- apt-get install"
92
93 $APT_GET install -d $TEST_PKG
94 test -e var/cache/apt/archives/$TEST_PKG*.deb
95 $APT_GET clean
96 ! test -e var/cache/apt/archives/$TEST_PKG*.deb
97}
98
99# test apt-get source
100check_get_source() {
101 echo "--- apt-get source"
102 $APT_GET source $TEST_PKG
103 test -f $TEST_SRC_*.dsc
104 test -d $TEST_SRC-*
105 rm -r $TEST_SRC*
106}
107
108############################################################################
109# main
110############################################################################
111
112echo "===== building sandbox ====="
31e1187b 113WORKDIR=$(mktemp -d)
114trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
115cd $WORKDIR
116
117rm -fr etc var
118rm -f home
119ln -s /home home
81563bc1 120mkdir -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
31e1187b 121cp /etc/apt/trusted.gpg etc/apt
122touch var/lib/dpkg/status
f4782b42 123echo "deb $TEST_SOURCE" > etc/apt/sources.list
124echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list
31e1187b 125
81563bc1 126# specifying -o RootDir at the command line does not work for
127# etc/apt/apt.conf.d/ since it is parsed after pkgInitConfig(); $APT_CONFIG is
128# checked first, so this works
129echo 'RootDir ".";' > apt_config
130export APT_CONFIG=`pwd`/apt_config
131
2aab191f 132echo "===== uncompressed indexes ====="
8d48388e 133# first attempt should fail, no trusted GPG key
2aab191f 134check_update
8d60bef0 135check_indexes
2aab191f 136check_cache
137check_install
138check_get_source
31e1187b 139
2aab191f 140echo "--- apt-get update with preexisting indexes"
141$APT_GET update
8d60bef0 142check_indexes
31e1187b 143
2aab191f 144echo "--- apt-get update with preexisting indexes and pdiff mode"
31e1187b 145$APT_GET -o Acquire::PDiffs=true update
8d60bef0 146check_indexes
31e1187b 147
2aab191f 148echo "===== compressed indexes ====="
2aab191f 149check_update -o Acquire::GzipIndexes=true
8d60bef0 150check_indexes compressed
2aab191f 151check_cache
152check_install
153check_get_source
31e1187b 154
2aab191f 155echo "--- apt-get update with preexisting indexes"
08abac55 156$APT_GET -o Acquire::GzipIndexes=true update
321798be 157check_indexes compressed
31e1187b 158
2aab191f 159echo "--- apt-get update with preexisting indexes and pdiff mode"
08abac55 160$APT_GET -o Acquire::GzipIndexes=true -o Acquire::PDiffs=true update
321798be 161check_indexes compressed
31e1187b 162
2aab191f 163echo "===== ALL TESTS PASSED ====="