chiark / gitweb /
Replace getsig.java with a pure python implementation
[fdroidserver.git] / tests / run-tests
index 5579fda24cd3de712765d393c41e291d7a1c6b99..1f0e7709e7355f770f496577fb7678403d44e527 100755 (executable)
@@ -12,7 +12,7 @@ copy_apks_into_repo() {
     set +x
     for f in `find $APKDIR -name '*.apk' | grep -F -v -e unaligned -e unsigned`; do
         name=$(basename $(dirname `dirname $f`))
-        apk=`aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
+        apk=`$aapt dump badging "$f" | sed -n "s,^package: name='\(.*\)' versionCode='\([0-9][0-9]*\)' .*,\1_\2.apk,p"`
         test $f -nt repo/$apk && rm -f repo/$apk  # delete existing if $f is newer
         if [ ! -e repo/$apk ] && [ ! -e archive/$apk ]; then
             echo "$f --> repo/$apk"
@@ -23,10 +23,14 @@ copy_apks_into_repo() {
     set -x
 }
 
+# keep this as an old version to test the automatic parsing of build-tools
+# verion numbers in `fdroid init`
 create_fake_android_home() {
+    mkdir $1/tools
+    mkdir $1/platform-tools
     mkdir $1/build-tools
-    mkdir $1/build-tools/19.1
-    touch $1/build-tools/19.1/aapt
+    mkdir $1/build-tools/19.0.2
+    touch $1/build-tools/19.0.2/aapt
 }
 
 create_test_dir() {
@@ -42,12 +46,23 @@ create_test_file() {
 #------------------------------------------------------------------------------#
 # "main"
 
-if [ $# -ne 1 ]; then
+if [ $1 = "-h" ] || [ $1 = "--help" ]; then
+    set +x
     echo "Usage: $0 '/path/to/folder/with/apks'"
     exit 1
 fi
 
-APKDIR=$1
+if [ -z $ANDROID_HOME ]; then
+    echo "ANDROID_HOME must be set with the path to the Android SDK, i.e.: "
+    echo "  export ANDROID_HOME=/opt/android-sdk"
+    exit 1
+fi
+
+if [ -z $1 ]; then
+    APKDIR=`pwd`
+else
+    APKDIR=$1
+fi
 
 if [ -z $WORKSPACE ]; then
     WORKSPACE=`dirname $(pwd)`
@@ -59,8 +74,76 @@ if [ -z $fdroid ]; then
     fdroid="$WORKSPACE/fdroid"
 fi
 
+# allow the location of aapt to be overridden
+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=python2
+fi
+
+
 #------------------------------------------------------------------------------#
-echo_header "setup a new repo from scratch using ANDROID_HOME"
+echo_header "run commit hooks"
+
+cd $WORKSPACE
+./hooks/pre-commit
+
+
+#------------------------------------------------------------------------------#
+echo_header "create a source tarball and use that to build a repo"
+
+cd $WORKSPACE
+$python setup.py sdist
+
+REPOROOT=`create_test_dir`
+cd $REPOROOT
+tar xzf `ls -1 $WORKSPACE/dist/fdroidserver-*.tar.gz | sort -n | tail -1`
+cd $REPOROOT
+./fdroidserver-*/fdroid init
+copy_apks_into_repo $REPOROOT
+./fdroidserver-*/fdroid update --create-metadata
+
+
+#------------------------------------------------------------------------------#
+echo_header "test config checks of local_copy_dir"
+
+REPOROOT=`create_test_dir`
+cd $REPOROOT
+$fdroid init
+$fdroid update --create-metadata
+$fdroid server update --local-copy-dir=/tmp/fdroid
+
+# now test the errors work
+set +e
+$fdroid server update --local-copy-dir=thisisnotanabsolutepath
+if [ $? -eq 0 ]; then
+    echo "This should have failed because thisisnotanabsolutepath is not an absolute path!"
+    exit 1
+else
+    echo "testing absolute path checker passed"
+fi
+$fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf
+if [ $? -eq 0 ]; then
+    echo "This should have failed because the path does not end with 'fdroid'!"
+    exit 1
+else
+    echo "testing dirname exists checker passed"
+fi
+$fdroid server update --local-copy-dir=/tmp/IReallyDoubtThisPathExistsasdfasdf/fdroid
+if [ $? -eq 0 ]; then
+    echo "This should have failed because the dirname path does not exist!"
+    exit 1
+else
+    echo "testing dirname exists checker passed"
+fi
+set -e
+
+
+#------------------------------------------------------------------------------#
+echo_header "setup a new repo from scratch using ANDROID_HOME and do a local sync"
 
 REPOROOT=`create_test_dir`
 cd $REPOROOT
@@ -69,6 +152,13 @@ copy_apks_into_repo $REPOROOT
 $fdroid update --create-metadata
 grep -F '<application id=' repo/index.xml
 
+LOCALCOPYDIR=`create_test_dir`/fdroid
+$fdroid server update --local-copy-dir=$LOCALCOPYDIR
+NEWREPOROOT=`create_test_dir`
+cd $NEWREPOROOT
+$fdroid init
+$fdroid server update --local-copy-dir=$LOCALCOPYDIR --sync-from-local-copy-dir
+
 
 #------------------------------------------------------------------------------#
 # check that --android-home fails when dir does not exist or is not a dir
@@ -96,7 +186,7 @@ set -e
 
 
 #------------------------------------------------------------------------------#
-echo_header "check that fake android home passes `fdroid init`"
+echo_header "check that fake android home passes 'fdroid init'"
 
 REPOROOT=`create_test_dir`
 FAKE_ANDROID_HOME=`create_test_dir`
@@ -221,5 +311,6 @@ $fdroid init --keystore NONE
 test -e opensc-fdroid.cfg
 test ! -e NONE
 
+rm -rf $WORKSPACE/fdroidserver.egg-info/
 
 echo SUCCESS