diff options
Diffstat (limited to 'tests/sources/git.py')
-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 82778e6df..db433f813 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -26,6 +26,7 @@ import shutil 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 @@ -413,6 +414,73 @@ def test_submodule_track_no_ref_or_track(cli, tmpdir, datafiles): @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) + + +@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available") +@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template')) def test_overwrite_rogue_tag_multiple_remotes(cli, tmpdir, datafiles): """When using multiple remotes in cache (i.e. when using aliases), we need to make sure we override tags. This is not allowed to fetch |