Blame tests/test-find-remotes.sh

Packit Service 2a3f3d
#!/bin/bash
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# Copyright © 2017 Endless Mobile, Inc.
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# SPDX-License-Identifier: LGPL-2.0+
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# This library is free software; you can redistribute it and/or
Packit Service 2a3f3d
# modify it under the terms of the GNU Lesser General Public
Packit Service 2a3f3d
# License as published by the Free Software Foundation; either
Packit Service 2a3f3d
# version 2 of the License, or (at your option) any later version.
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# This library is distributed in the hope that it will be useful,
Packit Service 2a3f3d
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 2a3f3d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 2a3f3d
# Lesser General Public License for more details.
Packit Service 2a3f3d
#
Packit Service 2a3f3d
# You should have received a copy of the GNU Lesser General Public
Packit Service 2a3f3d
# License along with this library; if not, write to the
Packit Service 2a3f3d
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service 2a3f3d
# Boston, MA 02111-1307, USA.
Packit Service 2a3f3d
Packit Service 2a3f3d
set -euo pipefail
Packit Service 2a3f3d
Packit Service 2a3f3d
. $(dirname $0)/libtest.sh
Packit Service 2a3f3d
Packit Service 2a3f3d
skip_without_gpgme
Packit Service 2a3f3d
Packit Service 2a3f3d
echo '1..1'
Packit Service 2a3f3d
Packit Service 2a3f3d
# Create two upstream collection repositories with some example commits
Packit Service 2a3f3d
cd ${test_tmpdir}
Packit Service 2a3f3d
Packit Service 2a3f3d
mkdir apps-collection
Packit Service 2a3f3d
ostree_repo_init apps-collection --collection-id org.example.AppsCollection
Packit Service 2a3f3d
mkdir -p files
Packit Service 2a3f3d
pushd files
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=../apps-collection commit -s "Test apps-collection commit 1" -b app1 --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1} > ../app1-checksum
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=../apps-collection commit -s "Test apps-collection commit 2" -b app2 --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1} > ../app2-checksum
Packit Service 2a3f3d
popd
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=apps-collection summary --update --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_1}
Packit Service 2a3f3d
Packit Service 2a3f3d
mkdir os-collection
Packit Service 2a3f3d
ostree_repo_init os-collection --collection-id org.example.OsCollection
Packit Service 2a3f3d
mkdir -p files
Packit Service 2a3f3d
pushd files
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=../os-collection commit -s "Test os-collection commit 1" -b os/amd64/master --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_2} > ../os-checksum
Packit Service 2a3f3d
popd
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=os-collection summary --update --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_2}
Packit Service 2a3f3d
Packit Service 2a3f3d
# Create a local repository where we pull the branches from the two remotes as normal, using GPG.
Packit Service 2a3f3d
mkdir local
Packit Service 2a3f3d
ostree_repo_init local
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local remote add apps-remote file://$(pwd)/apps-collection --collection-id org.example.AppsCollection --gpg-import=${test_tmpdir}/gpghome/key1.asc
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local remote add os-remote file://$(pwd)/os-collection --collection-id org.example.OsCollection --gpg-import=${test_tmpdir}/gpghome/key2.asc
Packit Service 2a3f3d
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local pull apps-remote app1
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local pull os-remote os/amd64/master
Packit Service 2a3f3d
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local refs > refs
Packit Service 2a3f3d
assert_file_has_content refs "^apps-remote:app1$"
Packit Service 2a3f3d
assert_file_has_content refs "^os-remote:os/amd64/master$"
Packit Service 2a3f3d
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local refs --collections > refs
Packit Service 2a3f3d
cat refs | wc -l > refscount
Packit Service 2a3f3d
assert_file_has_content refs "^(org\.example\.AppsCollection, app1)$"
Packit Service 2a3f3d
assert_file_has_content refs "^(org\.example\.OsCollection, os/amd64/master)$"
Packit Service 2a3f3d
assert_file_has_content refscount "^2$"
Packit Service 2a3f3d
Packit Service 2a3f3d
# Create a local mirror repository where we pull the branches *in mirror mode* from the two remotes.
Packit Service 2a3f3d
# This should pull them into refs/mirrors, since the remotes advertise a collection ID.
Packit Service 2a3f3d
mkdir local-mirror
Packit Service 2a3f3d
ostree_repo_init local-mirror
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local-mirror remote add apps-remote file://$(pwd)/apps-collection --collection-id org.example.AppsCollection --gpg-import=${test_tmpdir}/gpghome/key1.asc
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local-mirror remote add os-remote file://$(pwd)/os-collection --collection-id org.example.OsCollection --gpg-import=${test_tmpdir}/gpghome/key2.asc
Packit Service 2a3f3d
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local-mirror pull --mirror apps-remote app1
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local-mirror pull --mirror os-remote os/amd64/master
Packit Service 2a3f3d
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local-mirror refs | wc -l > refscount
Packit Service 2a3f3d
assert_file_has_content refscount "^0$"
Packit Service 2a3f3d
ls -1 local-mirror/refs/remotes | wc -l > remotescount
Packit Service 2a3f3d
assert_file_has_content remotescount "^0$"
Packit Service 2a3f3d
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local-mirror refs --collections > refs
Packit Service 2a3f3d
assert_file_has_content refs "^(org\.example\.AppsCollection, app1)$"
Packit Service 2a3f3d
assert_file_has_content refs "^(org\.example\.OsCollection, os/amd64/master)$"
Packit Service 2a3f3d
Packit Service 2a3f3d
assert_file_has_content local-mirror/refs/mirrors/org.example.AppsCollection/app1 "^$(cat app1-checksum)$"
Packit Service 2a3f3d
assert_file_has_content local-mirror/refs/mirrors/org.example.OsCollection/os/amd64/master "^$(cat os-checksum)$"
Packit Service 2a3f3d
Packit Service 2a3f3d
for repo in local local-mirror; do
Packit Service 2a3f3d
    # Try finding an update for an existing branch.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config org.example.AppsCollection app1 > find
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/apps-collection$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: apps-remote\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.AppsCollection, app1) = $(cat app1-checksum)$"
Packit Service 2a3f3d
    assert_file_has_content find "^1/1 refs were found\.$"
