File 0014-tests-Add-test-for-required-flatpak-versioning.patch of Package flatpak.14328
From cf13a1461fc9ed3c2a78d5b4f15466afb5ba87af Mon Sep 17 00:00:00 2001
From: Alexander Larsson <alexl@redhat.com>
Date: Wed, 18 Sep 2019 16:11:50 +0200
Subject: [PATCH] tests: Add test for required-flatpak versioning
This sets required-flatpak in the metadata to some different versions
and ensure we're properly able or not able to install it.
Additionally it uses some options with multiple versions. This is not
yet supported but I want to test the existing code and make sure it
properly falls back to just using the first element of the list.
Closes: #3112
Approved by: alexlarsson
(cherry picked from commit 62117308c1dd0f10f82d274d542da0d9b7f7d426)
(cherry picked from commit 5db4631a795fc642e9be2c58dd0efb2ef4ff6090)
Closes: #3115
Approved by: alexlarsson
---
tests/make-test-app.sh | 8 ++++++
tests/test-repo.sh | 56 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/tests/make-test-app.sh b/tests/make-test-app.sh
index 86afd48d8..cd3416030 100755
--- a/tests/make-test-app.sh
+++ b/tests/make-test-app.sh
@@ -25,7 +25,15 @@ cat > ${DIR}/metadata <<EOF
name=$APP_ID
runtime=org.test.Platform/$ARCH/master
sdk=org.test.Platform/$ARCH/master
+EOF
+
+if [ x${REQUIRED_VERSION-} != x ]; then
+cat >> ${DIR}/metadata <<EOF
+required-flatpak=$REQUIRED_VERSION
+EOF
+fi
+cat >> ${DIR}/metadata <<EOF
[Extension org.test.Hello.Locale]
directory=share/runtime/locale
autodelete=true
diff --git a/tests/test-repo.sh b/tests/test-repo.sh
index d0b0d3271..ee77b8c8b 100755
--- a/tests/test-repo.sh
+++ b/tests/test-repo.sh
@@ -23,7 +23,7 @@ set -euo pipefail
skip_without_bwrap
-echo "1..28"
+echo "1..29"
#Regular repo
setup_repo
@@ -234,6 +234,60 @@ assert_file_has_content install-error-log "GPG signatures found, but none are in
echo "ok fail with wrong gpg key"
+make_required_version_app () {
+ APP_ID=${1}
+ VERSION=${2}
+ if [ x${USE_COLLECTIONS_IN_SERVER-} == xyes ] ; then
+ CID=org.test.Collection.test
+ else
+ CID=""
+ fi
+
+ REQUIRED_VERSION="${VERSION}" GPGARGS="${FL_GPGARGS}" $(dirname $0)/make-test-app.sh repos/test ${APP_ID} "${CID}" > /dev/null
+}
+
+CURRENT_VERSION=`cat "$test_builddir/package_version.txt"`
+V=( ${CURRENT_VERSION//./ } ) # Split parts to array
+
+make_required_version_app org.test.SameVersion "${V[0]}.${V[1]}.${V[2]}"
+make_required_version_app org.test.NeedNewerMicro "${V[0]}.${V[1]}.$(expr ${V[2]} + 1)"
+make_required_version_app org.test.NeedNewerMinor "${V[0]}.$(expr ${V[1]} + 1).${V[2]}"
+make_required_version_app org.test.NeedNewerMaster "$(expr ${V[0]} + 1).${V[1]}.${V[2]}"
+make_required_version_app org.test.NeedOlderMinor "${V[0]}.$(expr ${V[1]} - 1).${V[2]}"
+make_required_version_app org.test.MultiVersionFallback "${V[0]}.${V[1]}.${V[2]};1.0.0;"
+make_required_version_app org.test.MultiVersionFallbackFail "${V[0]}.$(expr ${V[1]} + 1).${V[2]};1.0.0;"
+
+update_repo $REPONAME "${COLLECTION_ID}"
+
+${FLATPAK} ${U} install -y test-repo org.test.SameVersion
+${FLATPAK} ${U} install -y test-repo org.test.NeedOlderMinor
+
+if ${FLATPAK} ${U} install -y test-repo org.test.NeedNewerMicro 2> install-error-log; then
+ assert_not_reached "Should not be able to install with wrong micro version"
+fi
+assert_file_has_content install-error-log "needs a later flatpak version"
+
+if ${FLATPAK} ${U} install -y test-repo org.test.NeedNewerMinor 2> install-error-log; then
+ assert_not_reached "Should not be able to install with wrong minor version"
+fi
+assert_file_has_content install-error-log "needs a later flatpak version"
+
+if ${FLATPAK} ${U} install -y test-repo org.test.NeedNewerMajor 2> install-error-log; then
+ assert_not_reached "Should not be able to install with wrong micro version"
+fi
+assert_file_has_content install-error-log "needs a later flatpak version"
+
+${FLATPAK} ${U} install -y test-repo org.test.MultiVersionFallback
+
+if ${FLATPAK} ${U} install -y test-repo org.test.MultiVersionFallbackFail 2> install-error-log; then
+ assert_not_reached "Should not be able to install with wrong fallback version"
+fi
+assert_file_has_content install-error-log "needs a later flatpak version"
+
+${FLATPAK} ${U} uninstall -y --all
+
+echo "ok handles version requirements"
+
${FLATPAK} ${U} remotes -d | grep ^test-repo > repo-info
assert_not_file_has_content repo-info "new-title"
UPDATE_REPO_ARGS=--title=new-title update_repo