summaryrefslogtreecommitdiff
path: root/test/test-indexes.sh
blob: e826330224d619caba04f3b9f821b2445d6e6a57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/sh -e

# Test behaviour of index retrieval and usage, in particular with uncompressed
# and gzip compressed indexes.
# Author: Martin Pitt <martin.pitt@ubuntu.com>
# (C) 2010 Canonical Ltd.

BUILDDIR=$(readlink -f $(dirname $0)/../build)

TEST_SOURCE="http://ftp.debian.org/debian unstable contrib"
TEST_SOURCE_KEYID=55BE302B
GPG_KEYSERVER=gpg-keyserver.de
# should be a small package with dependencies satisfiable in TEST_SOURCE, i. e.
# ideally no depends at all
TEST_PKG="python-psyco-doc"

export LD_LIBRARY_PATH=$BUILDDIR/bin

OPTS="-o RootDir=. -o Dir::Bin::Methods=$BUILDDIR/bin/methods -o Debug::NoLocking=true"
DEBUG=""
#DEBUG="-o Debug::pkgCacheGen=true"
#DEBUG="-o Debug::pkgAcquire=true"
APT_GET="$BUILDDIR/bin/apt-get $OPTS $DEBUG"
APT_CACHE="$BUILDDIR/bin/apt-cache $OPTS $DEBUG"

[ -x "$BUILDDIR/bin/apt-get" ] || {
    echo "please build the tree first" >&2
    exit 1
}

echo "---- building sandbox----"
WORKDIR=$(mktemp -d)
trap "cd /; rm -rf $WORKDIR" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
cd $WORKDIR

rm -fr etc var
rm -f home
ln -s /home home
mkdir -p etc/apt/preferences.d etc/apt/trusted.gpg.d var/cache/apt/archives/partial var/lib/apt/lists/partial var/lib/dpkg
cp /etc/apt/trusted.gpg etc/apt
touch var/lib/dpkg/status
echo "deb $TEST_SOURCE" > etc/apt/sources.list
echo "deb-src $TEST_SOURCE" >> etc/apt/sources.list

# get keyring
gpg --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 $TEST_SOURCE_KEYID

echo "---- uncompressed update ----"
$APT_GET update
test -e var/lib/apt/lists/*_Packages
test -e var/lib/apt/lists/*_Sources
! test -e var/lib/apt/lists/*_Packages.gz
! test -e var/lib/apt/lists/*_Sources.gz

echo "---- uncompressed cache ----"
$APT_CACHE show $TEST_PKG | grep -q ^Version:
# again (with cache)
$APT_CACHE show $TEST_PKG | grep -q ^Version:
rm var/cache/apt/*.bin
$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
# again (with cache)
$APT_CACHE policy $TEST_PKG | grep -q '500 http://'

TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
rm var/cache/apt/*.bin
$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
# again (with cache)
$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:

echo "---- uncompressed install ----"
$APT_GET install -d $TEST_PKG 
test -e var/cache/apt/archives/$TEST_PKG*.deb
$APT_GET clean
! test -e var/cache/apt/archives/$TEST_PKG*.deb

echo "---- uncompressed get source ----"
$APT_GET source $TEST_PKG
test -f $TEST_SRC_*.dsc
test -d $TEST_SRC-*
rm -r $TEST_SRC*

echo "----- uncompressed update with preexisting indexes, no pdiff ----"
$APT_GET -o Acquire::PDiffs=false update
test -e var/lib/apt/lists/*_Packages
test -e var/lib/apt/lists/*_Sources
! test -e var/lib/apt/lists/*_Packages.gz
! test -e var/lib/apt/lists/*_Sources.gz

echo "----- uncompressed update with preexisting indexes, with pdiff ----"
$APT_GET -o Acquire::PDiffs=true update
test -e var/lib/apt/lists/*_Packages
test -e var/lib/apt/lists/*_Sources
! test -e var/lib/apt/lists/*_Packages.gz
! test -e var/lib/apt/lists/*_Sources.gz

echo "----- compressed update ----"
find var/lib/apt/lists/ -type f | xargs -r rm
$APT_GET -o Acquire::GzipIndexes=true update
! test -e var/lib/apt/lists/*_Packages
! test -e var/lib/apt/lists/*_Sources
test -e var/lib/apt/lists/*_Packages.gz
test -e var/lib/apt/lists/*_Sources.gz

echo "---- compressed cache ----"
$APT_CACHE show $TEST_PKG | grep -q ^Version:
# again (with cache)
$APT_CACHE show $TEST_PKG | grep -q ^Version:
rm var/cache/apt/*.bin
$APT_CACHE policy $TEST_PKG | grep -q '500 http://'
# again (with cache)
$APT_CACHE policy $TEST_PKG | grep -q '500 http://'

TEST_SRC=`$APT_CACHE show $TEST_PKG | grep ^Source: | awk '{print $2}'`
rm var/cache/apt/*.bin
$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:
# again (with cache)
$APT_CACHE showsrc $TEST_SRC | grep -q ^Binary:

echo "---- compressed install ----"
$APT_GET install -d $TEST_PKG 
! test -e var/cache/apt/archives/$TEST_PKG*.deb

echo "---- compressed get source ----"
$APT_GET source $TEST_PKG
test -f $TEST_SRC_*.dsc
test -d $TEST_SRC-*
rm -r $TEST_SRC*

echo "----- compressed update with preexisting indexes, no pdiff ----"
$APT_GET -o Acquire::PDiffs=false -o Acquire::GzipIndexes=true update
! test -e var/lib/apt/lists/*_Packages
! test -e var/lib/apt/lists/*_Sources
test -e var/lib/apt/lists/*_Packages.gz
test -e var/lib/apt/lists/*_Sources.gz

echo "----- compressed update with preexisting indexes, with pdiff ----"
$APT_GET -o Acquire::PDiffs=true -o Acquire::GzipIndexes=true update
! test -e var/lib/apt/lists/*_Packages
! test -e var/lib/apt/lists/*_Sources
test -e var/lib/apt/lists/*_Packages.gz
test -e var/lib/apt/lists/*_Sources.gz

echo "---- ALL TESTS PASSED ----"