summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-12-05 15:01:46 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-12-06 23:18:31 +0900
commitf139ca8f422c5bf8f0b42328e137b049532c7b72 (patch)
treeccdbca5bc5a06c7a8313ec8d4296a87528c1ee25
parent50cb2706ff6b47235097dcdc87e16547f1753956 (diff)
downloadbuildstream-f139ca8f422c5bf8f0b42328e137b049532c7b72.tar.gz
tests/sources/git.py: Testing the git:unlisted-submodule warning
o Test that it is not triggered in show before fetch, because we don't know about the unlisted submodules yet o Test that it is triggered by a fetch command o Test that it is triggered by `show` after having completed a fetch command, since now we have the repository and know about the unlisted submodule o Test all of this under warning or error conditions (parameterized for fatal-warnings)
-rw-r--r--tests/sources/git.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/sources/git.py b/tests/sources/git.py
index 124f036cf..275c5a9d7 100644
--- a/tests/sources/git.py
+++ b/tests/sources/git.py
@@ -457,6 +457,79 @@ def test_ref_not_in_track(cli, tmpdir, datafiles, fail):
@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
+@pytest.mark.parametrize("fail", ['warn', 'error'])
+def test_unlisted_submodule(cli, tmpdir, datafiles, fail):
+ project = os.path.join(datafiles.dirname, datafiles.basename)
+
+ # Make the warning an error if we're testing errors
+ if fail == 'error':
+ project_template = {
+ "name": "foo",
+ "fatal-warnings": ['git:unlisted-submodule']
+ }
+ _yaml.dump(project_template, os.path.join(project, 'project.conf'))
+
+ # Create the submodule first from the 'subrepofiles' subdir
+ subrepo = create_repo('git', str(tmpdir), 'subrepo')
+ subrepo.create(os.path.join(project, 'subrepofiles'))
+
+ # Create the repo from 'repofiles' subdir
+ repo = create_repo('git', str(tmpdir))
+ ref = repo.create(os.path.join(project, 'repofiles'))
+
+ # Add a submodule pointing to the one we created
+ ref = repo.add_submodule('subdir', 'file://' + subrepo.repo)
+
+ # Create the source, and delete the explicit configuration
+ # of the submodules.
+ #
+ # We expect this to cause an unlisted submodule warning
+ # after the source has been fetched.
+ #
+ gitsource = repo.source_config(ref=ref)
+ del gitsource['submodules']
+
+ # Write out our test target
+ element = {
+ 'kind': 'import',
+ 'sources': [
+ gitsource
+ ]
+ }
+ _yaml.dump(element, os.path.join(project, 'target.bst'))
+
+ # We will not see the warning or error before the first fetch, because
+ # we don't have the repository yet and so we have no knowledge of
+ # the unlisted submodule.
+ result = cli.run(project=project, args=['show', 'target.bst'])
+ result.assert_success()
+ assert "git:unlisted-submodule" not in result.stderr
+
+ # We will notice this directly in fetch, as it will try to fetch
+ # the submodules it discovers as a result of fetching the primary repo.
+ result = cli.run(project=project, args=['fetch', 'target.bst'])
+
+ # Assert a warning or an error depending on what we're checking
+ if fail == 'error':
+ result.assert_main_error(ErrorDomain.STREAM, None)
+ result.assert_task_error(ErrorDomain.PLUGIN, 'git:unlisted-submodule')
+ else:
+ result.assert_success()
+ assert "git:unlisted-submodule" in result.stderr
+
+ # Now that we've fetched it, `bst show` will discover the unlisted submodule too
+ result = cli.run(project=project, args=['show', 'target.bst'])
+
+ # Assert a warning or an error depending on what we're checking
+ if fail == 'error':
+ result.assert_main_error(ErrorDomain.PLUGIN, 'git:unlisted-submodule')
+ else:
+ result.assert_success()
+ assert "git:unlisted-submodule" in result.stderr
+
+
+@pytest.mark.skipif(HAVE_GIT is False, reason="git is not available")
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'template'))
@pytest.mark.parametrize("ref_format", ['sha1', 'git-describe'])
@pytest.mark.parametrize("tag,extra_commit", [(False, False), (True, False), (True, True)])
def test_track_fetch(cli, tmpdir, datafiles, ref_format, tag, extra_commit):