Skip to content
Snippets Groups Projects
Commit 01344f51 authored by James Ennis's avatar James Ennis
Browse files

tests: Add tests for the artifact delete subcommand

parent 3ba9bb50
No related branches found
No related tags found
No related merge requests found
......@@ -66,3 +66,87 @@ def test_artifact_log(cli, tmpdir, datafiles):
assert result.exit_code == 0
# The artifact is cached under both a strong key and a weak key
assert (log + log) == result.output
# Test that we can delete the artifact of the element which corresponds
# to the current project state
@pytest.mark.integration
@pytest.mark.datafiles(DATA_DIR)
def test_artifact_delete_element(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
element = 'integration.bst'
# Build the element and ensure it's cached
result = cli.run(project=project, args=['build', element])
result.assert_success()
assert cli.get_element_state(project, element) == 'cached'
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 an artifact by specifying its ref.
@pytest.mark.integration
@pytest.mark.datafiles(DATA_DIR)
def test_artifact_delete_artifact(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
element = 'integration.bst'
# Configure a local cache
local_cache = os.path.join(str(tmpdir), 'artifacts')
cli.configure({'artifactdir': 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, 'cas', 'refs', 'heads', artifact))
# Delete the artifact
result = cli.run(project=project, args=['artifact', 'delete', artifact])
result.assert_success()
# Check that the ARTIFACT is no longer in the cache
assert not os.path.exists(os.path.join(local_cache, 'cas', 'refs', 'heads', artifact))
# Test the `bst artifact delete` command with multiple, different arguments.
@pytest.mark.integration
@pytest.mark.datafiles(DATA_DIR)
def test_artifact_delete_element_and_artifact(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
element = 'integration.bst'
dep = 'base/base-alpine.bst'
# Configure a local cache
local_cache = os.path.join(str(tmpdir), 'artifacts')
cli.configure({'artifactdir': local_cache})
# First build an element so that we can find its artifact
result = cli.run(project=project, args=['build', element])
result.assert_success()
assert cli.get_element_state(project, element) == 'cached'
assert cli.get_element_state(project, dep) == 'cached'
# 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, 'cas', 'refs', 'heads', artifact))
# Delete the artifact
result = cli.run(project=project, args=['artifact', 'delete', artifact, dep])
result.assert_success()
# Check that the ARTIFACT is no longer in the cache
assert not os.path.exists(os.path.join(local_cache, 'cas', 'refs', 'heads', artifact))
# Check that the dependency ELEMENT is no longer cached
assert cli.get_element_state(project, dep) != 'cached'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment