From 8e654015c2eccd62d538ae6d39e78524913775b2 Mon Sep 17 00:00:00 2001 From: James Ennis Date: Thu, 29 Aug 2019 12:32:21 +0100 Subject: cli.py: Allow pull to handle artifact refs This patch adds support for the handling of artifact refs in bst artifact pull. A test for this has also been added. --- tests/frontend/buildcheckout.py | 2 +- tests/frontend/pull.py | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/frontend/buildcheckout.py b/tests/frontend/buildcheckout.py index 98b179b9e..6281217b7 100644 --- a/tests/frontend/buildcheckout.py +++ b/tests/frontend/buildcheckout.py @@ -358,7 +358,7 @@ def test_build_checkout_invalid_ref(datafiles, cli): checkout_args = ['artifact', 'checkout', '--deps', 'none', '--tar', checkout, non_existent_artifact] result = cli.run(project=project, args=checkout_args) - assert "{}\nis not present in the artifact cache".format(non_existent_artifact) in result.stderr + assert "Artifact reference '{}' seems to be invalid".format(non_existent_artifact) in result.stderr @pytest.mark.datafiles(DATA_DIR) diff --git a/tests/frontend/pull.py b/tests/frontend/pull.py index fd49ff1ef..f978258f1 100644 --- a/tests/frontend/pull.py +++ b/tests/frontend/pull.py @@ -558,3 +558,45 @@ 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 + + +# Tests `bst artifact pull $artifact_ref` +@pytest.mark.datafiles(DATA_DIR) +def test_pull_artifact(cli, tmpdir, datafiles): + project = str(datafiles) + element = 'target.bst' + + # Configure a local cache + local_cache = os.path.join(str(tmpdir), 'cache') + cli.configure({'cachedir': local_cache}) + + 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', element]) + result.assert_success() + + # Assert that the *artifact* is cached locally + cache_key = cli.get_element_key(project, element) + artifact_ref = os.path.join('test', os.path.splitext(element)[0], cache_key) + assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', artifact_ref)) + + # Assert that the target is shared (note that assert shared will use the artifact name) + assert_shared(cli, share, project, element) + + # Now we've pushed, remove the local cache + shutil.rmtree(os.path.join(local_cache, 'artifacts')) + + # Assert that nothing is cached locally anymore + assert not os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', artifact_ref)) + + # Now try bst artifact pull + result = cli.run(project=project, args=['artifact', 'pull', artifact_ref]) + result.assert_success() + + # And assert that it's again in the local cache, without having built + assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', artifact_ref)) -- cgit v1.2.1