summaryrefslogtreecommitdiff
path: root/tests/format
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2019-04-15 09:39:21 +0100
committerChandan Singh <csingh43@bloomberg.net>2019-04-18 15:45:19 +0100
commitdc4e10c39118b09a65eccaf5eacf7ca963a1f3e7 (patch)
tree004c1516aba8f433ac990ebf2754980d862dc957 /tests/format
parentefe5547f1fecc8076d3d769ae5468a1935dac10b (diff)
downloadbuildstream-dc4e10c39118b09a65eccaf5eacf7ca963a1f3e7.tar.gz
Add tests for specifying targets of junction elements
Diffstat (limited to 'tests/format')
-rw-r--r--tests/format/junctions.py54
-rw-r--r--tests/format/junctions/config-target/elements/invalid-source-target.bst8
-rw-r--r--tests/format/junctions/config-target/elements/nested-junction-target.bst4
-rw-r--r--tests/format/junctions/config-target/elements/no-junction.bst4
-rw-r--r--tests/format/junctions/config-target/elements/subproject.bst5
-rw-r--r--tests/format/junctions/config-target/elements/subsubproject.bst4
-rw-r--r--tests/format/junctions/config-target/elements/target.bst4
-rw-r--r--tests/format/junctions/config-target/project.conf3
-rw-r--r--tests/format/junctions/config-target/subproject/elements/subsubproject-junction.bst5
-rw-r--r--tests/format/junctions/config-target/subproject/project.conf3
-rw-r--r--tests/format/junctions/config-target/subproject/subsubproject/elements/hello.bst5
-rw-r--r--tests/format/junctions/config-target/subproject/subsubproject/files/hello.txt1
-rw-r--r--tests/format/junctions/config-target/subproject/subsubproject/project.conf3
13 files changed, 103 insertions, 0 deletions
diff --git a/tests/format/junctions.py b/tests/format/junctions.py
index 30891433b..bc85f182d 100644
--- a/tests/format/junctions.py
+++ b/tests/format/junctions.py
@@ -446,3 +446,57 @@ def test_build_git_cross_junction_names(cli, tmpdir, datafiles):
# Check that the checkout contains the expected files from both projects
assert os.path.exists(os.path.join(checkoutdir, 'base.txt'))
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_config_target(cli, tmpdir, datafiles):
+ project = os.path.join(str(datafiles), 'config-target')
+ checkoutdir = os.path.join(str(tmpdir), 'checkout')
+
+ # Build, checkout
+ result = cli.run(project=project, args=['build', 'target.bst'])
+ result.assert_success()
+ result = cli.run(project=project, args=['artifact', 'checkout', 'target.bst', '--directory', checkoutdir])
+ result.assert_success()
+
+ # Check that the checkout contains the expected files from sub-sub-project
+ assert os.path.exists(os.path.join(checkoutdir, 'hello.txt'))
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_invalid_sources_and_target(cli, tmpdir, datafiles):
+ project = os.path.join(str(datafiles), 'config-target')
+
+ result = cli.run(project=project, args=['show', 'invalid-source-target.bst'])
+ result.assert_main_error(ErrorDomain.ELEMENT, None)
+
+ assert "junction elements cannot define both 'sources' and 'target' config option" in result.stderr
+
+
+@pytest.mark.datafiles(DATA_DIR)
+def test_invalid_target_name(cli, tmpdir, datafiles):
+ project = os.path.join(str(datafiles), 'config-target')
+
+ # Rename our junction element to the same name as its target
+ old_path = os.path.join(project, 'elements/subsubproject.bst')
+ new_path = os.path.join(project, 'elements/subsubproject-junction.bst')
+ os.rename(old_path, new_path)
+
+ # This should fail now
+ result = cli.run(project=project, args=['show', 'subsubproject-junction.bst'])
+ result.assert_main_error(ErrorDomain.ELEMENT, None)
+
+ assert "junction elements cannot target an element with the same name" in result.stderr
+
+
+# We cannot exhaustively test all possible ways in which this can go wrong, so
+# test a couple of common ways in which we expect this to go wrong.
+@pytest.mark.parametrize('target', ['no-junction.bst', 'nested-junction-target.bst'])
+@pytest.mark.datafiles(DATA_DIR)
+def test_invalid_target_format(cli, tmpdir, datafiles, target):
+ project = os.path.join(str(datafiles), 'config-target')
+
+ result = cli.run(project=project, args=['show', target])
+ result.assert_main_error(ErrorDomain.ELEMENT, None)
+
+ assert "'target' option must be in format '{junction-name}:{element-name}'" in result.stderr
diff --git a/tests/format/junctions/config-target/elements/invalid-source-target.bst b/tests/format/junctions/config-target/elements/invalid-source-target.bst
new file mode 100644
index 000000000..b97d09034
--- /dev/null
+++ b/tests/format/junctions/config-target/elements/invalid-source-target.bst
@@ -0,0 +1,8 @@
+kind: junction
+
+sources:
+- kind: local
+ path: subproject/subsubproject
+
+config:
+ target: subproject.bst:subsubproject-junction.bst
diff --git a/tests/format/junctions/config-target/elements/nested-junction-target.bst b/tests/format/junctions/config-target/elements/nested-junction-target.bst
new file mode 100644
index 000000000..f76a264e5
--- /dev/null
+++ b/tests/format/junctions/config-target/elements/nested-junction-target.bst
@@ -0,0 +1,4 @@
+kind: junction
+
+config:
+ target: subproject.bst:subsubproject.bst:hello.bst
diff --git a/tests/format/junctions/config-target/elements/no-junction.bst b/tests/format/junctions/config-target/elements/no-junction.bst
new file mode 100644
index 000000000..15d1842f6
--- /dev/null
+++ b/tests/format/junctions/config-target/elements/no-junction.bst
@@ -0,0 +1,4 @@
+kind: junction
+
+config:
+ target: subproject.bst
diff --git a/tests/format/junctions/config-target/elements/subproject.bst b/tests/format/junctions/config-target/elements/subproject.bst
new file mode 100644
index 000000000..6664eeec6
--- /dev/null
+++ b/tests/format/junctions/config-target/elements/subproject.bst
@@ -0,0 +1,5 @@
+kind: junction
+
+sources:
+- kind: local
+ path: subproject
diff --git a/tests/format/junctions/config-target/elements/subsubproject.bst b/tests/format/junctions/config-target/elements/subsubproject.bst
new file mode 100644
index 000000000..20dc4a0c4
--- /dev/null
+++ b/tests/format/junctions/config-target/elements/subsubproject.bst
@@ -0,0 +1,4 @@
+kind: junction
+
+config:
+ target: subproject.bst:subsubproject-junction.bst
diff --git a/tests/format/junctions/config-target/elements/target.bst b/tests/format/junctions/config-target/elements/target.bst
new file mode 100644
index 000000000..50d74489a
--- /dev/null
+++ b/tests/format/junctions/config-target/elements/target.bst
@@ -0,0 +1,4 @@
+kind: stack
+
+depends:
+- subsubproject.bst:hello.bst
diff --git a/tests/format/junctions/config-target/project.conf b/tests/format/junctions/config-target/project.conf
new file mode 100644
index 000000000..4049c3739
--- /dev/null
+++ b/tests/format/junctions/config-target/project.conf
@@ -0,0 +1,3 @@
+name: config-target
+
+element-path: elements
diff --git a/tests/format/junctions/config-target/subproject/elements/subsubproject-junction.bst b/tests/format/junctions/config-target/subproject/elements/subsubproject-junction.bst
new file mode 100644
index 000000000..018fb8ec4
--- /dev/null
+++ b/tests/format/junctions/config-target/subproject/elements/subsubproject-junction.bst
@@ -0,0 +1,5 @@
+kind: junction
+
+sources:
+- kind: local
+ path: subsubproject
diff --git a/tests/format/junctions/config-target/subproject/project.conf b/tests/format/junctions/config-target/subproject/project.conf
new file mode 100644
index 000000000..1097282c3
--- /dev/null
+++ b/tests/format/junctions/config-target/subproject/project.conf
@@ -0,0 +1,3 @@
+name: subproject
+
+element-path: elements
diff --git a/tests/format/junctions/config-target/subproject/subsubproject/elements/hello.bst b/tests/format/junctions/config-target/subproject/subsubproject/elements/hello.bst
new file mode 100644
index 000000000..a04a856cd
--- /dev/null
+++ b/tests/format/junctions/config-target/subproject/subsubproject/elements/hello.bst
@@ -0,0 +1,5 @@
+kind: import
+
+sources:
+- kind: local
+ path: files/hello.txt
diff --git a/tests/format/junctions/config-target/subproject/subsubproject/files/hello.txt b/tests/format/junctions/config-target/subproject/subsubproject/files/hello.txt
new file mode 100644
index 000000000..ce0136250
--- /dev/null
+++ b/tests/format/junctions/config-target/subproject/subsubproject/files/hello.txt
@@ -0,0 +1 @@
+hello
diff --git a/tests/format/junctions/config-target/subproject/subsubproject/project.conf b/tests/format/junctions/config-target/subproject/subsubproject/project.conf
new file mode 100644
index 000000000..9d75121a0
--- /dev/null
+++ b/tests/format/junctions/config-target/subproject/subsubproject/project.conf
@@ -0,0 +1,3 @@
+name: subsubproject
+
+element-path: elements