Packit Service 2a3f3d
    assert_not_file_has_content find "^No results\.$"
Packit Service 2a3f3d
Packit Service 2a3f3d
    # Find several updates for several existing branches.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config org.example.AppsCollection app1 org.example.OsCollection os/amd64/master > find
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/apps-collection$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: apps-remote\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.AppsCollection, app1) = $(cat app1-checksum)$"
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/os-collection$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: os-remote\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.OsCollection, os/amd64/master) = $(cat os-checksum)$"
Packit Service 2a3f3d
    assert_file_has_content find "^2/2 refs were found\.$"
Packit Service 2a3f3d
    assert_not_file_has_content find "^No results\.$"
Packit Service 2a3f3d
Packit Service 2a3f3d
    # Find some updates and a new branch.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config org.example.AppsCollection app1 org.example.AppsCollection app2 org.example.OsCollection os/amd64/master > find
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/apps-collection$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: apps-remote\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.AppsCollection, app1) = $(cat app1-checksum)$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.AppsCollection, app2) = $(cat app2-checksum)$"
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/os-collection$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: os-remote\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.OsCollection, os/amd64/master) = $(cat os-checksum)$"
Packit Service 2a3f3d
    assert_file_has_content find "^3/3 refs were found\.$"
Packit Service 2a3f3d
    assert_not_file_has_content find "^No results\.$"
Packit Service 2a3f3d
Packit Service 2a3f3d
    # Find an update and a non-existent branch.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config org.example.AppsCollection app1 org.example.AppsCollection not-an-app > find
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/apps-collection$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: apps-remote\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.AppsCollection, not-an-app) = (not found)$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.AppsCollection, app1) = $(cat app1-checksum)$"
Packit Service 2a3f3d
    assert_file_has_content find "^Refs not found in any remote:$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - (org\.example\.AppsCollection, not-an-app)$"
Packit Service 2a3f3d
    assert_file_has_content find "^1/2 refs were found\.$"
Packit Service 2a3f3d
    assert_not_file_has_content find "^No results\.$"
