diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-12-06 16:48:01 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-12-06 23:18:31 +0900 |
commit | afe1aa9fc2355bc71563ec0112ce4a26d9eebdce (patch) | |
tree | 86312bc58f4fb2a18dd13863438de4ea89ca1e8e /tests/sources/git.py | |
parent | f139ca8f422c5bf8f0b42328e137b049532c7b72 (diff) | |
download | buildstream-afe1aa9fc2355bc71563ec0112ce4a26d9eebdce.tar.gz |
tests/sources/git.py: Testing the git:invalid-submodule warning
o Test that it is not triggered in show before fetch, because we
don't know the submodules yet so we cannot know if they are
valid or not.
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 which
specified submodules are invalid
o Test all of this under warning or error conditions (parameterized
for fatal-warnings)
Diffstat (limited to 'tests/sources/git.py')
-rw-r--r-- | tests/sources/git.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/sources/git.py b/tests/sources/git.py index 275c5a9d7..dc18a3c20 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -530,6 +530,77 @@ def test_unlisted_submodule(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_invalid_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:invalid-submodule'] + } + _yaml.dump(project_template, os.path.join(project, 'project.conf')) + + # Create the repo from 'repofiles' subdir + repo = create_repo('git', str(tmpdir)) + ref = repo.create(os.path.join(project, 'repofiles')) + + # Create the source without any submodules, and add + # an invalid submodule configuration to it. + # + # We expect this to cause an invalid submodule warning + # after the source has been fetched and we know what + # the real submodules actually are. + # + gitsource = repo.source_config(ref=ref) + gitsource['submodules'] = { + 'subdir': { + 'url': 'https://pony.org/repo.git' + } + } + + # 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:invalid-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:invalid-submodule') + else: + result.assert_success() + assert "git:invalid-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:invalid-submodule') + else: + result.assert_success() + assert "git:invalid-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): |