test-apt-ftparchive-src-cachedb 6.2 KB

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