Packit Service 2a3f3d
Packit Service 2a3f3d
    # Do all the above, but pull this time.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config --pull org.example.AppsCollection app1 > pull || true
Packit Service 2a3f3d
    assert_file_has_content pull "^1/1 refs were found\.$"
Packit Service 2a3f3d
    assert_file_has_content pull "^Pulled 1/1 refs successfully\.$"
Packit Service 2a3f3d
    assert_not_file_has_content pull "Failed to pull some refs from the remotes"
Packit Service 2a3f3d
    assert_ref $repo app1 $(cat app1-checksum)
Packit Service 2a3f3d
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config --pull org.example.AppsCollection app1 org.example.OsCollection os/amd64/master > pull
Packit Service 2a3f3d
    assert_file_has_content pull "^2/2 refs were found\.$"
Packit Service 2a3f3d
    assert_file_has_content pull "^Pulled 2/2 refs successfully\.$"
Packit Service 2a3f3d
    assert_not_file_has_content pull "Failed to pull some refs from the remotes"
Packit Service 2a3f3d
    assert_ref $repo app1 $(cat app1-checksum)
Packit Service 2a3f3d
    assert_ref $repo os/amd64/master $(cat os-checksum)
Packit Service 2a3f3d
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config --pull org.example.AppsCollection app1 org.example.AppsCollection app2 org.example.OsCollection os/amd64/master > pull
Packit Service 2a3f3d
    assert_file_has_content pull "^3/3 refs were found\.$"
Packit Service 2a3f3d
    assert_file_has_content pull "^Pulled 3/3 refs successfully\.$"
Packit Service 2a3f3d
    assert_not_file_has_content pull "Failed to pull some refs from the remotes"
Packit Service 2a3f3d
    assert_ref $repo app1 $(cat app1-checksum)
Packit Service 2a3f3d
    assert_ref $repo app2 $(cat app2-checksum)
Packit Service 2a3f3d
    assert_ref $repo os/amd64/master $(cat os-checksum)
Packit Service 2a3f3d
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config --pull org.example.AppsCollection app1 org.example.AppsCollection not-an-app > pull
Packit Service 2a3f3d
    assert_file_has_content pull "^1/2 refs were found\.$"
Packit Service 2a3f3d
    assert_not_file_has_content pull "Failed to pull some refs from the remotes"
Packit Service 2a3f3d
    assert_ref $repo app1 $(cat app1-checksum)
Packit Service 2a3f3d
    assert_not_ref $repo not-an-app
Packit Service 2a3f3d
done
Packit Service 2a3f3d
Packit Service 2a3f3d
# Test pulling a new commit into the local mirror from one of the repositories.
Packit Service 2a3f3d
pushd files
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=../os-collection commit -s "Test os-collection commit 2" -b os/amd64/master --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_2} > ../os-checksum-2
Packit Service 2a3f3d
popd
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=os-collection summary --update --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_2}
Packit Service 2a3f3d
Packit Service 2a3f3d
for repo in local-mirror; do
Packit Service 2a3f3d
    # Try finding an update for that branch.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config org.example.OsCollection os/amd64/master > find
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/os-collection$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: os-remote\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.OsCollection, os/amd64/master) = $(cat os-checksum-2)$"
Packit Service 2a3f3d
    assert_file_has_content find "^1/1 refs were found\.$"
Packit Service 2a3f3d
    assert_not_file_has_content find "^No results\.$"
Packit Service 2a3f3d
Packit Service 2a3f3d
    # Pull it.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config --pull org.example.OsCollection os/amd64/master > pull || true
Packit Service 2a3f3d
    assert_file_has_content pull "^1/1 refs were found\.$"
Packit Service 2a3f3d
    assert_file_has_content pull "^Pulled 1/1 refs successfully\.$"
Packit Service 2a3f3d
    assert_not_file_has_content pull "Failed to pull some refs from the remotes"
Packit Service 2a3f3d
    assert_ref $repo os/amd64/master $(cat os-checksum-2)
Packit Service 2a3f3d
Packit Service 2a3f3d
    # We need to manually update the refs afterwards, since the original pull
Packit Service 2a3f3d
    # into the local-mirror was a --mirror pull — so it wrote refs/mirrors/blah.
