From 6f0b620f2473c33cc610130ed29382d9e4c63fb2 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Tue, 2 Jan 2018 16:59:45 +0900 Subject: tests/sources/local.py: Testing failures to create staging directories Seems that local.py is an appropriate plugin to use for testing errors which originate from the abstract Source class. This test checks that we raise the appropriate error in the case that we attempt to stage to a directory that is a regular file. --- tests/sources/local.py | 11 +++++++++++ tests/sources/local/file-exists/files/file.txt | 1 + tests/sources/local/file-exists/project.conf | 2 ++ tests/sources/local/file-exists/target.bst | 14 ++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 tests/sources/local/file-exists/files/file.txt create mode 100644 tests/sources/local/file-exists/project.conf create mode 100644 tests/sources/local/file-exists/target.bst diff --git a/tests/sources/local.py b/tests/sources/local.py index 9cb76bc87..4fe941b35 100644 --- a/tests/sources/local.py +++ b/tests/sources/local.py @@ -53,3 +53,14 @@ def test_stage_directory(cli, tmpdir, datafiles): # Check that the checkout contains the expected file and directory and other file assert(os.path.exists(os.path.join(checkoutdir, 'file.txt'))) assert(os.path.exists(os.path.join(checkoutdir, 'subdir', 'anotherfile.txt'))) + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'file-exists')) +def test_stage_file_exists(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + checkoutdir = os.path.join(str(tmpdir), "checkout") + + # Build, checkout + result = cli.run(project=project, args=['build', 'target.bst']) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, 'ensure-stage-dir-fail') diff --git a/tests/sources/local/file-exists/files/file.txt b/tests/sources/local/file-exists/files/file.txt new file mode 100644 index 000000000..5cbed1a2f --- /dev/null +++ b/tests/sources/local/file-exists/files/file.txt @@ -0,0 +1 @@ +I'm a text file diff --git a/tests/sources/local/file-exists/project.conf b/tests/sources/local/file-exists/project.conf new file mode 100644 index 000000000..afa0f5475 --- /dev/null +++ b/tests/sources/local/file-exists/project.conf @@ -0,0 +1,2 @@ +# Basic project +name: foo diff --git a/tests/sources/local/file-exists/target.bst b/tests/sources/local/file-exists/target.bst new file mode 100644 index 000000000..9e36fa41b --- /dev/null +++ b/tests/sources/local/file-exists/target.bst @@ -0,0 +1,14 @@ +kind: import +description: | + + This is the regular file staged twice, second time we stage into a subdir + of the staging area. The subdir we specify is the file we already staged, + provoking a plausible error where the user tries to stage something + unreasonable. + +sources: +- kind: local + path: files/file.txt +- kind: local + path: files/file.txt + directory: file.txt -- cgit v1.2.1