summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2018-08-17 15:22:00 +0100
committerTiago Gomes <tiago.gomes@codethink.co.uk>2018-09-07 14:52:59 +0100
commitd415bde5aa314df04baa58ca186b4a7be2d7aea3 (patch)
tree172aee60e8d5e517abe16ee6a2e224c5c414f651
parentff033825010be705843e08c2b1f0dd909b1fcb77 (diff)
downloadbuildstream-tiagogomes/issue-287.tar.gz
Add tests for validating configuration variablestiagogomes/issue-287
-rw-r--r--tests/loader/variables.py81
-rw-r--r--tests/loader/variables/simple/foo.txt1
-rw-r--r--tests/loader/variables/simple/project.conf1
3 files changed, 83 insertions, 0 deletions
diff --git a/tests/loader/variables.py b/tests/loader/variables.py
new file mode 100644
index 000000000..852b1279c
--- /dev/null
+++ b/tests/loader/variables.py
@@ -0,0 +1,81 @@
+import os
+import pytest
+
+from buildstream import _yaml
+from buildstream._exceptions import ErrorDomain, LoadErrorReason
+from tests.testutils import cli
+
+DATA_DIR = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)),
+ 'variables',
+)
+
+PROTECTED_VARIABLES = [('project-name'), ('element-name'), ('max-jobs')]
+
+
+@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES)
+@pytest.mark.datafiles(DATA_DIR)
+def test_use_of_protected_var_in_element(cli, tmpdir, datafiles, protected_var):
+ project = os.path.join(str(datafiles), 'simple')
+
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ {
+ 'kind': 'local',
+ 'path': 'foo.txt'
+ }
+ ],
+ 'variables': {
+ protected_var: 'some-value'
+ }
+ }
+ _yaml.dump(element, os.path.join(project, 'target.bst'))
+
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_main_error(ErrorDomain.LOAD,
+ LoadErrorReason.PROTECTED_VARIABLE_REDEFINED)
+
+
+@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES)
+@pytest.mark.datafiles(DATA_DIR)
+def test_use_of_protected_var_project_conf(cli, tmpdir, datafiles, protected_var):
+ project = os.path.join(str(datafiles), 'simple')
+
+ conf = {
+ 'name': 'test',
+ 'variables': {
+ protected_var: 'some-value'
+ }
+ }
+ _yaml.dump(conf, os.path.join(project, 'project.conf'))
+
+ result = cli.run(project=project, args=['show'])
+ result.assert_main_error(ErrorDomain.LOAD,
+ LoadErrorReason.PROTECTED_VARIABLE_REDEFINED)
+
+
+@pytest.mark.parametrize('plugin_type', [
+ ('sources'),
+ ('elements')
+])
+@pytest.mark.parametrize('protected_var', PROTECTED_VARIABLES)
+@pytest.mark.datafiles(DATA_DIR)
+def test_use_of_protected_var_element_overrides(cli, tmpdir, datafiles, plugin_type, protected_var):
+ project = os.path.join(str(datafiles), 'simple')
+
+ conf = {
+ 'name': 'test',
+ plugin_type: {
+ 'some-plugin-name': {
+ 'variables': {
+ protected_var: 'some-value'
+ }
+ }
+ }
+ }
+ _yaml.dump(conf, os.path.join(project, 'project.conf'))
+
+ result = cli.run(project=project, args=['show'])
+ result.assert_main_error(ErrorDomain.LOAD,
+ LoadErrorReason.PROTECTED_VARIABLE_REDEFINED)
diff --git a/tests/loader/variables/simple/foo.txt b/tests/loader/variables/simple/foo.txt
new file mode 100644
index 000000000..257cc5642
--- /dev/null
+++ b/tests/loader/variables/simple/foo.txt
@@ -0,0 +1 @@
+foo
diff --git a/tests/loader/variables/simple/project.conf b/tests/loader/variables/simple/project.conf
new file mode 100644
index 000000000..5a240e3ed
--- /dev/null
+++ b/tests/loader/variables/simple/project.conf
@@ -0,0 +1 @@
+name: foo