Packit Service 2a3f3d
    # This pull was not, so it wrote refs/remotes/blah.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo refs --collections --create org.example.OsCollection:os/amd64/master os-remote:os/amd64/master
Packit Service 2a3f3d
done
Packit Service 2a3f3d
Packit Service 2a3f3d
# Add the local mirror to the local repository as a remote, so that the local repo
Packit Service 2a3f3d
# has two configured remotes for the os-collection. Ensure its summary is up to date first.
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local-mirror summary --update
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=local remote add os-remote-local-mirror file://$(pwd)/local-mirror --collection-id org.example.OsCollection --gpg-import=${test_tmpdir}/gpghome/key2.asc
Packit Service 2a3f3d
Packit Service 2a3f3d
for repo in local; do
Packit Service 2a3f3d
    # Try finding an update for that branch.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config org.example.OsCollection os/amd64/master > find
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/os-collection$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: os-remote\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.OsCollection, os/amd64/master) = $(cat os-checksum-2)$"
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/local-mirror$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: os-remote-local-mirror\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.OsCollection, os/amd64/master) = $(cat os-checksum-2)$"
Packit Service 2a3f3d
    assert_file_has_content find "^1/1 refs were found\.$"
Packit Service 2a3f3d
    assert_not_file_has_content find "^No results\.$"
Packit Service 2a3f3d
Packit Service 2a3f3d
    # Pull it.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config --pull org.example.OsCollection os/amd64/master > pull || true
Packit Service 2a3f3d
    assert_file_has_content pull "^1/1 refs were found\.$"
Packit Service 2a3f3d
    assert_file_has_content pull "^Pulled 1/1 refs successfully\.$"
Packit Service 2a3f3d
    assert_not_file_has_content pull "Failed to pull some refs from the remotes"
Packit Service 2a3f3d
    assert_ref $repo os/amd64/master $(cat os-checksum-2)
Packit Service 2a3f3d
done
Packit Service 2a3f3d
Packit Service 2a3f3d
# Add another commit to the OS collection, but don’t update the mirror. Then try pulling
Packit Service 2a3f3d
# into the local repository again, and check that the outdated ref in the mirror is ignored.
Packit Service 2a3f3d
pushd files
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=../os-collection commit -s "Test os-collection commit 3" -b os/amd64/master --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_2} > ../os-checksum-3
Packit Service 2a3f3d
popd
Packit Service 2a3f3d
${CMD_PREFIX} ostree --repo=os-collection summary --update --gpg-homedir=${TEST_GPG_KEYHOME} --gpg-sign=${TEST_GPG_KEYID_2}
Packit Service 2a3f3d
Packit Service 2a3f3d
for repo in local; do
Packit Service 2a3f3d
    # Try finding an update for that branch.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config org.example.OsCollection os/amd64/master > find
Packit Service 2a3f3d
    assert_file_has_content find "^Result [0-9]\+: file://$(pwd)/os-collection$"
Packit Service 2a3f3d
    assert_file_has_content find "^ - Keyring: os-remote\.trustedkeys\.gpg$"
Packit Service 2a3f3d
    assert_file_has_content find "^    - (org\.example\.OsCollection, os/amd64/master) = $(cat os-checksum-3)$"
Packit Service 2a3f3d
    assert_file_has_content find "^1/1 refs were found\.$"
Packit Service 2a3f3d
    assert_not_file_has_content find "^No results\.$"
Packit Service 2a3f3d
Packit Service 2a3f3d
    # Pull it.
Packit Service 2a3f3d
    ${CMD_PREFIX} ostree --repo=$repo find-remotes --finders=config --pull org.example.OsCollection os/amd64/master > pull || true
Packit Service 2a3f3d
    assert_file_has_content pull "^1/1 refs were found\.$"
Packit Service 2a3f3d
    assert_file_has_content pull "^Pulled 1/1 refs successfully\.$"
Packit Service 2a3f3d
    assert_not_file_has_content pull "Failed to pull some refs from the remotes"
Packit Service 2a3f3d
    assert_ref $repo os/amd64/master $(cat os-checksum-3)
Packit Service 2a3f3d
done
Packit Service 2a3f3d
Packit Service 2a3f3d
echo "ok find-remotes"