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> | 2019-08-03 22:18:16 -0400 |
commit | 2475b45d617b431266d32a15fc2d7c96795581ed (patch) | |
tree | 8a0c448764b92a722ae7361fc977ef3b9e71a58b | |
parent | d177cada9f3e437b26e99bf134a9b91206b4bda8 (diff) | |
download | buildstream-2475b45d617b431266d32a15fc2d7c96795581ed.tar.gz |
tests/sources/git.py: Test invalid submodules warning appearing after track
-rw-r--r-- | tests/sources/git.py | 116 |
1 files changed, 57 insertions, 59 deletions
diff --git a/tests/sources/git.py b/tests/sources/git.py index 59f210c0b..e7daa95a7 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -555,33 +555,34 @@ 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_track_unlisted_submodule(cli, tmpdir, datafiles, fail): +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:unlisted-submodule'] + "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, but use - # the original ref, let the submodules appear after tracking - repo.add_submodule('subdir', 'file://' + subrepo.repo) - - # Create the source, and delete the explicit configuration - # of the submodules. + # 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) - del gitsource['submodules'] + gitsource['submodules'] = { + 'subdir': { + 'url': 'https://pony.org/repo.git' + } + } # Write out our test target element = { @@ -592,33 +593,40 @@ def test_track_unlisted_submodule(cli, tmpdir, datafiles, fail): } _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:unlisted-submodule" not in result.stderr - - # We won't get a warning/error when tracking either, the source - # has not become Consistency.CACHED so the opportunity to check - # for the warning has not yet arisen. - result = cli.run(project=project, args=['track', '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 + assert "git:invalid-submodule" not in result.stderr - # Fetching the repo at the new ref will finally reveal the warning + # 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') + result.assert_task_error(ErrorDomain.PLUGIN, 'git:invalid-submodule') else: result.assert_success() - assert "git:unlisted-submodule" in result.stderr + 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("fail", ['warn', 'error']) -def test_invalid_submodule(cli, tmpdir, datafiles, fail): +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 @@ -629,23 +637,23 @@ def test_invalid_submodule(cli, tmpdir, datafiles, fail): } _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')) - # 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. - # + # 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) - gitsource['submodules'] = { - 'subdir': { - 'url': 'https://pony.org/repo.git' - } - } # Write out our test target element = { @@ -656,18 +664,18 @@ def test_invalid_submodule(cli, tmpdir, datafiles, fail): } _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']) + # 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 - # 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 + # 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') @@ -675,16 +683,6 @@ def test_invalid_submodule(cli, tmpdir, datafiles, fail): 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')) |