tests: Add simple test for summary file caching
authorPhilip Withnall <pwithnall@endlessos.org>
Fri, 9 Oct 2020 17:34:55 +0000 (18:34 +0100)
committerPhilip Withnall <pwithnall@endlessos.org>
Thu, 22 Oct 2020 20:03:34 +0000 (21:03 +0100)
This test would have actually passed before the summary file caching
changes (in the previous few commits) were added, as the `summary.sig`
essentially acted as the ETag for the summary file, and itself wasn’t
updated on disk if it didn’t change when querying the server.

Actually testing that the HTTP caching headers are working to reduce
HTTP traffic would require test hooks into the pull code or the
trivial-httpd server, neither of which I have the time to add at the
moment.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Makefile-tests.am
tests/test-pull-summary-caching.sh [new file with mode: 0755]

index 3fbc94bfcf680d4c7bbff998c0bee0fe81fc2d4c..570f83890d957a24a1380e68d2093cfac123163f 100644 (file)
@@ -82,6 +82,7 @@ _installed_or_uninstalled_test_scripts = \
        tests/test-pull-mirror-summary.sh \
        tests/test-pull-large-metadata.sh \
        tests/test-pull-metalink.sh \
+       tests/test-pull-summary-caching.sh \
        tests/test-pull-summary-sigs.sh \
        tests/test-pull-resume.sh \
        tests/test-pull-basicauth.sh \
diff --git a/tests/test-pull-summary-caching.sh b/tests/test-pull-summary-caching.sh
new file mode 100755 (executable)
index 0000000..9671199
--- /dev/null
@@ -0,0 +1,66 @@
+#!/bin/bash
+#
+# Copyright © 2020 Endless OS Foundation LLC
+#
+# SPDX-License-Identifier: LGPL-2.0+
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+#
+# Authors:
+#  - Philip Withnall <pwithnall@endlessos.org>
+
+set -euo pipefail
+
+. $(dirname $0)/libtest.sh
+
+if ! has_gpgme; then
+    echo "1..0 #SKIP no gpg support compiled in"
+    exit 0
+fi
+
+COMMIT_SIGN="--gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}"
+
+echo "1..1"
+
+setup_fake_remote_repo2 "archive" "${COMMIT_SIGN}"
+
+# Create a few branches and update the summary file (and sign it)
+mkdir ${test_tmpdir}/ostree-srv/other-files
+cd ${test_tmpdir}/ostree-srv/other-files
+echo 'hello world another object' > hello-world
+${CMD_PREFIX} ostree  --repo=${test_tmpdir}/ostree-srv/gnomerepo commit ${COMMIT_SIGN} -b other -s "A commit" -m "Another Commit body"
+
+mkdir ${test_tmpdir}/ostree-srv/yet-other-files
+cd ${test_tmpdir}/ostree-srv/yet-other-files
+echo 'hello world yet another object' > yet-another-hello-world
+${CMD_PREFIX} ostree  --repo=${test_tmpdir}/ostree-srv/gnomerepo commit ${COMMIT_SIGN} -b yet-another -s "A commit" -m "Another Commit body"
+
+${CMD_PREFIX} ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo summary -u ${COMMIT_SIGN}
+
+# Test that pulling twice in a row doesn’t re-download the summary file or its signature
+cd ${test_tmpdir}
+rm -rf repo
+ostree_repo_init repo --mode=archive
+${OSTREE} --repo=repo remote add --set=gpg-verify-summary=true origin $(cat httpd-address)/ostree/gnomerepo
+${OSTREE} --repo=repo pull origin other
+assert_has_file repo/tmp/cache/summaries/origin
+assert_has_file repo/tmp/cache/summaries/origin.sig
+summary_inode="$(stat -c '%i' repo/tmp/cache/summaries/origin)"
+summary_sig_inode="$(stat -c '%i' repo/tmp/cache/summaries/origin.sig)"
+${OSTREE} --repo=repo pull origin other
+assert_streq "$(stat -c '%i' repo/tmp/cache/summaries/origin)" "${summary_inode}"
+assert_streq "$(stat -c '%i' repo/tmp/cache/summaries/origin.sig)" "${summary_sig_inode}"
+echo "ok pull caches the summary files"