You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by gi...@apache.org on 2020/12/29 13:21:33 UTC

[buildstream] 02/02: Add test for pulling artifact refs

This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch raoul/pull-refs
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 55705aba3600f61f75859ce7f8af2c35f9f421ea
Author: Raoul Hidalgo Charman <ra...@codethink.co.uk>
AuthorDate: Fri Jul 5 15:59:51 2019 +0100

    Add test for pulling artifact refs
---
 tests/frontend/pull.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/tests/frontend/pull.py b/tests/frontend/pull.py
index a87a311..aa5853d 100644
--- a/tests/frontend/pull.py
+++ b/tests/frontend/pull.py
@@ -6,6 +6,7 @@ import shutil
 import stat
 import pytest
 from buildstream import utils
+from buildstream._exceptions import ErrorDomain
 from buildstream.testing import cli  # pylint: disable=unused-import
 from tests.testutils import create_artifact_share, generate_junction, assert_shared, assert_not_shared
 
@@ -558,3 +559,51 @@ def test_pull_access_rights(cli, tmpdir, datafiles):
         st = os.lstat(os.path.join(checkout, 'usr/share/big-file'))
         assert stat.S_ISREG(st.st_mode)
         assert stat.S_IMODE(st.st_mode) == 0o0644
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_pull_artifact_ref(cli, tmpdir, datafiles):
+    project = str(datafiles)
+
+    with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
+
+        # First build the target element and push to the remote.
+        cli.configure({
+            'artifacts': {'url': share.repo, 'push': True}
+        })
+        result = cli.run(project=project, args=['build', 'target.bst'])
+        result.assert_success()
+        assert cli.get_element_state(project, 'target.bst') == 'cached'
+
+        # Assert that everything is now cached in the remote.
+        all_elements = ['target.bst', 'import-bin.bst', 'import-dev.bst', 'compose-all.bst']
+        for element_name in all_elements:
+            assert_shared(cli, share, project, element_name)
+
+        # get target cache key to pull ref of
+        cache_key = cli.get_element_key(project, 'target.bst')
+        target = "test/target/{}".format(cache_key)
+
+        # Now we've pushed, delete the user's local artifact cache
+        # directory and try to redownload it from the share
+        #
+        casdir = os.path.join(cli.directory, 'cas')
+        shutil.rmtree(casdir)
+        artifactdir = os.path.join(cli.directory, 'artifacts')
+        shutil.rmtree(artifactdir)
+
+        # Assert that nothing is cached locally anymore
+        states = cli.get_element_states(project, all_elements)
+        assert not any(states[e] == 'cached' for e in all_elements)
+
+        # Now try bst artifact pull
+        result = cli.run(project=project, args=['artifact', 'pull', target])
+        result.assert_success()
+
+        # And assert that it's again in the local cache, without having built
+        assert cli.get_element_state(project, 'target.bst') == 'cached'
+
+        # check that it fails if you try and pull with dependencies
+        result = cli.run(project=project, args=[
+            'artifact', 'pull', '--deps', 'all', target])
+        result.assert_main_error(ErrorDomain.ELEMENT, None, debug=True)