diff options
author | Tom Pollard <tom.pollard@codethink.co.uk> | 2018-08-29 12:44:42 +0100 |
---|---|---|
committer | Tom Pollard <tom.pollard@codethink.co.uk> | 2018-09-03 09:44:36 +0000 |
commit | c96fec5d3205f63c29a072eff9ec7418090375c1 (patch) | |
tree | 891a95c7afc4a36220d80017ce5f8e5f08173df8 | |
parent | 2339f0c4fe76fb94c7453cd0a78be47e634681aa (diff) | |
download | buildstream-tpollard/483.tar.gz |
tests/sources/git.py: Add tests for REF_NOT_IN_TRACKtpollard/483
Add tests that cover assert_ref_in_track & the configurable
CoreWarnings REF_NOT_IN_TRACK warnings token.
-rw-r--r-- | tests/sources/git.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/sources/git.py b/tests/sources/git.py index 781d6d4d1..8f6074fae 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -25,6 +25,7 @@ import pytest from buildstream._exceptions import ErrorDomain from buildstream import _yaml +from buildstream.plugin import CoreWarnings from tests.testutils import cli, create_repo from tests.testutils.site import HAVE_GIT @@ -408,3 +409,70 @@ def test_submodule_track_no_ref_or_track(cli, tmpdir, datafiles): result = cli.run(project=project, args=['show', 'target.bst']) result.assert_main_error(ErrorDomain.SOURCE, "missing-track-and-ref") result.assert_task_error(None, None) + + +@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) +def test_ref_not_in_track_warn(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + + # Create the repo from 'repofiles', create a branch without latest commit + repo = create_repo('git', str(tmpdir)) + ref = repo.create(os.path.join(project, 'repofiles')) + + gitsource = repo.source_config(ref=ref) + + # Overwrite the track value to the added branch + gitsource['track'] = 'foo' + + # Write out our test target + element = { + 'kind': 'import', + 'sources': [ + gitsource + ] + } + _yaml.dump(element, os.path.join(project, 'target.bst')) + + # Assert the warning is raised as ref is not in branch foo. + # Assert warning not error to the user, when not set as fatal. + result = cli.run(project=project, args=['build', 'target.bst']) + assert "The ref provided for the element does not exist locally" in result.stderr + + +@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) +def test_ref_not_in_track_warn_error(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + + # Add fatal-warnings ref-not-in-track to project.conf + project_template = { + "name": "foo", + "fatal-warnings": [CoreWarnings.REF_NOT_IN_TRACK] + } + + _yaml.dump(project_template, os.path.join(project, 'project.conf')) + + # Create the repo from 'repofiles', create a branch without latest commit + repo = create_repo('git', str(tmpdir)) + ref = repo.create(os.path.join(project, 'repofiles')) + + gitsource = repo.source_config(ref=ref) + + # Overwrite the track value to the added branch + gitsource['track'] = 'foo' + + # Write out our test target + element = { + 'kind': 'import', + 'sources': [ + gitsource + ] + } + _yaml.dump(element, os.path.join(project, 'target.bst')) + + # Assert that build raises a warning here that is captured + # as plugin error, due to the fatal warning being set + result = cli.run(project=project, args=['build', 'target.bst']) + result.assert_main_error(ErrorDomain.STREAM, None) + result.assert_task_error(ErrorDomain.PLUGIN, CoreWarnings.REF_NOT_IN_TRACK) |