diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-12-29 19:39:35 -0500 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-01-01 19:44:53 +0900 |
commit | c6df92fcbec1300334cdb1a79fdfa633fb3385fb (patch) | |
tree | 4ecce9db0109df4c0340c65119c71c19ba6e84bf /tests | |
parent | fbdb5118f6322cf2f5e8bdb24bc7c5a8fdd374bc (diff) | |
download | buildstream-c6df92fcbec1300334cdb1a79fdfa633fb3385fb.tar.gz |
tests/sources: Use new error checking tools for source tests
Also added a test case for the `patch` plugin which checks for graceful
failure when the specified patch file is not a regular file (but a block
device or a named pipe instead).
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sources/git.py | 13 | ||||
-rw-r--r-- | tests/sources/local.py | 14 | ||||
-rw-r--r-- | tests/sources/patch.py | 47 | ||||
-rw-r--r-- | tests/sources/patch/basic/irregular.bst | 7 | ||||
-rw-r--r-- | tests/sources/tar.py | 54 | ||||
-rw-r--r-- | tests/sources/zip.py | 38 |
6 files changed, 91 insertions, 82 deletions
diff --git a/tests/sources/git.py b/tests/sources/git.py index f3b148a61..39de0b92b 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -1,7 +1,7 @@ import os import pytest -from buildstream._pipeline import PipelineError +from buildstream._exceptions import ErrorDomain from buildstream import _yaml from tests.testutils import cli, create_repo @@ -35,9 +35,8 @@ def test_fetch_bad_ref(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'fetch', 'target.bst' ]) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, PipelineError) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, None) @pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") @@ -68,11 +67,11 @@ def test_submodule_fetch_checkout(cli, tmpdir, datafiles): # Fetch, build, checkout result = cli.run(project=project, args=['fetch', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Assert we checked out both files at their expected location assert os.path.exists(os.path.join(checkoutdir, 'file.txt')) diff --git a/tests/sources/local.py b/tests/sources/local.py index 02d132986..9cb76bc87 100644 --- a/tests/sources/local.py +++ b/tests/sources/local.py @@ -1,7 +1,7 @@ import os import pytest -from buildstream import SourceError +from buildstream._exceptions import ErrorDomain from tests.testutils import cli DATA_DIR = os.path.join( @@ -21,9 +21,7 @@ def test_missing_file(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'show', 'target.bst' ]) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, SourceError) + result.assert_main_error(ErrorDomain.SOURCE, None) @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) @@ -33,9 +31,9 @@ def test_stage_file(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the checkout contains the expected file assert(os.path.exists(os.path.join(checkoutdir, 'file.txt'))) @@ -48,9 +46,9 @@ def test_stage_directory(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the checkout contains the expected file and directory and other file assert(os.path.exists(os.path.join(checkoutdir, 'file.txt'))) diff --git a/tests/sources/patch.py b/tests/sources/patch.py index 8a1b9bf42..2f23fd5dd 100644 --- a/tests/sources/patch.py +++ b/tests/sources/patch.py @@ -1,8 +1,7 @@ import os import pytest -from buildstream._pipeline import PipelineError -from buildstream import SourceError +from buildstream._exceptions import ErrorDomain from tests.testutils import cli DATA_DIR = os.path.join( @@ -22,9 +21,21 @@ def test_missing_patch(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'show', 'target.bst' ]) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, SourceError) + result.assert_main_error(ErrorDomain.SOURCE, 'patch-no-exist') + + +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) +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) + + result = cli.run(project=project, args=[ + 'show', 'irregular.bst' + ]) + result.assert_main_error(ErrorDomain.SOURCE, "patch-not-a-file") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) @@ -34,9 +45,9 @@ def test_stage_and_patch(cli, tmpdir, datafiles): # Build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Test the file.txt was patched and changed with open(os.path.join(checkoutdir, 'file.txt')) as f: @@ -50,9 +61,8 @@ def test_stage_file_nonexistent_dir(cli, tmpdir, datafiles): # Fails at build time because it tries to patch into a non-existing directory result = cli.run(project=project, args=['build', 'failure-nonexistent-dir.bst']) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, PipelineError) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, "patch-no-files") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic')) @@ -62,9 +72,8 @@ def test_stage_file_empty_dir(cli, tmpdir, datafiles): # Fails at build time because it tries to patch with nothing else staged result = cli.run(project=project, args=['build', 'failure-empty-dir.bst']) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, PipelineError) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, "patch-no-files") @pytest.mark.datafiles(os.path.join(DATA_DIR, 'separate-patch-dir')) @@ -74,9 +83,9 @@ def test_stage_separate_patch_dir(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Test the file.txt was patched and changed with open(os.path.join(checkoutdir, 'test-dir', 'file.txt')) as f: @@ -90,9 +99,9 @@ def test_stage_multiple_patches(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Test the file.txt was patched and changed with open(os.path.join(checkoutdir, 'file.txt')) as f: @@ -106,9 +115,9 @@ def test_patch_strip_level(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Test the file.txt was patched and changed with open(os.path.join(checkoutdir, 'file.txt')) as f: diff --git a/tests/sources/patch/basic/irregular.bst b/tests/sources/patch/basic/irregular.bst new file mode 100644 index 000000000..425cbcc01 --- /dev/null +++ b/tests/sources/patch/basic/irregular.bst @@ -0,0 +1,7 @@ +kind: import +description: This is the pony +sources: +- kind: local + path: file.txt +- kind: patch + path: irregular_file.patch diff --git a/tests/sources/tar.py b/tests/sources/tar.py index ca1bef7da..c0b29ee3f 100644 --- a/tests/sources/tar.py +++ b/tests/sources/tar.py @@ -4,7 +4,7 @@ import tarfile import tempfile import subprocess -from buildstream._pipeline import PipelineError +from buildstream._exceptions import ErrorDomain from buildstream import _yaml from tests.testutils import cli from tests.testutils.site import HAVE_LZIP @@ -65,9 +65,8 @@ def test_fetch_bad_url(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'fetch', 'target.bst' ]) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, PipelineError) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, None) # Test that when I fetch with an invalid ref, it fails. @@ -84,9 +83,8 @@ def test_fetch_bad_ref(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'fetch', 'target.bst' ]) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, PipelineError) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, None) # Test that when tracking with a ref set, there is a warning @@ -103,7 +101,7 @@ def test_track_warning(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'track', 'target.bst' ]) - assert result.exit_code == 0 + result.assert_success() assert "Potential man-in-the-middle attack!" in result.stderr @@ -131,13 +129,13 @@ def test_stage_default_basedir(cli, tmpdir, datafiles, srcdir): # Track, fetch, build, checkout result = cli.run(project=project, args=['track', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['fetch', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the content of the first directory is checked out (base-dir: '*') original_dir = os.path.join(str(datafiles), "content", "a") @@ -160,13 +158,13 @@ def test_stage_no_basedir(cli, tmpdir, datafiles, srcdir): # Track, fetch, build, checkout result = cli.run(project=project, args=['track', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['fetch', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the full content of the tarball is checked out (base-dir: '') original_dir = os.path.join(str(datafiles), "content") @@ -189,13 +187,13 @@ def test_stage_explicit_basedir(cli, tmpdir, datafiles, srcdir): # Track, fetch, build, checkout result = cli.run(project=project, args=['track', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['fetch', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the content of the first directory is checked out (base-dir: '*') original_dir = os.path.join(str(datafiles), "content", "a") @@ -225,13 +223,13 @@ def test_stage_contains_links(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['track', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['fetch', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the content of the first directory is checked out (base-dir: '*') original_dir = os.path.join(str(datafiles), "content", "base-directory") @@ -254,13 +252,13 @@ def test_stage_default_basedir_lzip(cli, tmpdir, datafiles, srcdir): # Track, fetch, build, checkout result = cli.run(project=project, args=['track', 'target-lz.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['fetch', 'target-lz.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['build', 'target-lz.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target-lz.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the content of the first directory is checked out (base-dir: '*') original_dir = os.path.join(str(datafiles), "content", "a") diff --git a/tests/sources/zip.py b/tests/sources/zip.py index 70ad491ff..b028163f9 100644 --- a/tests/sources/zip.py +++ b/tests/sources/zip.py @@ -2,7 +2,7 @@ import os import pytest import zipfile -from buildstream._pipeline import PipelineError +from buildstream._exceptions import ErrorDomain from buildstream import _yaml from tests.testutils import cli @@ -52,9 +52,8 @@ def test_fetch_bad_url(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'fetch', 'target.bst' ]) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, PipelineError) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, None) # Test that when I fetch with an invalid ref, it fails. @@ -71,9 +70,8 @@ def test_fetch_bad_ref(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'fetch', 'target.bst' ]) - assert result.exit_code != 0 - assert result.exception - assert isinstance(result.exception, PipelineError) + result.assert_main_error(ErrorDomain.PIPELINE, None) + result.assert_task_error(ErrorDomain.SOURCE, None) # Test that when tracking with a ref set, there is a warning @@ -90,7 +88,7 @@ def test_track_warning(cli, tmpdir, datafiles): result = cli.run(project=project, args=[ 'track', 'target.bst' ]) - assert result.exit_code == 0 + result.assert_success() assert "Potential man-in-the-middle attack!" in result.stderr @@ -117,13 +115,13 @@ def test_stage_default_basedir(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['track', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['fetch', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the content of the first directory is checked out (base-dir: '*') original_dir = os.path.join(str(datafiles), "content", "a") @@ -145,13 +143,13 @@ def test_stage_no_basedir(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['track', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['fetch', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the full content of the tarball is checked out (base-dir: '') original_dir = os.path.join(str(datafiles), "content") @@ -173,13 +171,13 @@ def test_stage_explicit_basedir(cli, tmpdir, datafiles): # Track, fetch, build, checkout result = cli.run(project=project, args=['track', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['fetch', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['build', 'target.bst']) - assert result.exit_code == 0 + result.assert_success() result = cli.run(project=project, args=['checkout', 'target.bst', checkoutdir]) - assert result.exit_code == 0 + result.assert_success() # Check that the content of the first directory is checked out (base-dir: '*') original_dir = os.path.join(str(datafiles), "content", "a") |