summaryrefslogtreecommitdiff
path: root/tests/integration/script.py
diff options
context:
space:
mode:
authorTristan Maat <tm@tlater.net>2018-01-11 08:25:37 +0000
committerTristan Maat <tristan.maat@codethink.co.uk>2018-02-07 16:14:11 +0000
commiteeed9f62eec752e3071211ccbdca1139e6e3448b (patch)
tree2d246fa3c02358d53037a2c7a41c18d2acefdf90 /tests/integration/script.py
parent11c8f386bbf2c416705f4b6399b20b49f33dbde2 (diff)
downloadbuildstream-eeed9f62eec752e3071211ccbdca1139e6e3448b.tar.gz
Merge integration tests into general tests
Diffstat (limited to 'tests/integration/script.py')
-rw-r--r--tests/integration/script.py159
1 files changed, 159 insertions, 0 deletions
diff --git a/tests/integration/script.py b/tests/integration/script.py
new file mode 100644
index 000000000..d7448c4d5
--- /dev/null
+++ b/tests/integration/script.py
@@ -0,0 +1,159 @@
+import os
+import pytest
+
+from buildstream import _yaml
+
+from tests.testutils import cli_integration as cli
+from tests.testutils.integration import format_files, walk_dir
+
+
+pytestmark = pytest.mark.integration
+
+
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ "project"
+)
+
+
+def create_script_element(name, path, config={}, variables={}):
+ element = {
+ 'kind': 'script',
+ 'depends': [{
+ 'filename': 'base.bst',
+ 'type': 'build'
+ }],
+ 'config': config,
+ 'variables': variables
+ }
+ os.makedirs(os.path.dirname(os.path.join(path, name)), exist_ok=True)
+ _yaml.dump(element, os.path.join(path, name))
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_script(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkout = os.path.join(cli.directory, 'checkout')
+ element_path = os.path.join(project, 'elements')
+ element_name = 'script/script-layout.bst'
+
+ create_script_element(element_name, element_path,
+ config={
+ 'commands': [
+ "mkdir -p /buildstream/install",
+ "echo 'Hi' > /buildstream/install/test"
+ ],
+ })
+
+ res = cli.run(project=project, args=['build', element_name])
+ assert res.exit_code == 0
+
+ res = cli.run(project=project, args=['checkout', element_name, checkout])
+ assert res.exit_code == 0
+
+ with open(os.path.join(checkout, 'test')) as f:
+ text = f.read()
+
+ assert text == "Hi\n"
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_script_root(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkout = os.path.join(cli.directory, 'checkout')
+ element_path = os.path.join(project, 'elements')
+ element_name = 'script/script-layout.bst'
+
+ create_script_element(element_name, element_path,
+ config={
+ # Root-read only is False by default, we
+ # want to check the default here
+ # 'root-read-only': False,
+ 'commands': [
+ "mkdir -p /buildstream/install",
+ "echo 'I can write to root' > /test",
+ "cp /test /buildstream/install"
+ ],
+ })
+
+ res = cli.run(project=project, args=['build', element_name])
+ assert res.exit_code == 0
+
+ res = cli.run(project=project, args=['checkout', element_name, checkout])
+ assert res.exit_code == 0
+
+ with open(os.path.join(checkout, 'test')) as f:
+ text = f.read()
+
+ assert text == "I can write to root\n"
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_script_no_root(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ element_path = os.path.join(project, 'elements')
+ element_name = 'script/script-layout.bst'
+
+ create_script_element(element_name, element_path,
+ config={
+ 'root-read-only': True,
+ 'commands': [
+ "mkdir -p /buildstream/install",
+ "echo 'I can not write to root' > /test",
+ "cp /test /buildstream/install"
+ ],
+ })
+
+ res = cli.run(project=project, args=['build', element_name])
+ assert res.exit_code != 0
+
+ assert "sh: /test: Read-only file system" in res.stderr
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_script_cwd(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkout = os.path.join(cli.directory, 'checkout')
+ element_path = os.path.join(project, 'elements')
+ element_name = 'script/script-layout.bst'
+
+ create_script_element(element_name, element_path,
+ config={
+ 'commands': [
+ "echo 'test' > test",
+ "cp /buildstream/test %{install-root}"
+ ],
+ },
+ variables={
+ 'cwd': '/buildstream'
+ })
+
+ res = cli.run(project=project, args=['build', element_name])
+ assert res.exit_code == 0
+
+ res = cli.run(project=project, args=['checkout', element_name, checkout])
+ assert res.exit_code == 0
+
+ with open(os.path.join(checkout, 'test')) as f:
+ text = f.read()
+
+ assert text == "test\n"
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_script_layout(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+ checkout = os.path.join(cli.directory, 'checkout')
+ element_path = os.path.join(project, 'elements')
+ element_name = 'script/script-layout.bst'
+
+ res = cli.run(project=project, args=['build', element_name])
+ assert res.exit_code == 0
+
+ cli.run(project=project, args=['checkout', element_name, checkout])
+ assert res.exit_code == 0
+
+ with open(os.path.join(checkout, 'test')) as f:
+ text = f.read()
+
+ assert text == "Hi\n"