chiark / gitweb /
Merge branch 'nail-down-tests' into 'master'
authorHans-Christoph Steiner <hans@guardianproject.info>
Wed, 20 Dec 2017 23:16:03 +0000 (23:16 +0000)
committerHans-Christoph Steiner <hans@guardianproject.info>
Wed, 20 Dec 2017 23:16:03 +0000 (23:16 +0000)
Nail down tests

Closes #432

See merge request fdroid/fdroidserver!418

.travis.yml
README.md
fdroidserver/build.py
fdroidserver/common.py
fdroidserver/update.py
tests/complete-ci-tests
tests/run-tests

index 8af3260630aca5228955aa45cde7f958ede7d3be..edfd9079bb34ac6063e19e5123699a21db73058f 100644 (file)
@@ -67,11 +67,13 @@ install:
 
       mkdir -p "$ANDROID_HOME/licenses";
       echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license";
+      echo -e "\nd56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license";
       echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license";
-      echo y | $ANDROID_HOME/tools/bin/sdkmanager "platform-tools" > /dev/null 2&>1;
-      echo y | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;25.0.2" > /dev/null 2&>1;
-      echo y | $ANDROID_HOME/tools/bin/sdkmanager "platforms;android-23" > /dev/null 2&>1;
+      echo y | $ANDROID_HOME/tools/bin/sdkmanager "platform-tools";
+      echo y | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;25.0.2";
+      echo y | $ANDROID_HOME/tools/bin/sdkmanager "platforms;android-23";
 
+      sudo pip3 install babel;
       sudo pip3 install --quiet --editable . ;
       sudo rm -rf fdroidserver.egg-info;
 
index a28b484412966dc5198cde2b6ad18c711adb4e01..8ebbeb612ea885dec1ebe3f5d311c8e061e57617 100644 (file)
--- a/README.md
+++ b/README.md
@@ -40,6 +40,39 @@ https://f-droid.org/docs/Installing_the_Server_and_Repo_Tools
 All sorts of other documentation lives there as well.
 
 
