summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-11-01 18:22:41 +0000
committerJonathan Maw <jonathan.maw@codethink.co.uk>2018-12-11 14:12:54 +0000
commit494cb7c65b62b915fe036d8ff39b522db0d1703c (patch)
treef845189dfc5344dce28b5762093322a53665a341
parentf145a3e4c66017ab5b2de492c4d6de538d4ec224 (diff)
downloadbuildstream-494cb7c65b62b915fe036d8ff39b522db0d1703c.tar.gz
tests: Test bst commands from an external workspace
This is a part of #222
-rw-r--r--tests/frontend/cross_junction_workspace.py20
-rw-r--r--tests/frontend/workspace.py147
-rw-r--r--tests/integration/shell.py26
3 files changed, 188 insertions, 5 deletions
diff --git a/tests/frontend/cross_junction_workspace.py b/tests/frontend/cross_junction_workspace.py
index fb2b34c43..ad2a62626 100644
--- a/tests/frontend/cross_junction_workspace.py
+++ b/tests/frontend/cross_junction_workspace.py
@@ -115,3 +115,23 @@ def test_close_all_cross_junction(cli, tmpdir):
assert isinstance(loaded.get('workspaces'), list)
workspaces = loaded['workspaces']
assert len(workspaces) == 0
+
+
+def test_subdir_command_cross_junction(cli, tmpdir):
+ # i.e. commands can be run successfully from a subdirectory of the
+ # junction's workspace, in case project loading logic has gone wrong
+ project = prepare_junction_project(cli, tmpdir)
+ workspace = os.path.join(str(tmpdir), 'workspace')
+ junction_element = 'sub.bst'
+
+ # Open the junction as a workspace
+ args = ['workspace', 'open', '--directory', workspace, junction_element]
+ result = cli.run(project=project, args=args)
+ result.assert_success()
+
+ # Run commands from a subdirectory of the workspace
+ newdir = os.path.join(str(workspace), "newdir")
+ element_name = 'data.bst'
+ os.makedirs(newdir)
+ result = cli.run(project=str(workspace), args=['-C', newdir, 'show', element_name])
+ result.assert_success()
diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py
index bc928ad51..baca869bf 100644
--- a/tests/frontend/workspace.py
+++ b/tests/frontend/workspace.py
@@ -31,6 +31,7 @@ import shutil
import subprocess
from ruamel.yaml.comments import CommentedSet
from tests.testutils import cli, create_repo, ALL_REPO_KINDS, wait_for_cache_granularity
+from tests.testutils import create_artifact_share
from buildstream import _yaml
from buildstream._exceptions import ErrorDomain, LoadError, LoadErrorReason
@@ -615,9 +616,12 @@ def test_list(cli, tmpdir, datafiles):
@pytest.mark.datafiles(DATA_DIR)
@pytest.mark.parametrize("kind", repo_kinds)
@pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
-def test_build(cli, tmpdir, datafiles, kind, strict):
+@pytest.mark.parametrize("call_from", [("project"), ("workspace")])
+def test_build(cli, tmpdir_factory, datafiles, kind, strict, call_from):
+ tmpdir = tmpdir_factory.mktemp('')
element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, kind, False)
checkout = os.path.join(str(tmpdir), 'checkout')
+ args_pre = ['-C', workspace] if call_from == "workspace" else []
# Modify workspace
shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
@@ -640,15 +644,14 @@ def test_build(cli, tmpdir, datafiles, kind, strict):
# Build modified workspace
assert cli.get_element_state(project, element_name) == 'buildable'
assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
- result = cli.run(project=project, args=['build', element_name])
+ result = cli.run(project=project, args=args_pre + ['build', element_name])
result.assert_success()
assert cli.get_element_state(project, element_name) == 'cached'
assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
# Checkout the result
- result = cli.run(project=project, args=[
- 'checkout', element_name, checkout
- ])
+ result = cli.run(project=project,
+ args=args_pre + ['checkout', element_name, checkout])
result.assert_success()
# Check that the pony.conf from the modified workspace exists
@@ -1055,3 +1058,137 @@ def test_multiple_failed_builds(cli, tmpdir, datafiles):
result = cli.run(project=project, args=["build", element_name])
assert "BUG" not in result.stderr
assert cli.get_element_state(project, element_name) != "cached"
+
+
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize('subdir', [True, False], ids=["subdir", "no-subdir"])
+def test_external_fetch(cli, datafiles, tmpdir_factory, subdir):
+ # Fetching from a workspace outside a project doesn't fail horribly
+ tmpdir = tmpdir_factory.mktemp('')
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
+
+ if subdir:
+ call_dir = os.path.join(workspace, 'usr')
+ else:
+ call_dir = workspace
+
+ result = cli.run(project=project, args=['-C', call_dir, 'fetch', element_name])
+ result.assert_success()
+
+ # We already fetched it by opening the workspace, but we're also checking
+ # `bst show` works here
+ assert cli.get_element_state(project, element_name) == 'buildable'
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_external_push_pull(cli, datafiles, tmpdir_factory):
+ # Pushing and pulling to/from an artifact cache works from an external workspace
+ tmpdir = tmpdir_factory.mktemp('')
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
+
+ with create_artifact_share(os.path.join(str(tmpdir), 'artifactshare')) as share:
+ result = cli.run(project=project, args=['-C', workspace, 'build', element_name])
+ result.assert_success()
+
+ cli.configure({
+ 'artifacts': {'url': share.repo, 'push': True}
+ })
+
+ result = cli.run(project=project, args=['-C', workspace, 'push', element_name])
+ result.assert_success()
+
+ result = cli.run(project=project, args=['-C', workspace, 'pull', '--deps', 'all', element_name])
+ result.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_external_track(cli, datafiles, tmpdir_factory):
+ # Tracking does not get horribly confused
+ tmpdir = tmpdir_factory.mktemp('')
+ element_name, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", True)
+
+ # The workspace is necessarily already tracked, so we only care that
+ # there's no weird errors.
+ result = cli.run(project=project, args=['-C', workspace, 'track', element_name])
+ result.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_external_open_other(cli, datafiles, tmpdir_factory):
+ # From inside an external workspace, open another workspace
+ tmpdir1 = tmpdir_factory.mktemp('')
+ tmpdir2 = tmpdir_factory.mktemp('')
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
+
+ # Closing the other element first, because I'm too lazy to create an
+ # element without opening it
+ result = cli.run(project=project, args=['workspace', 'close', beta_element])
+ result.assert_success()
+
+ result = cli.run(project=project, args=[
+ '-C', alpha_workspace, 'workspace', 'open', '--force', '--directory', beta_workspace, beta_element
+ ])
+ result.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_external_close_other(cli, datafiles, tmpdir_factory):
+ # From inside an external workspace, close the other workspace
+ tmpdir1 = tmpdir_factory.mktemp('')
+ tmpdir2 = tmpdir_factory.mktemp('')
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
+
+ result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', beta_element])
+ result.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_external_close_self(cli, datafiles, tmpdir_factory):
+ # From inside an external workspace, close it
+ tmpdir1 = tmpdir_factory.mktemp('')
+ tmpdir2 = tmpdir_factory.mktemp('')
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
+
+ result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'close', alpha_element])
+ result.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_external_reset_other(cli, datafiles, tmpdir_factory):
+ tmpdir1 = tmpdir_factory.mktemp('')
+ tmpdir2 = tmpdir_factory.mktemp('')
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
+ alpha_element, project, alpha_workspace = open_workspace(cli, tmpdir1, datafiles, "git", False, suffix="-alpha")
+ beta_element, _, beta_workspace = open_workspace(cli, tmpdir2, datafiles, "git", False, suffix="-beta")
+
+ result = cli.run(project=project, args=['-C', alpha_workspace, 'workspace', 'reset', beta_element])
+ result.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_external_reset_self(cli, datafiles, tmpdir):
+ element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
+
+ # Command succeeds
+ result = cli.run(project=project, args=['-C', workspace, 'workspace', 'reset', element])
+ result.assert_success()
+
+ # Successive commands still work (i.e. .bstproject.yaml hasn't been deleted)
+ result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
+ result.assert_success()
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_external_list(cli, datafiles, tmpdir_factory):
+ tmpdir = tmpdir_factory.mktemp('')
+ # Making use of the assumption that it's the same project in both invocations of open_workspace
+ element, project, workspace = open_workspace(cli, tmpdir, datafiles, "git", False)
+
+ result = cli.run(project=project, args=['-C', workspace, 'workspace', 'list'])
+ result.assert_success()
diff --git a/tests/integration/shell.py b/tests/integration/shell.py
index 68535bfdc..1cec21818 100644
--- a/tests/integration/shell.py
+++ b/tests/integration/shell.py
@@ -353,3 +353,29 @@ def test_integration_devices(cli, tmpdir, datafiles):
result = execute_shell(cli, project, ["true"], element=element_name)
assert result.exit_code == 0
+
+
+# Test that a shell can be opened from an external workspace
+@pytest.mark.datafiles(DATA_DIR)
+@pytest.mark.parametrize("build_shell", [("build"), ("nobuild")])
+@pytest.mark.skipif(IS_LINUX and not HAVE_BWRAP, reason='Only available with bubblewrap on Linux')
+def test_integration_external_workspace(cli, tmpdir_factory, datafiles, build_shell):
+ tmpdir = tmpdir_factory.mktemp("")
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ element_name = 'autotools/amhello.bst'
+ workspace_dir = os.path.join(str(tmpdir), 'workspace')
+
+ result = cli.run(project=project, args=[
+ 'workspace', 'open', '--directory', workspace_dir, element_name
+ ])
+ result.assert_success()
+
+ result = cli.run(project=project, args=['-C', workspace_dir, 'build', element_name])
+ result.assert_success()
+
+ command = ['shell']
+ if build_shell == 'build':
+ command.append('--build')
+ command.extend([element_name, '--', 'true'])
+ result = cli.run(project=project, cwd=workspace_dir, args=command)
+ result.assert_success()