diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-12-06 22:55:40 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-12-06 23:18:31 +0900 |
commit | a029762537e6d3744edbe2bf30b3532490bfd065 (patch) | |
tree | cce5e2b0ec4d406140a716b571d9031725d30a25 | |
parent | 573002016397bb657f3dee980f68814aadb07b25 (diff) | |
download | buildstream-a029762537e6d3744edbe2bf30b3532490bfd065.tar.gz |
tests/sources/git.py: Test invalid submodules warning appearing after track
-rw-r--r-- | tests/sources/git.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/sources/git.py b/tests/sources/git.py index 64acbd770..b9251e36a 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -664,6 +664,67 @@ def test_invalid_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_track_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 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) + + # Add a commit beyond the ref which *removes* the submodule we've added + repo.remove_path('subdir') + + # Create the source, this will keep the submodules so initially + # the configuration is valid for the ref we're using + gitsource = repo.source_config(ref=ref) + + # Write out our test target + element = { + 'kind': 'import', + 'sources': [ + gitsource + ] + } + _yaml.dump(element, os.path.join(project, 'target.bst')) + + # Fetch the repo, we will not see the warning because we + # are still pointing to a ref which predates the submodules + result = cli.run(project=project, args=['fetch', 'target.bst']) + result.assert_success() + assert "git:invalid-submodule" not in result.stderr + + # In this case, we will get the error directly after tracking, + # since the new HEAD does not require any submodules which are + # not locally cached, the Source will be CACHED directly after + # tracking and the validations will occur as a result. + # + result = cli.run(project=project, args=['track', 'target.bst']) + 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 + + +@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): |