+### Tests
+
+There are many components to all of the tests for the components in
+this git repo.  The most commonly used parts of well tested, while
+some parts still lack tests.  This test suite has built over time a
+bit haphazardly, so it is not as clean, organized, or complete as it
+could be.  We welcome contributions.  Before rearchitecting any parts
+of it, be sure to [contact us](https://f-droid.org/about) to discuss
+the changes beforehand.
+
+
+#### `fdroid` commands
+
+The test suite for all of the `fdroid` commands is in the _tests/_
+subdir.  _.gitlab-ci.yml_ and _.travis.yml_ run this test suite on
+various configurations.
+
+* _tests/complete-ci-tests_ runs _pylint_ and all tests on two
+  different pyvenvs
+* _tests/run-tests_ runs the whole test suite
+* _tests/*.TestCase_ are individual unit tests for all of the `fdroid`
+  commands, which can be run separately, e.g. `./update.TestCase`.
+
+
+#### buildserver
+
+The tests for the whole build server setup are entirely separate
+because they require at least 200GB of disk space, and 8GB of
+RAM. These test scripts are in the root of the project, all starting
+with _jenkins-_ since they are run on https://jenkins.debian.net.
+
+
+
 ### Drozer Scanner
 
 There is a new feature under development that can scan any APK in a
index d4f500057f85a63e70a1d1efb8d4c689d6273d17..3f428af789e3aaf86a0b4e19ae786edce7ee980f 100644 (file)
@@ -419,7 +419,7 @@ def build_local(app, build, vcs, build_dir, output_dir, log_dir, srclib_dir, ext
             raise BuildException("Error locking root account for %s:%s" %
                                  (app.id, build.versionName), p.output)
 
-        p = FDroidPopen(['sudo', 'SUDO_FORCE_REMOVE=yes', 'apt-get', '-y', 'purge', 'sudo'])
+        p = FDroidPopen(['sudo', 'SUDO_FORCE_REMOVE=yes', 'dpkg', '--purge', 'sudo'])
         if p.returncode != 0:
             raise BuildException("Error removing sudo for %s:%s" %
                                  (app.id, build.versionName), p.output)
index 624e93538d9d0de01dfb2561d94154fe4d3c2c2b..8248a9441349f3c06b87eb66f0706db7ed7a8dee 100644 (file)
@@ -128,6 +128,13 @@ default_config = {
 
 
 def setup_global_opts(parser):
+    try:  # the buildserver VM might not have PIL installed
+        from PIL import PngImagePlugin
+        logger = logging.getLogger(PngImagePlugin.__name__)
+        logger.setLevel(logging.INFO)  # tame the "STREAM" debug messages
+    except ImportError:
+        pass
+
     parser.add_argument("-v", "--verbose", action="store_true", default=False,
                         help=_("Spew out even more information than normal"))
     parser.add_argument("-q", "--quiet", action="store_true", default=False,
index 3015e337ca6325813337e1a8c6bb6dd66a7f4178..c1079489cc8f08020d03f26f1bd7f58bcde4decc 100644 (file)
@@ -1492,7 +1492,7 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
             logging.warning(_("Failed reading {path}: {error}")
                             .format(path=icon_path, error=e))
         finally:
-            if im:
+            if im and hasattr(im, 'close'):
                 im.close()
 
     if apk['icons']:
index 4573fcd5cd9468d510a1cc946f4ba0365aa2450f..6201eb2c5342c071aba839fc2f05016ede5f43d4 100755 (executable)
@@ -92,11 +92,6 @@ test -e $WORKSPACE/env/share/locale/de/LC_MESSAGES/fdroidserver.mo
 fdroid=$WORKSPACE/env/bin/fdroid $WORKSPACE/tests/run-tests $apksource
 
 
-#------------------------------------------------------------------------------#
-# run git pre-commit hook for pep8, pyflakes, etc
-sh hooks/pre-commit
-
-
 #------------------------------------------------------------------------------#
 # run pylint
 
index af29f471eeb186a5480815658759b206b16afc5a..13a96a37c66b07088bbda9461cd2b09f5e2dd214 100755 (executable)
@@ -41,6 +41,17 @@ create_test_file() {
     TMPDIR=$WORKSPACE/.testfiles  mktemp
 }
 
+fdroid_init_with_prebuilt_keystore() {
+    if [ -z "$1" ]; then
+        keystore=$WORKSPACE/tests/keystore.jks
+    else
+        keystore="$1"
+    fi
+    $fdroid init --keystore $keystore --repo-keyalias=sova
+    echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
+    echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
+}
+
 # the < is reverse since 0 means success in exit codes
 have_git_2_3() {
     python3 -c "import sys; from distutils.version import LooseVersion as V; sys.exit(V(sys.argv[3]) < V('2.3'))" `git --version`
@@ -91,11 +102,6 @@ if [ -z $aapt ]; then
     aapt=`ls -1 $ANDROID_HOME/build-tools/*/aapt | sort | tail -1`
 fi
 
-# allow the location of python to be overridden
-if [ -z $python ]; then
-    python=python3
-fi
-
 # try to use GNU sed on OSX/BSD cuz BSD sed sucks
 if which gsed; then
     sed=gsed
@@ -165,7 +171,7 @@ echo_header "test UTF-8 metadata"
 REPOROOT=`create_test_dir`
 cd $REPOROOT
 
-$fdroid init
+fdroid_init_with_prebuilt_keystore
 $sed -i.tmp 's,^ *repo_description.*,repo_description = """获取已安装在您的设备上的应用的,' config.py
 echo "mirrors = ('https://foo.bar/fdroid', 'http://secret.onion/fdroid')" >> config.py
 mkdir metadata
@@ -219,11 +225,8 @@ echo_header "copy tests/repo, generate java/gpg keys, update, and gpgsign"
 
 REPOROOT=`create_test_dir`
 GNUPGHOME=$REPOROOT/gnupghome
-KEYSTORE=$WORKSPACE/tests/keystore.jks
 cd $REPOROOT
-$fdroid init --keystore $KEYSTORE --repo-keyalias=sova
-echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
-echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
+fdroid_init_with_prebuilt_keystore
 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
 cp -a $WORKSPACE/tests/gnupghome $GNUPGHOME
 chmod 0700 $GNUPGHOME
@@ -263,10 +266,7 @@ echo_header 'test moving lots of APKs to the archive'
 
 REPOROOT=`create_test_dir`
 cd $REPOROOT
-cp $WORKSPACE/tests/keystore.jks $REPOROOT/
-$fdroid init --keystore keystore.jks --repo-keyalias=sova
-echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
-echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
+fdroid_init_with_prebuilt_keystore
 echo "accepted_formats = ['txt']" >> config.py
 $sed -i.tmp '/allow_disabled_algorithms/d' config.py
 test -d metadata || mkdir metadata
@@ -293,10 +293,7 @@ echo_header 'test per-app "Archive Policy"'
 
 REPOROOT=`create_test_dir`
 cd $REPOROOT
-cp $WORKSPACE/tests/keystore.jks $REPOROOT/
-$fdroid init --keystore keystore.jks --repo-keyalias=sova
-echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
-echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
+fdroid_init_with_prebuilt_keystore
 echo "accepted_formats = ['txt']" >> config.py
 test -d metadata || mkdir metadata
 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
@@ -367,10 +364,7 @@ echo_header 'test moving old APKs to and from the archive'
 
 REPOROOT=`create_test_dir`
 cd $REPOROOT
-cp $WORKSPACE/tests/keystore.jks $REPOROOT/
-$fdroid init --keystore keystore.jks --repo-keyalias=sova
-echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
-echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
+fdroid_init_with_prebuilt_keystore
 echo "accepted_formats = ['txt']" >> config.py
 test -d metadata || mkdir metadata
 cp $WORKSPACE/tests/metadata/com.politedroid.txt metadata/
@@ -436,10 +430,7 @@ echo_header 'test allowing disabled signatures in repo and archive'
 
 REPOROOT=`create_test_dir`
 cd $REPOROOT
-cp $WORKSPACE/tests/keystore.jks $REPOROOT/
-$fdroid init --keystore keystore.jks --repo-keyalias=sova
-echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
-echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
+fdroid_init_with_prebuilt_keystore
 echo "accepted_formats = ['txt']" >> config.py
 echo 'allow_disabled_algorithms = True' >> config.py
 $sed -i.tmp 's,archive_older = [0-9],archive_older = 3,' config.py
@@ -507,10 +498,7 @@ echo_header 'rename apks with `fdroid update --rename-apks`, --nosign for speed'
 
 REPOROOT=`create_test_dir`
 cd $REPOROOT
-cp $WORKSPACE/tests/keystore.jks $REPOROOT/
-$fdroid init --keystore keystore.jks --repo-keyalias=sova
-echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
-echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
+fdroid_init_with_prebuilt_keystore
 echo "accepted_formats = ['txt', 'yml']" >> config.py
 echo 'keydname = "CN=Birdman, OU=Cell, O=Alcatraz, L=Alcatraz, S=California, C=US"' >> config.py
 test -d metadata || mkdir metadata
@@ -610,10 +598,10 @@ $fdroid install || true
 
 
 #------------------------------------------------------------------------------#
-echo_header "create a source tarball and use that to build a repo"
+echo_header "create a source tarball"
 
 cd $WORKSPACE
-$python setup.py sdist
+./setup.py compile_catalog sdist
 
 REPOROOT=`create_test_dir`
 cd $REPOROOT
@@ -665,7 +653,7 @@ echo_header "setup a new repo from scratch using ANDROID_HOME and do a local syn
 
 REPOROOT=`create_test_dir`
 cd $REPOROOT
-$fdroid init
+fdroid_init_with_prebuilt_keystore
 copy_apks_into_repo $REPOROOT
 $fdroid update --create-metadata --verbose
 $fdroid readmeta
@@ -675,7 +663,7 @@ LOCALCOPYDIR=`create_test_dir`/fdroid
 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
 NEWREPOROOT=`create_test_dir`
 cd $NEWREPOROOT
-$fdroid init
+fdroid_init_with_prebuilt_keystore
 echo "sync_from_local_copy_dir = True" >> config.py
 $fdroid server update --local-copy-dir=$LOCALCOPYDIR
 
@@ -787,11 +775,8 @@ export ANDROID_HOME=$STORED_ANDROID_HOME
 echo_header "check duplicate files are properly handled by fdroid update"
 
 REPOROOT=`create_test_dir`
-KEYSTORE=$WORKSPACE/tests/keystore.jks
 cd $REPOROOT
-$fdroid init --keystore $KEYSTORE --repo-keyalias=sova
-echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
-echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
+fdroid_init_with_prebuilt_keystore
 mkdir $REPOROOT/metadata
 cp -a $WORKSPACE/tests/metadata/obb.mainpatch.current.txt $REPOROOT/metadata
 echo "accepted_formats = ['txt']" >> config.py
@@ -813,7 +798,7 @@ REPOROOT=`create_test_dir`
 cd $REPOROOT
 mkdir repo
 copy_apks_into_repo $REPOROOT
-$fdroid init
+fdroid_init_with_prebuilt_keystore
 $fdroid update --create-metadata --verbose
 $fdroid readmeta
 grep -F '<application id=' repo/index.xml > /dev/null
@@ -946,12 +931,9 @@ echo_header "copy tests/repo, update with binary transparency log"
 REPOROOT=`create_test_dir`
 GIT_REMOTE=`create_test_dir`
 GNUPGHOME=$REPOROOT/gnupghome
-KEYSTORE=$WORKSPACE/tests/keystore.jks
 cd $REPOROOT
-$fdroid init --keystore $KEYSTORE --repo-keyalias=sova
+fdroid_init_with_prebuilt_keystore
 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $REPOROOT/
-echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
-echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
 echo "binary_transparency_remote = '$GIT_REMOTE'" >> config.py
 echo "accepted_formats = ['json', 'txt', 'yml']" >> config.py
 $fdroid update --verbose
@@ -976,7 +958,8 @@ echo_header "setup a new repo with keystore with APK, update, then without key"
 REPOROOT=`create_test_dir`
 KEYSTORE=$REPOROOT/keystore.jks
 cd $REPOROOT
-$fdroid init --keystore $KEYSTORE
+cp $WORKSPACE/tests/keystore.jks $KEYSTORE
+fdroid_init_with_prebuilt_keystore $KEYSTORE
 test -e $KEYSTORE
 cp $WORKSPACE/tests/urzip.apk $REPOROOT/repo/
 $fdroid update --create-metadata --verbose
@@ -1047,11 +1030,9 @@ if have_git_2_3; then
 fi
 
 cd $OFFLINE_ROOT
-$fdroid init --keystore $KEYSTORE --repo-keyalias=sova
+fdroid_init_with_prebuilt_keystore
 cp -a $WORKSPACE/tests/metadata $WORKSPACE/tests/repo $WORKSPACE/tests/stats $OFFLINE_ROOT/
 
-echo 'keystorepass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
-echo 'keypass = "r9aquRHYoI8+dYz6jKrLntQ5/NJNASFBacJh7Jv2BlI="' >> config.py
 echo "mirrors = ['http://foo.bar/fdroid', 'http://asdflkdsfjafdsdfhkjh.onion/fdroid']" >> config.py
 echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
 echo "local_copy_dir = '$LOCAL_COPY_DIR'" >> config.py