summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-09-03 23:05:26 -0400
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-09-04 04:14:54 -0400
commitae31df34ebb556a94d678c78574254a4bac2990f (patch)
tree4da008e61dd9e71f38ab681cbaf105d2e0c34400
parent3027bc1e2b5711994427ec632eaff6ef7366b46a (diff)
downloadbuildstream-ae31df34ebb556a94d678c78574254a4bac2990f.tar.gz
tests/frontend/fetch.py: Added tests for `bst fetch`
-rw-r--r--tests/frontend/fetch.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/frontend/fetch.py b/tests/frontend/fetch.py
new file mode 100644
index 000000000..23e6b3a35
--- /dev/null
+++ b/tests/frontend/fetch.py
@@ -0,0 +1,50 @@
+import os
+import pytest
+from tests.testutils.runcli import cli
+from tests.testutils.repo import create_repo
+
+from buildstream import _yaml
+
+
+# Project directory
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project",
+)
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("kind", [('git'), ('bzr'), ('ostree'), ('tar')])
+def test_fetch(cli, tmpdir, datafiles, kind):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ bin_files_path = os.path.join(project, 'files', 'bin-files')
+ element_path = os.path.join(project, 'elements')
+ element_name = 'fetch-test-{}.bst'.format(kind)
+
+ # Create our repo object of the given source type with
+ # the bin files, and then collect the initial ref.
+ #
+ repo = create_repo(kind, str(tmpdir))
+ ref = repo.create(bin_files_path)
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ repo.source_config(ref=ref)
+ ]
+ }
+ _yaml.dump(element,
+ os.path.join(element_path,
+ element_name))
+
+ # Assert that a fetch is needed
+ assert cli.get_element_state(project, element_name) == 'fetch needed'
+
+ # Now try to fetch it
+ result = cli.run(project=project, args=['fetch', element_name])
+ assert result.exit_code == 0
+
+ # Assert that we are now buildable because the source is
+ # now cached.
+ assert cli.get_element_state(project, element_name) == 'buildable'