]> git.saurik.com Git - apt.git/commitdiff
add test for binary cachedb and contents generation
authorMichael Vogt <mvo@ubuntu.com>
Fri, 4 Apr 2014 13:36:42 +0000 (15:36 +0200)
committerMichael Vogt <mvo@ubuntu.com>
Fri, 4 Apr 2014 13:36:42 +0000 (15:36 +0200)
ftparchive/cachedb.cc
test/integration/test-apt-ftparchive [deleted file]
test/integration/test-apt-ftparchive-cachedb [new file with mode: 0755]
test/integration/test-apt-ftparchive-src-cachedb [new file with mode: 0755]

index a63b5b9d9e859df5d372b2271d67005d9257f55f..f6cbad668f660729b62155f608253bba4f3c9ab6 100644 (file)
@@ -349,6 +349,7 @@ bool CacheDB::LoadContents(bool const &GenOnly)
         return false;
    }
 
+   Stats.Misses++;
    if (Contents.Read(*DebFile) == false)
       return false;        
    
diff --git a/test/integration/test-apt-ftparchive b/test/integration/test-apt-ftparchive
deleted file mode 100755 (executable)
index b05c15c..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-#!/bin/sh
-set -e
-
-assert_correct_sources_file() {
-    testequal "Package: bar
-Binary: bar
-Version: 1.0
-Architecture: all
-Format: 3.0 (native)
-Directory: pool/main
-Files:
- 7b57dd065e51de5905288a5104d4bef5 406 bar_1.0.dsc
- d41d8cd98f00b204e9800998ecf8427e 0 bar_1.0.tar.gz
-Package-List:
- bar deb admin extra
-Checksums-Sha1:
- 17a40b76715f393ab7fd6485c9392a02f1adf903 406 bar_1.0.dsc
- da39a3ee5e6b4b0d3255bfef95601890afd80709 0 bar_1.0.tar.gz
-Checksums-Sha256:
- d9d7507f66a89258b6920aca47747d7a30e0e64b09ecabbf02b2efbdabf840a9 406 bar_1.0.dsc
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 bar_1.0.tar.gz
-Checksums-Sha512:
- ee0a9bfb6614159b45203fc29487d4f37387993ca0e6d6f27b80010498f3731d75753188ece307508ae9af0259bd11a6af15a1a38f0b87dbd5ea1273b7a7d53e 406 bar_1.0.dsc
- cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e 0 bar_1.0.tar.gz
-
-Package: foo
-Binary: foo
-Version: 1.0
-Architecture: all
-Format: 3.0 (native)
-Directory: pool/main
-Files:
- d144826e6f02831c1933e910c92cd7e0 171 foo_1.0.dsc
- d41d8cd98f00b204e9800998ecf8427e 0 foo_1.0.tar.gz
-Package-List: 
- foo deb admin extra
-Checksums-Sha1:
- 979306aa3ccff3d61bba062bb6977e2493c6f907 171 foo_1.0.dsc
- da39a3ee5e6b4b0d3255bfef95601890afd80709 0 foo_1.0.tar.gz
-Checksums-Sha256:
- 8c780af8b5a6d5b3c2e2f9518940beebea52ac6d6ad7b52c082dc925cfe5b532 171 foo_1.0.dsc
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 foo_1.0.tar.gz
-Checksums-Sha512:
- 3da0240fd764657c2f3661b4d750578a9a99b0580591b133756379d48117ebda87a5ed2467f513200d6e7eaf51422cbe91c15720eef7fb4bba2cc8ff81ebc547 171 foo_1.0.dsc
- cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e 0 foo_1.0.tar.gz
-" cat ./aptarchive/dists/test/main/source/Sources
-}
-
-create_source_files() {
-    NAME="$1"
-    REQUEST_CLEARSIGN="$2"
-    
-    TARFILE="aptarchive/pool/main/${NAME}_1.0.tar.gz"
-    DSC_FILE="aptarchive/pool/main/${NAME}_1.0.dsc"
-    touch $TARFILE
-    if [ "$REQUEST_CLEARSIGN" = "CLEARSIGN" ]; then
-        printf -- "-----BEGIN PGP SIGNED MESSAGE-----\n\n" > $DSC_FILE
-    fi
-    cat >> $DSC_FILE << EOF
-Format: 3.0 (native)
-Source: $NAME
-Binary: $NAME
-Architecture: all
-Version: 1.0
-Package-List: 
- $NAME deb admin extra
-Files: 
- $(md5sum $TARFILE|cut -f1 -d' ') $(stat --print="%s" $TARFILE) ${NAME}_1.0.tar.gz
-EOF
-    if [ "$REQUEST_CLEARSIGN" = "CLEARSIGN" ]; then
-        cat >> $DSC_FILE <<EOF
-
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.11 (GNU/Linux)
-
-iEYEARECAAYFAk3k/VoACgkQliSD4VZixzQxlgCgpav7j68z48qNTDFuT9fLqwT5
-DFwAoIXatJFENEC371bMKTkUKlwZxQEk
-=iI9V
------END PGP SIGNATURE-----
-EOF
-    fi
-}
-
-create_clearsigned_source_files() {
-    NAME="$1"
-    create_source_files "$NAME" "CLEARSIGN"
-}
-
-#
-# main()
-#
-TESTDIR=$(readlink -f $(dirname $0))
-. $TESTDIR/framework
-setupenvironment
-configarchitecture "i386"
-
-msgtest 'Test apt-ftparchive source with missing hashes in .dsc'
-
-mkdir -p aptarchive/pool/main
-create_source_files foo
-create_clearsigned_source_files bar
-
-mkdir -p aptarchive/dists/test/main/i18n/
-mkdir -p aptarchive/dists/test/main/source/
-
-mkdir aptarchive-overrides
-mkdir aptarchive-cache
-cat > apt-ftparchive.conf <<"EOF"
-Dir {
-  ArchiveDir "./aptarchive";
-  OverrideDir "./aptarchive-overrides";
-  CacheDir "./aptarchive-cache";
-};
-
-Default {
- Packages::Compress ". gzip bzip2";
- Contents::Compress ". gzip bzip2";
- LongDescription "false";
-};
-
-TreeDefault {
- BinCacheDB "packages-$(SECTION)-$(ARCH).db";
- SrcCacheDB "sources-$(SECTION).db";
-
- Directory  "pool/$(SECTION)";
- SrcDirectory "pool/$(SECTION)";
-
- Packages   "$(DIST)/$(SECTION)/binary-$(ARCH)/Packages";
- Sources    "$(DIST)/$(SECTION)/source/Sources";
- Contents    "$(DIST)/Contents-$(ARCH)";
-};
-
-Tree "dists/test" {
-  Sections "main";
-  Architectures "source";
-
-};
-EOF
-
-
-# generate (no cachedb)
-aptftparchive generate apt-ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 2> stats-out.txt
-testequal " Misses in Cache: 2" grep Misses stats-out.txt
-assert_correct_sources_file
-
-
-# generate again out of the cache
-rm -f ./aptarchive/dists/test/main/source/Sources
-aptftparchive generate apt-ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1  2> stats-out.txt
-testequal " Misses in Cache: 0" grep Misses stats-out.txt
-assert_correct_sources_file
-
-# generate invalid files
-mkdir aptarchive/pool/invalid
-printf "meep" > aptarchive/pool/invalid/invalid_1.0.dsc
-testequal "
-E: Could not find a Source entry in the DSC 'aptarchive/pool/invalid/invalid_1.0.dsc'" aptftparchive sources aptarchive/pool/invalid
-rm -f aptarchive/pool/invalid/invalid_1.0.dsc
-
-dd if=/dev/zero of="aptarchive/pool/invalid/toobig_1.0.dsc" bs=1k count=129 2>/dev/null
-testequal "
-E: DSC file 'aptarchive/pool/invalid/toobig_1.0.dsc' is too large!" aptftparchive sources aptarchive/pool/invalid
-
-
diff --git a/test/integration/test-apt-ftparchive-cachedb b/test/integration/test-apt-ftparchive-cachedb
new file mode 100755 (executable)
index 0000000..2a3bfce
--- /dev/null
@@ -0,0 +1,93 @@
+#!/bin/sh
+set -e
+
+ensure_correct_packages_file() {
+    testequal "Package: foo
+Priority: optional
+Section: others
+Installed-Size: 29
+Maintainer: Joe Sixpack <joe@example.org>
+Architecture: i386
+Version: 1
+Filename: pool/main/foo_1_i386.deb" head -n8 ./aptarchive/dists/test/main/binary-i386/Packages 
+}
+
+ensure_correct_contents_file() {
+    testequal "usr/bin/foo-i386                                            others/foo
+usr/share/doc/foo/FEATURES                                 others/foo
+usr/share/doc/foo/changelog                                others/foo
+usr/share/doc/foo/copyright                                others/foo" cat ./aptarchive/dists/test/Contents-i386
+}
+
+#
+# main()
+#
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture "i386"
+
+mkdir -p aptarchive/dists/test/main/i18n/
+mkdir -p aptarchive/dists/test/main/source/
+mkdir -p aptarchive/dists/test/main/binary-i386
+mkdir -p aptarchive/pool/main
+
+mkdir aptarchive-overrides
+mkdir aptarchive-cache
+cat > ftparchive.conf <<"EOF"
+Dir {
+  ArchiveDir "./aptarchive";
+  OverrideDir "./aptarchive-overrides";
+  CacheDir "./aptarchive-cache";
+};
+
+Default {
+ Packages::Compress ". gzip bzip2";
+ Contents::Compress ". gzip bzip2";
+ LongDescription "false";
+};
+
+TreeDefault {
+ BinCacheDB "packages-$(SECTION)-$(ARCH).db";
+
+ Directory  "pool/$(SECTION)";
+ SrcDirectory "pool/$(SECTION)";
+
+ Packages   "$(DIST)/$(SECTION)/binary-$(ARCH)/Packages";
+ Contents    "$(DIST)/Contents-$(ARCH)";
+};
+
+Tree "dists/test" {
+  Sections "main";
+  Architectures "i386";
+
+};
+EOF
+
+# build one pacakge
+buildsimplenativepackage 'foo' 'i386' '1' 'test'
+mv incoming/* aptarchive/pool/main/
+
+# generate (empty cachedb)
+aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 2> stats-out.txt
+ensure_correct_packages_file
+ensure_correct_contents_file
+testequal " Misses in Cache: 2
+ dists/test/Contents-i386: New 402 B  Misses in Cache: 0" grep Misses stats-out.txt
+
+# generate again
+aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 2> stats-out.txt
+ensure_correct_packages_file
+ensure_correct_contents_file
+testequal " Misses in Cache: 0
+ dists/test/Contents-i386:  Misses in Cache: 0" grep Misses stats-out.txt
+
+# and again (with removing the Packages file)
+rm -f ./aptarchive/dists/test/main/binary-i386/*
+rm -f ./aptarchive/dists/test/Contents-i386
+aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 2> stats-out.txt
+ensure_correct_packages_file
+ensure_correct_contents_file
+testequal " Misses in Cache: 0
+ dists/test/Contents-i386: New 402 B  Misses in Cache: 0" grep Misses stats-out.txt
+
diff --git a/test/integration/test-apt-ftparchive-src-cachedb b/test/integration/test-apt-ftparchive-src-cachedb
new file mode 100755 (executable)
index 0000000..3a5507c
--- /dev/null
@@ -0,0 +1,162 @@
+#!/bin/sh
+set -e
+
+assert_correct_sources_file() {
+    testequal "Package: bar
+Binary: bar
+Version: 1.0
+Architecture: all
+Format: 3.0 (native)
+Directory: pool/main
+Files:
+ 7b57dd065e51de5905288a5104d4bef5 406 bar_1.0.dsc
+ d41d8cd98f00b204e9800998ecf8427e 0 bar_1.0.tar.gz
+Package-List:
+ bar deb admin extra
+Checksums-Sha1:
+ 17a40b76715f393ab7fd6485c9392a02f1adf903 406 bar_1.0.dsc
+ da39a3ee5e6b4b0d3255bfef95601890afd80709 0 bar_1.0.tar.gz
+Checksums-Sha256:
+ d9d7507f66a89258b6920aca47747d7a30e0e64b09ecabbf02b2efbdabf840a9 406 bar_1.0.dsc
+ e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 bar_1.0.tar.gz
+Checksums-Sha512:
+ ee0a9bfb6614159b45203fc29487d4f37387993ca0e6d6f27b80010498f3731d75753188ece307508ae9af0259bd11a6af15a1a38f0b87dbd5ea1273b7a7d53e 406 bar_1.0.dsc
+ cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e 0 bar_1.0.tar.gz
+
+Package: foo
+Binary: foo
+Version: 1.0
+Architecture: all
+Format: 3.0 (native)
+Directory: pool/main
+Files:
+ d144826e6f02831c1933e910c92cd7e0 171 foo_1.0.dsc
+ d41d8cd98f00b204e9800998ecf8427e 0 foo_1.0.tar.gz
+Package-List: 
+ foo deb admin extra
+Checksums-Sha1:
+ 979306aa3ccff3d61bba062bb6977e2493c6f907 171 foo_1.0.dsc
+ da39a3ee5e6b4b0d3255bfef95601890afd80709 0 foo_1.0.tar.gz
+Checksums-Sha256:
+ 8c780af8b5a6d5b3c2e2f9518940beebea52ac6d6ad7b52c082dc925cfe5b532 171 foo_1.0.dsc
+ e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 foo_1.0.tar.gz
+Checksums-Sha512:
+ 3da0240fd764657c2f3661b4d750578a9a99b0580591b133756379d48117ebda87a5ed2467f513200d6e7eaf51422cbe91c15720eef7fb4bba2cc8ff81ebc547 171 foo_1.0.dsc
+ cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e 0 foo_1.0.tar.gz
+" cat ./aptarchive/dists/test/main/source/Sources
+}
+
+create_source_files() {
+    NAME="$1"
+    REQUEST_CLEARSIGN="$2"
+    
+    TARFILE="aptarchive/pool/main/${NAME}_1.0.tar.gz"
+    DSC_FILE="aptarchive/pool/main/${NAME}_1.0.dsc"
+    touch $TARFILE
+    if [ "$REQUEST_CLEARSIGN" = "CLEARSIGN" ]; then
+        printf -- "-----BEGIN PGP SIGNED MESSAGE-----\n\n" > $DSC_FILE
+    fi
+    cat >> $DSC_FILE << EOF
+Format: 3.0 (native)
+Source: $NAME
+Binary: $NAME
+Architecture: all
+Version: 1.0
+Package-List: 
+ $NAME deb admin extra
+Files: 
+ $(md5sum $TARFILE|cut -f1 -d' ') $(stat --print="%s" $TARFILE) ${NAME}_1.0.tar.gz
+EOF
+    if [ "$REQUEST_CLEARSIGN" = "CLEARSIGN" ]; then
+        cat >> $DSC_FILE <<EOF
+
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.11 (GNU/Linux)
+
+iEYEARECAAYFAk3k/VoACgkQliSD4VZixzQxlgCgpav7j68z48qNTDFuT9fLqwT5
+DFwAoIXatJFENEC371bMKTkUKlwZxQEk
+=iI9V
+-----END PGP SIGNATURE-----
+EOF
+    fi
+}
+
+create_clearsigned_source_files() {
+    NAME="$1"
+    create_source_files "$NAME" "CLEARSIGN"
+}
+
+#
+# main()
+#
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+configarchitecture "i386"
+
+msgtest 'Test apt-ftparchive source with missing hashes in .dsc'
+
+mkdir -p aptarchive/pool/main
+create_source_files foo
+create_clearsigned_source_files bar
+
+mkdir -p aptarchive/dists/test/main/i18n/
+mkdir -p aptarchive/dists/test/main/source/
+
+mkdir aptarchive-overrides
+mkdir aptarchive-cache
+cat > apt-ftparchive.conf <<"EOF"
+Dir {
+  ArchiveDir "./aptarchive";
+  OverrideDir "./aptarchive-overrides";
+  CacheDir "./aptarchive-cache";
+};
+
+Default {
+ Packages::Compress ". gzip bzip2";
+ Contents::Compress ". gzip bzip2";
+ LongDescription "false";
+};
+
+TreeDefault {
+ BinCacheDB "packages-$(SECTION)-$(ARCH).db";
+ SrcCacheDB "sources-$(SECTION).db";
+
+ Directory  "pool/$(SECTION)";
+ SrcDirectory "pool/$(SECTION)";
+
+ Sources    "$(DIST)/$(SECTION)/source/Sources";
+};
+
+Tree "dists/test" {
+  Sections "main";
+  Architectures "source";
+
+};
+EOF
+
+
+# generate (empty cachedb)
+aptftparchive generate apt-ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 2> stats-out.txt
+testequal " Misses in Cache: 2" grep Misses stats-out.txt
+assert_correct_sources_file
+
+
+# generate again out of the cache
+rm -f ./aptarchive/dists/test/main/source/Sources
+aptftparchive generate apt-ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1  2> stats-out.txt
+testequal " Misses in Cache: 0" grep Misses stats-out.txt
+assert_correct_sources_file
+
+# generate invalid files
+mkdir aptarchive/pool/invalid
+printf "meep" > aptarchive/pool/invalid/invalid_1.0.dsc
+testequal "
+E: Could not find a Source entry in the DSC 'aptarchive/pool/invalid/invalid_1.0.dsc'" aptftparchive sources aptarchive/pool/invalid
+rm -f aptarchive/pool/invalid/invalid_1.0.dsc
+
+dd if=/dev/zero of="aptarchive/pool/invalid/toobig_1.0.dsc" bs=1k count=129 2>/dev/null
+testequal "
+E: DSC file 'aptarchive/pool/invalid/toobig_1.0.dsc' is too large!" aptftparchive sources aptarchive/pool/invalid
+
+