test-apt-ftparchive-src-cachedb 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/bin/sh
  2. set -e
  3. assert_correct_sources_file() {
  4. testsuccessequal "Package: bar
  5. Architecture: all
  6. Version: 1.0
  7. Binary: bar
  8. Format: 3.0 (native)
  9. Directory: pool/main
  10. Files:
  11. 7b57dd065e51de5905288a5104d4bef5 406 bar_1.0.dsc
  12. d41d8cd98f00b204e9800998ecf8427e 0 bar_1.0.tar.gz
  13. Package-List:
  14. bar deb admin extra
  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. Architecture: all
  26. Version: 1.0
  27. Binary: foo
  28. Format: 3.0 (native)
  29. Directory: pool/main
  30. Files:
  31. d144826e6f02831c1933e910c92cd7e0 171 foo_1.0.dsc
  32. d41d8cd98f00b204e9800998ecf8427e 0 foo_1.0.tar.gz
  33. Package-List:
  34. foo deb admin extra
  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
  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. msgtest 'Test apt-ftparchive source with missing hashes in .dsc'
  89. mkdir -p aptarchive/pool/main
  90. create_source_files foo
  91. create_clearsigned_source_files bar
  92. mkdir -p aptarchive/dists/test/main/i18n/
  93. mkdir -p aptarchive/dists/test/main/source/
  94. mkdir aptarchive-overrides
  95. mkdir aptarchive-cache
  96. msgtest 'generate with --db option'
  97. cd aptarchive
  98. aptftparchive --db ./test.db sources pool/main/ -q=0 -o APT::FTPArchive::ShowCacheMisses=1 > dists/test/main/source/Sources 2>stats-out.txt && msgpass || msgfail
  99. testsuccess grep Misses stats-out.txt
  100. testfileequal '../rootdir/tmp/testsuccess.output' ' Misses in Cache: 2'
  101. cd ..
  102. assert_correct_sources_file
  103. msgtest 'generate with --db option (again to ensure its in the cache)'
  104. cd aptarchive
  105. aptftparchive --db ./test.db sources pool/main/ -q=0 -o APT::FTPArchive::ShowCacheMisses=1 > dists/test/main/source/Sources 2>stats-out.txt && msgpass || msgfail
  106. testsuccess grep Misses stats-out.txt
  107. testfileequal '../rootdir/tmp/testsuccess.output' ' Misses in Cache: 0'
  108. cd ..
  109. assert_correct_sources_file
  110. # get ready for the "apt-ftparchive generate" command
  111. cat > apt-ftparchive.conf <<"EOF"
  112. Dir {
  113. ArchiveDir "./aptarchive";
  114. OverrideDir "./aptarchive-overrides";
  115. CacheDir "./aptarchive-cache";
  116. };
  117. Default {
  118. Packages::Compress ". gzip bzip2";
  119. Contents::Compress ". gzip bzip2";
  120. LongDescription "false";
  121. };
  122. TreeDefault {
  123. BinCacheDB "packages-$(SECTION)-$(ARCH).db";
  124. SrcCacheDB "sources-$(SECTION).db";
  125. Directory "pool/$(SECTION)";
  126. SrcDirectory "pool/$(SECTION)";
  127. Sources "$(DIST)/$(SECTION)/source/Sources";
  128. };
  129. Tree "dists/test" {
  130. Sections "main";
  131. Architectures "source";
  132. };
  133. EOF
  134. msgtest 'generate (empty cachedb)'
  135. testsuccess aptftparchive generate apt-ftparchive.conf -q=0 -o APT::FTPArchive::ShowCacheMisses=1
  136. cp rootdir/tmp/testsuccess.output stats-out.txt
  137. testsuccess grep Misses stats-out.txt
  138. testfileequal rootdir/tmp/testsuccess.output ' Misses in Cache: 2'
  139. assert_correct_sources_file
  140. msgtest 'generate again out of the cache'
  141. rm -f ./aptarchive/dists/test/main/source/Sources
  142. testsuccess aptftparchive generate apt-ftparchive.conf -q=0 -o APT::FTPArchive::ShowCacheMisses=1
  143. cp rootdir/tmp/testsuccess.output stats-out.txt
  144. testsuccess grep Misses stats-out.txt
  145. testfileequal rootdir/tmp/testsuccess.output ' Misses in Cache: 0'
  146. assert_correct_sources_file
  147. # generate invalid files
  148. mkdir aptarchive/pool/invalid
  149. printf "meep" > aptarchive/pool/invalid/invalid_1.0.dsc
  150. testequal "
  151. E: Could not find a record in the DSC 'aptarchive/pool/invalid/invalid_1.0.dsc'" aptftparchive sources aptarchive/pool/invalid
  152. rm -f aptarchive/pool/invalid/invalid_1.0.dsc
  153. printf "meep: yes" > aptarchive/pool/invalid/invalid_1.0.dsc
  154. testequal "
  155. E: Could not find a Source entry in the DSC 'aptarchive/pool/invalid/invalid_1.0.dsc'" aptftparchive sources aptarchive/pool/invalid
  156. rm -f aptarchive/pool/invalid/invalid_1.0.dsc
  157. # ensure clean works
  158. rm -f aptarchive/pool/main/*
  159. testsuccess aptftparchive clean apt-ftparchive.conf -q=0 -o Debug::APT::FTPArchive::Clean=1
  160. cp rootdir/tmp/testsuccess.output clean-out.txt
  161. testsuccess grep unique clean-out.txt
  162. testfileequal 'rootdir/tmp/testsuccess.output' "0 Number of unique keys in the tree"
  163. testsuccess grep sources-main.db clean-out.txt
  164. testfileequal 'rootdir/tmp/testsuccess.output' "sources-main.db"