summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Pollard <tom.pollard@codethink.co.uk>2018-08-29 12:44:42 +0100
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2019-08-04 01:23:57 +0000
commita155ba93df2073f233a2f2569e6cbd6b2df91aab (patch)
tree12b60ff999505bd65966192477ee0462f6112d4e
parent6f66f0e26e81f107802d17b020a33638ec19872d (diff)
downloadbuildstream-a155ba93df2073f233a2f2569e6cbd6b2df91aab.tar.gz
tests/sources/git.py: Add tests for REF_NOT_IN_TRACK
Add tests that cover assert_ref_in_track & the configurable CoreWarnings REF_NOT_IN_TRACK warnings token.
-rw-r--r--tests/sources/git.py68
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