summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/frontend/artifact_delete.py (renamed from tests/frontend/artifact.py)242
-rw-r--r--tests/frontend/artifact_list_contents.py98
-rw-r--r--tests/frontend/artifact_log.py99
-rw-r--r--tests/frontend/artifact_show.py136
4 files changed, 334 insertions, 241 deletions
diff --git a/tests/frontend/artifact.py b/tests/frontend/artifact_delete.py
index 9ad03909e..80870c81a 100644
--- a/tests/frontend/artifact.py
+++ b/tests/frontend/artifact_delete.py
@@ -1,6 +1,5 @@
#
-# Copyright (C) 2018 Codethink Limited
-# Copyright (C) 2018 Bloomberg Finance LP
+# Copyright (C) 2019 Codethink Limited
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -15,8 +14,6 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
#
-# Authors: Richard Maw <richard.maw@codethink.co.uk>
-#
# Pylint doesn't play well with fixtures and dependency injection from pytest
# pylint: disable=redefined-outer-name
@@ -37,140 +34,6 @@ DATA_DIR = os.path.join(
)
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_log(cli, datafiles):
- project = str(datafiles)
-
- # Get the cache key of our test element
- result = cli.run(project=project, silent=True, args=[
- '--no-colors',
- 'show', '--deps', 'none', '--format', '%{full-key}',
- 'target.bst'
- ])
- key = result.output.strip()
-
- # Ensure we have an artifact to read
- result = cli.run(project=project, args=['build', 'target.bst'])
- assert result.exit_code == 0
-
- # Read the log via the element name
- result = cli.run(project=project, args=['artifact', 'log', 'target.bst'])
- assert result.exit_code == 0
- log = result.output
-
- # Assert that there actually was a log file
- assert log != ''
-
- # Read the log via the key
- result = cli.run(project=project, args=['artifact', 'log', 'test/target/' + key])
- assert result.exit_code == 0
- assert log == result.output
-
- # Read the log via glob
- result = cli.run(project=project, args=['artifact', 'log', 'test/target/*'])
- assert result.exit_code == 0
- assert log == result.output
-
-
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_list_exact_contents_element(cli, datafiles):
- project = str(datafiles)
-
- # Ensure we have an artifact to read
- result = cli.run(project=project, args=['build', 'import-bin.bst'])
- assert result.exit_code == 0
-
- # List the contents via the element name
- result = cli.run(project=project, args=['artifact', 'list-contents', 'import-bin.bst'])
- assert result.exit_code == 0
- expected_output = ("import-bin.bst:\n"
- "\tusr\n"
- "\tusr/bin\n"
- "\tusr/bin/hello\n\n")
- assert expected_output in result.output
-
-
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_list_exact_contents_ref(cli, datafiles):
- project = str(datafiles)
-
- # Get the cache key of our test element
- key = cli.get_element_key(project, 'import-bin.bst')
-
- # Ensure we have an artifact to read
- result = cli.run(project=project, args=['build', 'import-bin.bst'])
- assert result.exit_code == 0
-
- # List the contents via the key
- result = cli.run(project=project, args=['artifact', 'list-contents', 'test/import-bin/' + key])
- assert result.exit_code == 0
-
- expected_output = ("test/import-bin/" + key + ":\n"
- "\tusr\n"
- "\tusr/bin\n"
- "\tusr/bin/hello\n\n")
- assert expected_output in result.output
-
-
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_list_exact_contents_glob(cli, datafiles):
- project = str(datafiles)
-
- # Ensure we have an artifact to read
- result = cli.run(project=project, args=['build', 'target.bst'])
- assert result.exit_code == 0
-
- # List the contents via glob
- result = cli.run(project=project, args=['artifact', 'list-contents', 'test/*'])
- assert result.exit_code == 0
-
- # get the cahe keys for each element in the glob
- import_bin_key = cli.get_element_key(project, 'import-bin.bst')
- import_dev_key = cli.get_element_key(project, 'import-dev.bst')
- compose_all_key = cli.get_element_key(project, 'compose-all.bst')
- target_key = cli.get_element_key(project, 'target.bst')
-
- expected_artifacts = ["test/import-bin/" + import_bin_key,
- "test/import-dev/" + import_dev_key,
- "test/compose-all/" + compose_all_key,
- "test/target/" + target_key]
-
- for artifact in expected_artifacts:
- assert artifact in result.output
-
-
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_log_files(cli, datafiles):
- project = str(datafiles)
-
- # Ensure we have an artifact to read
- result = cli.run(project=project, args=['build', 'target.bst'])
- assert result.exit_code == 0
-
- logfiles = os.path.join(project, "logfiles")
- target = os.path.join(project, logfiles, "target.log")
- import_bin = os.path.join(project, logfiles, "import-bin.log")
- # Ensure the logfile doesn't exist before the command is run
- assert not os.path.exists(logfiles)
- assert not os.path.exists(target)
- assert not os.path.exists(import_bin)
-
- # Run the command and ensure the file now exists
- result = cli.run(project=project, args=['artifact', 'log', '--out', logfiles, 'target.bst', 'import-bin.bst'])
- assert result.exit_code == 0
- assert os.path.exists(logfiles)
- assert os.path.exists(target)
- assert os.path.exists(import_bin)
-
- # Ensure the file contains the logs by checking for the LOG line
- with open(target, 'r') as f:
- data = f.read()
- assert "LOG target.bst" in data
- with open(import_bin, 'r') as f:
- data = f.read()
- assert "LOG import-bin.bst" in data
-
-
# Test that we can delete the artifact of the element which corresponds
# to the current project state
@pytest.mark.datafiles(DATA_DIR)
@@ -400,106 +263,3 @@ def test_artifact_delete_artifact_with_deps_all_fails(cli, tmpdir, datafiles):
result.assert_main_error(ErrorDomain.STREAM, None)
assert "Error: '--deps all' is not supported for artifact refs" in result.stderr
-
-
-# Test artifact show
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_show_element_name(cli, tmpdir, datafiles):
- project = str(datafiles)
- element = 'target.bst'
-
- result = cli.run(project=project, args=['artifact', 'show', element])
- result.assert_success()
- assert 'not cached {}'.format(element) in result.output
-
- result = cli.run(project=project, args=['build', element])
- result.assert_success()
-
- result = cli.run(project=project, args=['artifact', 'show', element])
- result.assert_success()
- assert 'cached {}'.format(element) in result.output
-
-
-# Test artifact show on a failed element
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_show_failed_element(cli, tmpdir, datafiles):
- project = str(datafiles)
- element = 'manual.bst'
-
- result = cli.run(project=project, args=['artifact', 'show', element])
- result.assert_success()
- assert 'not cached {}'.format(element) in result.output
-
- result = cli.run(project=project, args=['build', element])
- result.assert_task_error(ErrorDomain.SANDBOX, 'missing-command')
-
- result = cli.run(project=project, args=['artifact', 'show', element])
- result.assert_success()
- assert 'failed {}'.format(element) in result.output
-
-
-# Test artifact show with a deleted dependency
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_show_element_missing_deps(cli, tmpdir, datafiles):
- project = str(datafiles)
- element = 'target.bst'
- dependency = 'import-bin.bst'
-
- result = cli.run(project=project, args=['build', element])
- result.assert_success()
-
- result = cli.run(project=project, args=['artifact', 'delete', dependency])
- result.assert_success()
-
- result = cli.run(project=project, args=['artifact', 'show', '--deps', 'all', element])
- result.assert_success()
- assert 'not cached {}'.format(dependency) in result.output
- assert 'cached {}'.format(element) in result.output
-
-
-# Test artifact show with artifact ref
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_show_artifact_ref(cli, tmpdir, datafiles):
- project = str(datafiles)
- element = 'target.bst'
-
- result = cli.run(project=project, args=['build', element])
- result.assert_success()
-
- cache_key = cli.get_element_key(project, element)
- artifact_ref = 'test/target/' + cache_key
-
- result = cli.run(project=project, args=['artifact', 'show', artifact_ref])
- result.assert_success()
- assert 'cached {}'.format(artifact_ref) in result.output
-
-
-# Test artifact show artifact in remote
-@pytest.mark.datafiles(DATA_DIR)
-def test_artifact_show_element_available_remotely(cli, tmpdir, datafiles):
- project = str(datafiles)
- element = 'target.bst'
-
- # Set up remote and local shares
- local_cache = os.path.join(str(tmpdir), 'artifacts')
- with create_artifact_share(os.path.join(str(tmpdir), 'remote')) as remote:
- cli.configure({
- 'artifacts': {'url': remote.repo, 'push': True},
- 'cachedir': local_cache,
- })
-
- # Build the element
- result = cli.run(project=project, args=['build', element])
- result.assert_success()
-
- # Make sure it's in the share
- assert remote.has_artifact(cli.get_artifact_name(project, 'test', element))
-
- # Delete the artifact from the local cache
- result = cli.run(project=project, args=['artifact', 'delete', element])
- result.assert_success()
- assert cli.get_element_state(project, element) != 'cached'
-
- result = cli.run(project=project, args=['artifact', 'show', element])
- result.assert_success()
- assert 'available {}'.format(element) in result.output
diff --git a/tests/frontend/artifact_list_contents.py b/tests/frontend/artifact_list_contents.py
new file mode 100644
index 000000000..5bb08e3fa
--- /dev/null
+++ b/tests/frontend/artifact_list_contents.py
@@ -0,0 +1,98 @@
+#
+# Copyright (C) 2019 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+
+from buildstream.testing import cli # pylint: disable=unused-import
+
+
+# Project directory
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project",
+)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_list_exact_contents_element(cli, datafiles):
+ project = str(datafiles)
+
+ # Ensure we have an artifact to read
+ result = cli.run(project=project, args=['build', 'import-bin.bst'])
+ assert result.exit_code == 0
+
+ # List the contents via the element name
+ result = cli.run(project=project, args=['artifact', 'list-contents', 'import-bin.bst'])
+ assert result.exit_code == 0
+ expected_output = ("import-bin.bst:\n"
+ "\tusr\n"
+ "\tusr/bin\n"
+ "\tusr/bin/hello\n\n")
+ assert expected_output in result.output
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_list_exact_contents_ref(cli, datafiles):
+ project = str(datafiles)
+
+ # Get the cache key of our test element
+ key = cli.get_element_key(project, 'import-bin.bst')
+
+ # Ensure we have an artifact to read
+ result = cli.run(project=project, args=['build', 'import-bin.bst'])
+ assert result.exit_code == 0
+
+ # List the contents via the key
+ result = cli.run(project=project, args=['artifact', 'list-contents', 'test/import-bin/' + key])
+ assert result.exit_code == 0
+
+ expected_output = ("test/import-bin/" + key + ":\n"
+ "\tusr\n"
+ "\tusr/bin\n"
+ "\tusr/bin/hello\n\n")
+ assert expected_output in result.output
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_list_exact_contents_glob(cli, datafiles):
+ project = str(datafiles)
+
+ # Ensure we have an artifact to read
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ assert result.exit_code == 0
+
+ # List the contents via glob
+ result = cli.run(project=project, args=['artifact', 'list-contents', 'test/*'])
+ assert result.exit_code == 0
+
+ # get the cahe keys for each element in the glob
+ import_bin_key = cli.get_element_key(project, 'import-bin.bst')
+ import_dev_key = cli.get_element_key(project, 'import-dev.bst')
+ compose_all_key = cli.get_element_key(project, 'compose-all.bst')
+ target_key = cli.get_element_key(project, 'target.bst')
+
+ expected_artifacts = ["test/import-bin/" + import_bin_key,
+ "test/import-dev/" + import_dev_key,
+ "test/compose-all/" + compose_all_key,
+ "test/target/" + target_key]
+
+ for artifact in expected_artifacts:
+ assert artifact in result.output
diff --git a/tests/frontend/artifact_log.py b/tests/frontend/artifact_log.py
new file mode 100644
index 000000000..39c9458ad
--- /dev/null
+++ b/tests/frontend/artifact_log.py
@@ -0,0 +1,99 @@
+#
+# Copyright (C) 2019 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+
+from buildstream.testing import cli # pylint: disable=unused-import
+
+
+# Project directory
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project",
+)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_log(cli, datafiles):
+ project = str(datafiles)
+
+ # Get the cache key of our test element
+ result = cli.run(project=project, silent=True, args=[
+ '--no-colors',
+ 'show', '--deps', 'none', '--format', '%{full-key}',
+ 'target.bst'
+ ])
+ key = result.output.strip()
+
+ # Ensure we have an artifact to read
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ assert result.exit_code == 0
+
+ # Read the log via the element name
+ result = cli.run(project=project, args=['artifact', 'log', 'target.bst'])
+ assert result.exit_code == 0
+ log = result.output
+
+ # Assert that there actually was a log file
+ assert log != ''
+
+ # Read the log via the key
+ result = cli.run(project=project, args=['artifact', 'log', 'test/target/' + key])
+ assert result.exit_code == 0
+ assert log == result.output
+
+ # Read the log via glob
+ result = cli.run(project=project, args=['artifact', 'log', 'test/target/*'])
+ assert result.exit_code == 0
+ # The artifact is cached under both a strong key and a weak key
+ assert log == result.output
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_log_files(cli, datafiles):
+ project = str(datafiles)
+
+ # Ensure we have an artifact to read
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ assert result.exit_code == 0
+
+ logfiles = os.path.join(project, "logfiles")
+ target = os.path.join(project, logfiles, "target.log")
+ import_bin = os.path.join(project, logfiles, "import-bin.log")
+ # Ensure the logfile doesn't exist before the command is run
+ assert not os.path.exists(logfiles)
+ assert not os.path.exists(target)
+ assert not os.path.exists(import_bin)
+
+ # Run the command and ensure the file now exists
+ result = cli.run(project=project, args=['artifact', 'log', '--out', logfiles, 'target.bst', 'import-bin.bst'])
+ assert result.exit_code == 0
+ assert os.path.exists(logfiles)
+ assert os.path.exists(target)
+ assert os.path.exists(import_bin)
+
+ # Ensure the file contains the logs by checking for the LOG line
+ with open(target, 'r') as f:
+ data = f.read()
+ assert "LOG target.bst" in data
+ with open(import_bin, 'r') as f:
+ data = f.read()
+ assert "LOG import-bin.bst" in data
diff --git a/tests/frontend/artifact_show.py b/tests/frontend/artifact_show.py
new file mode 100644
index 000000000..913dde9c8
--- /dev/null
+++ b/tests/frontend/artifact_show.py
@@ -0,0 +1,136 @@
+#
+# Copyright (C) 2019 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+#
+
+# Pylint doesn't play well with fixtures and dependency injection from pytest
+# pylint: disable=redefined-outer-name
+
+import os
+import pytest
+
+from buildstream._exceptions import ErrorDomain
+from buildstream.testing import cli # pylint: disable=unused-import
+from tests.testutils import create_artifact_share
+
+
+# Project directory
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project",
+)
+
+
+# Test artifact show
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_show_element_name(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element = 'target.bst'
+
+ result = cli.run(project=project, args=['artifact', 'show', element])
+ result.assert_success()
+ assert 'not cached {}'.format(element) in result.output
+
+ result = cli.run(project=project, args=['build', element])
+ result.assert_success()
+
+ result = cli.run(project=project, args=['artifact', 'show', element])
+ result.assert_success()
+ assert 'cached {}'.format(element) in result.output
+
+
+# Test artifact show on a failed element
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_show_failed_element(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element = 'manual.bst'
+
+ result = cli.run(project=project, args=['artifact', 'show', element])
+ result.assert_success()
+ assert 'not cached {}'.format(element) in result.output
+
+ result = cli.run(project=project, args=['build', element])
+ result.assert_task_error(ErrorDomain.SANDBOX, 'missing-command')
+
+ result = cli.run(project=project, args=['artifact', 'show', element])
+ result.assert_success()
+ assert 'failed {}'.format(element) in result.output
+
+
+# Test artifact show with a deleted dependency
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_show_element_missing_deps(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element = 'target.bst'
+ dependency = 'import-bin.bst'
+
+ result = cli.run(project=project, args=['build', element])
+ result.assert_success()
+
+ result = cli.run(project=project, args=['artifact', 'delete', dependency])
+ result.assert_success()
+
+ result = cli.run(project=project, args=['artifact', 'show', '--deps', 'all', element])
+ result.assert_success()
+ assert 'not cached {}'.format(dependency) in result.output
+ assert 'cached {}'.format(element) in result.output
+
+
+# Test artifact show with artifact ref
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_show_artifact_ref(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element = 'target.bst'
+
+ result = cli.run(project=project, args=['build', element])
+ result.assert_success()
+
+ cache_key = cli.get_element_key(project, element)
+ artifact_ref = 'test/target/' + cache_key
+
+ result = cli.run(project=project, args=['artifact', 'show', artifact_ref])
+ result.assert_success()
+ assert 'cached {}'.format(artifact_ref) in result.output
+
+
+# Test artifact show artifact in remote
+@pytest.mark.datafiles(DATA_DIR)
+def test_artifact_show_element_available_remotely(cli, tmpdir, datafiles):
+ project = str(datafiles)
+ element = 'target.bst'
+
+ # Set up remote and local shares
+ local_cache = os.path.join(str(tmpdir), 'artifacts')
+ with create_artifact_share(os.path.join(str(tmpdir), 'remote')) as remote:
+ cli.configure({
+ 'artifacts': {'url': remote.repo, 'push': True},
+ 'cachedir': local_cache,
+ })
+
+ # Build the element
+ result = cli.run(project=project, args=['build', element])
+ result.assert_success()
+
+ # Make sure it's in the share
+ assert remote.has_artifact(cli.get_artifact_name(project, 'test', element))
+
+ # Delete the artifact from the local cache
+ result = cli.run(project=project, args=['artifact', 'delete', element])
+ result.assert_success()
+ assert cli.get_element_state(project, element) != 'cached'
+
+ result = cli.run(project=project, args=['artifact', 'show', element])
+ result.assert_success()
+ assert 'available {}'.format(element) in result.output