summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2018-07-31 16:37:44 +0100
committerTiago Gomes <tiago.avv@gmail.com>2018-08-02 11:24:43 +0000
commit7e3944dc7a73d068f6345ea7d31856b1c386c0a9 (patch)
tree22a3beb1a9d46d97fdc2753802db943d8337e6fb
parentb7362a3226bd181306d02c760a4dfd6da3acf7fb (diff)
downloadbuildstream-7e3944dc7a73d068f6345ea7d31856b1c386c0a9.tar.gz
tests: add additional tests to patch plugin
-rw-r--r--tests/sources/patch.py45
-rw-r--r--tests/sources/patch/invalid-relative-path/file_1.patch7
-rw-r--r--tests/sources/patch/invalid-relative-path/irregular.bst5
-rw-r--r--tests/sources/patch/invalid-relative-path/project.conf2
4 files changed, 50 insertions, 9 deletions
diff --git a/tests/sources/patch.py b/tests/sources/patch.py
index 17b650b02..39d43369d 100644
--- a/tests/sources/patch.py
+++ b/tests/sources/patch.py
@@ -2,7 +2,7 @@ import os
import pytest
from buildstream._exceptions import ErrorDomain, LoadErrorReason
-from tests.testutils import cli
+from tests.testutils import cli, filetypegenerator
DATA_DIR = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
@@ -28,16 +28,43 @@ def test_missing_patch(cli, tmpdir, datafiles):
def test_non_regular_file_patch(cli, tmpdir, datafiles):
project = os.path.join(datafiles.dirname, datafiles.basename)
- # Add a fifo, that's not a regular file, should cause explosions
- patch_path = os.path.join(datafiles.dirname, datafiles.basename,
- 'irregular_file.patch')
- os.mkfifo(patch_path)
+ patch_path = os.path.join(project, 'irregular_file.patch')
+ for file_type in filetypegenerator.generate_file_types(patch_path):
+ result = cli.run(project=project, args=[
+ 'show', 'irregular.bst'
+ ])
+ if os.path.isfile(patch_path) and not os.path.islink(patch_path):
+ result.assert_success()
+ else:
+ result.assert_main_error(ErrorDomain.LOAD,
+ LoadErrorReason.PROJ_PATH_INVALID_KIND)
- result = cli.run(project=project, args=[
- 'show', 'irregular.bst'
- ])
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_invalid_absolute_path(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ with open(os.path.join(project, "target.bst"), 'r') as f:
+ old_yaml = f.read()
+ new_yaml = old_yaml.replace("file_1.patch",
+ os.path.join(project, "file_1.patch"))
+ assert old_yaml != new_yaml
+
+ with open(os.path.join(project, "target.bst"), 'w') as f:
+ f.write(new_yaml)
+
+ result = cli.run(project=project, args=['show', 'target.bst'])
+ result.assert_main_error(ErrorDomain.LOAD,
+ LoadErrorReason.PROJ_PATH_INVALID)
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'invalid-relative-path'))
+def test_invalid_relative_path(cli, tmpdir, datafiles):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ result = cli.run(project=project, args=['show', 'irregular.bst'])
result.assert_main_error(ErrorDomain.LOAD,
- LoadErrorReason.PROJ_PATH_INVALID_KIND)
+ LoadErrorReason.PROJ_PATH_INVALID)
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
diff --git a/tests/sources/patch/invalid-relative-path/file_1.patch b/tests/sources/patch/invalid-relative-path/file_1.patch
new file mode 100644
index 000000000..424a486dd
--- /dev/null
+++ b/tests/sources/patch/invalid-relative-path/file_1.patch
@@ -0,0 +1,7 @@
+diff --git a/file.txt b/file.txt
+index a496efe..341ef26 100644
+--- a/file.txt
++++ b/file.txt
+@@ -1 +1 @@
+-This is a text file
++This is text file with superpowers
diff --git a/tests/sources/patch/invalid-relative-path/irregular.bst b/tests/sources/patch/invalid-relative-path/irregular.bst
new file mode 100644
index 000000000..6b63a4edb
--- /dev/null
+++ b/tests/sources/patch/invalid-relative-path/irregular.bst
@@ -0,0 +1,5 @@
+kind: import
+description: This is the pony
+sources:
+- kind: patch
+ path: ../invalid-relative-path/irregular_file.patch
diff --git a/tests/sources/patch/invalid-relative-path/project.conf b/tests/sources/patch/invalid-relative-path/project.conf
new file mode 100644
index 000000000..afa0f5475
--- /dev/null
+++ b/tests/sources/patch/invalid-relative-path/project.conf
@@ -0,0 +1,2 @@
+# Basic project
+name: foo