]> git.saurik.com Git - apt.git/blob - test/integration/test-apt-ftparchive-src-cachedb
test: Use :$(id -gn) instead of :root (when run as root)
[apt.git] / test / integration / test-apt-ftparchive-src-cachedb
1 #!/bin/sh
2 set -e
3
4 assert_correct_sources_file() {
5 testsuccessequal "Package: bar
6 Format: 3.0 (native)
7 Binary: bar
8 Architecture: all
9 Version: 1.0
10 Directory: pool/main
11 Package-List:
12 bar deb admin extra
13 Files:
14 7b57dd065e51de5905288a5104d4bef5 406 bar_1.0.dsc
15 d41d8cd98f00b204e9800998ecf8427e 0 bar_1.0.tar.gz
16 Checksums-Sha1:
17 17a40b76715f393ab7fd6485c9392a02f1adf903 406 bar_1.0.dsc
18 da39a3ee5e6b4b0d3255bfef95601890afd80709 0 bar_1.0.tar.gz
19 Checksums-Sha256:
20 d9d7507f66a89258b6920aca47747d7a30e0e64b09ecabbf02b2efbdabf840a9 406 bar_1.0.dsc
21 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 bar_1.0.tar.gz
22 Checksums-Sha512:
23 ee0a9bfb6614159b45203fc29487d4f37387993ca0e6d6f27b80010498f3731d75753188ece307508ae9af0259bd11a6af15a1a38f0b87dbd5ea1273b7a7d53e 406 bar_1.0.dsc
24 cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e 0 bar_1.0.tar.gz
25
26 Package: foo
27 Format: 3.0 (native)
28 Binary: foo
29 Architecture: all
30 Version: 1.0
31 Directory: pool/main
32 Package-List:
33 foo deb admin extra
34 Files:
35 d144826e6f02831c1933e910c92cd7e0 171 foo_1.0.dsc
36 d41d8cd98f00b204e9800998ecf8427e 0 foo_1.0.tar.gz
37 Checksums-Sha1:
38 979306aa3ccff3d61bba062bb6977e2493c6f907 171 foo_1.0.dsc
39 da39a3ee5e6b4b0d3255bfef95601890afd80709 0 foo_1.0.tar.gz
40 Checksums-Sha256:
41 8c780af8b5a6d5b3c2e2f9518940beebea52ac6d6ad7b52c082dc925cfe5b532 171 foo_1.0.dsc
42 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 foo_1.0.tar.gz
43 Checksums-Sha512:
44 3da0240fd764657c2f3661b4d750578a9a99b0580591b133756379d48117ebda87a5ed2467f513200d6e7eaf51422cbe91c15720eef7fb4bba2cc8ff81ebc547 171 foo_1.0.dsc
45 cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e 0 foo_1.0.tar.gz
46 " aptsortpkgs ./aptarchive/dists/test/main/source/Sources -o APT::SortPkgs::Source=true
47 }
48
49 create_source_files() {
50 NAME="$1"
51 REQUEST_CLEARSIGN="$2"
52
53 TARFILE="aptarchive/pool/main/${NAME}_1.0.tar.gz"
54 DSC_FILE="aptarchive/pool/main/${NAME}_1.0.dsc"
55 touch $TARFILE
56 if [ "$REQUEST_CLEARSIGN" = "CLEARSIGN" ]; then
57 printf -- "-----BEGIN PGP SIGNED MESSAGE-----\n\n" > $DSC_FILE
58 fi
59 cat >> $DSC_FILE << EOF
60 Format: 3.0 (native)
61 Source: $NAME
62 Binary: $NAME
63 Architecture: all
64 Version: 1.0
65 Package-List:
66 $NAME deb admin extra
67 Files:
68 $(md5sum $TARFILE|cut -f1 -d' ') $(stat --print="%s" $TARFILE) ${NAME}_1.0.tar.gz
69 EOF
70 if [ "$REQUEST_CLEARSIGN" = "CLEARSIGN" ]; then
71 cat >> $DSC_FILE <<EOF
72
73 -----BEGIN PGP SIGNATURE-----
74 Version: GnuPG v1.4.11 (GNU/Linux)
75
76 iEYEARECAAYFAk3k/VoACgkQliSD4VZixzQxlgCgpav7j68z48qNTDFuT9fLqwT5
77 DFwAoIXatJFENEC371bMKTkUKlwZxQEk
78 =iI9V
79 -----END PGP SIGNATURE-----
80 EOF
81 fi
82 }
83
84 create_clearsigned_source_files() {
85 NAME="$1"
86 create_source_files "$NAME" "CLEARSIGN"
87 }
88
89 #
90 # main()
91 #
92 TESTDIR="$(readlink -f "$(dirname "$0")")"
93 . "$TESTDIR/framework"
94 setupenvironment
95 configarchitecture "i386"
96 confighashes 'MD5' 'SHA1' 'SHA256' 'SHA512'
97
98 msgtest 'Test apt-ftparchive source with missing hashes in .dsc'
99
100 mkdir -p aptarchive/pool/main
101 create_source_files foo
102 create_clearsigned_source_files bar
103
104 mkdir -p aptarchive/dists/test/main/i18n/
105 mkdir -p aptarchive/dists/test/main/source/
106
107 mkdir aptarchive-overrides
108 mkdir aptarchive-cache
109
110 msgtest 'generate with --db option'
111 cd aptarchive
112 aptftparchive --db ./test.db sources pool/main/ -o APT::FTPArchive::ShowCacheMisses=1 > dists/test/main/source/Sources 2>stats-out.txt && msgpass || msgfail
113 testsuccess grep Misses stats-out.txt
114 testfileequal '../rootdir/tmp/testsuccess.output' ' Misses in Cache: 2'
115 cd ..
116 assert_correct_sources_file
117
118 msgtest 'generate with --db option (again to ensure its in the cache)'
119 cd aptarchive
120 aptftparchive --db ./test.db sources pool/main/ -o APT::FTPArchive::ShowCacheMisses=1 > dists/test/main/source/Sources 2>stats-out.txt && msgpass || msgfail
121 testsuccess grep Misses stats-out.txt
122 testfileequal '../rootdir/tmp/testsuccess.output' ' Misses in Cache: 0'
123 cd ..
124 assert_correct_sources_file
125
126 # get ready for the "apt-ftparchive generate" command
127 cat > apt-ftparchive.conf <<"EOF"
128 Dir {
129 ArchiveDir "./aptarchive";
130 OverrideDir "./aptarchive-overrides";
131 CacheDir "./aptarchive-cache";
132 };
133
134 Default {
135 Packages::Compress ". gzip bzip2";
136 Contents::Compress ". gzip bzip2";
137 LongDescription "false";
138 };
139
140 TreeDefault {
141 BinCacheDB "packages-$(SECTION)-$(ARCH).db";
142 SrcCacheDB "sources-$(SECTION).db";
143
144 Directory "pool/$(SECTION)";
145 SrcDirectory "pool/$(SECTION)";
146
147 Sources "$(DIST)/$(SECTION)/source/Sources";
148 };
149
150 Tree "dists/test" {
151 Sections "main";
152 Architectures "source";
153
154 };
155 EOF
156
157 msgtest 'generate (empty cachedb)'
158 testsuccess aptftparchive generate apt-ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
159 cp rootdir/tmp/testsuccess.output stats-out.txt
160 testsuccess grep Misses stats-out.txt
161 testfileequal rootdir/tmp/testsuccess.output ' Misses in Cache: 2'
162 assert_correct_sources_file
163
164 msgtest 'generate again out of the cache'
165 rm -f ./aptarchive/dists/test/main/source/Sources
166 testsuccess aptftparchive generate apt-ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1
167 cp rootdir/tmp/testsuccess.output stats-out.txt
168 testsuccess grep Misses stats-out.txt
169 testfileequal rootdir/tmp/testsuccess.output ' Misses in Cache: 0'
170 assert_correct_sources_file
171
172 # generate invalid files
173 mkdir aptarchive/pool/invalid
174 printf "meep" > aptarchive/pool/invalid/invalid_1.0.dsc
175 testequal "
176 E: Could not find a record in the DSC 'aptarchive/pool/invalid/invalid_1.0.dsc'" aptftparchive sources aptarchive/pool/invalid
177 rm -f aptarchive/pool/invalid/invalid_1.0.dsc
178
179 printf "meep: yes" > aptarchive/pool/invalid/invalid_1.0.dsc
180 testequal "
181 E: Could not find a Source entry in the DSC 'aptarchive/pool/invalid/invalid_1.0.dsc'" aptftparchive sources aptarchive/pool/invalid
182 rm -f aptarchive/pool/invalid/invalid_1.0.dsc
183
184 # ensure clean works
185 rm -f aptarchive/pool/main/*
186 testsuccess aptftparchive clean apt-ftparchive.conf -o Debug::APT::FTPArchive::Clean=1
187 cp rootdir/tmp/testsuccess.output clean-out.txt
188 testsuccess grep unique clean-out.txt
189 testfileequal 'rootdir/tmp/testsuccess.output' "0 Number of unique keys in the tree"
190 testsuccess grep sources-main.db clean-out.txt
191 testfileequal 'rootdir/tmp/testsuccess.output' "sources-main.db"