summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Ennis <james.ennis@codethink.co.uk>2019-08-16 16:51:50 +0100
committerJames Ennis <james.ennis@codethink.co.uk>2019-08-16 16:52:30 +0100
commitcb08ad0cd2c5b4ab0ca4beb1d608ff75b5f435ae (patch)
treef5e71c72b4ab4abbaaed152b1177ee625bce2006
parent40ce6500a750e13c24efe3da86e12bcc0213bf33 (diff)
downloadbuildstream-jennis/load_deps_from_artifact_ref.tar.gz
tests/frontend/artifact.py: test artifact delete with --deps buildjennis/load_deps_from_artifact_ref
-rw-r--r--tests/frontend/artifact.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/frontend/artifact.py b/tests/frontend/artifact.py
index 177be8c30..b4b3581b2 100644
--- a/tests/frontend/artifact.py
+++ b/tests/frontend/artifact.py
@@ -25,6 +25,7 @@ import os
import pytest
from buildstream.testing import cli # pylint: disable=unused-import
+from buildstream.utils import _get_normal_name
from tests.testutils import create_artifact_share
@@ -211,3 +212,71 @@ def test_artifact_delete_pulled_artifact_without_buildtree(cli, tmpdir, datafile
result = cli.run(project=project, args=['artifact', 'delete', element])
result.assert_success()
assert cli.get_element_state(project, element) != 'cached'
+
+
+# Test that we can delete the build deps of an element
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_delete_elements_build_deps(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element = 'target.bst'
+
+ # Build the element and ensure it's cached
+ result = cli.run(project=project, args=['build', element])
+ result.assert_success()
+
+ # Assert element and build deps are cached
+ assert cli.get_element_state(project, element) == 'cached'
+ bdep_states = cli.get_element_states(project, [element], deps='build')
+ for state in bdep_states.values():
+ assert state == 'cached'
+
+ result = cli.run(project=project, args=['artifact', 'delete', '--deps', 'build', element])
+ result.assert_success()
+
+ # Assert that the build deps have been deleted and that the artifact remains cached
+ assert cli.get_element_state(project, element) == 'cached'
+ bdep_states = cli.get_element_states(project, [element], deps='build')
+ for state in bdep_states.values():
+ assert state != 'cached'
+
+
+# Test that we can delete the build deps of an artifact by providing an artifact ref
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_delete_artifacts_build_deps(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})
+
+ # First build an element so that we can find its artifact
+ result = cli.run(project=project, args=['build', element])
+ result.assert_success()
+
+ # Obtain the artifact ref
+ cache_key = cli.get_element_key(project, element)
+ artifact = os.path.join('test', os.path.splitext(element)[0], cache_key)
+
+ # Explicitly check that the ARTIFACT exists in the cache
+ assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', artifact))
+
+ # get the artifact refs of the build dependencies
+ bdep_refs = []
+ bdep_states = cli.get_element_states(project, [element], deps='build')
+ for bdep in bdep_states.keys():
+ bdep_refs.append(os.path.join('test', _get_normal_name(bdep), cli.get_element_key(project, bdep)))
+
+ # Assert build dependencies are cached
+ for ref in bdep_refs:
+ assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', ref))
+
+ # Delete the artifact
+ result = cli.run(project=project, args=['artifact', 'delete', '--deps', 'build', artifact])
+ result.assert_success()
+
+ # Check that the artifact's build deps are no longer in the cache
+ # Assert build dependencies are cached and that the artifact remains
+ for ref in bdep_refs:
+ assert not os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', ref))
+ assert os.path.exists(os.path.join(local_cache, 'artifacts', 'refs', artifact))