From c283d5f8b867a7bc0b589b72f18cf06ad8659b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Sun, 23 Sep 2018 16:55:08 +0200 Subject: tests/sources/git.py: Add track and fetch test with and without tag --- tests/sources/git.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/sources/git.py b/tests/sources/git.py index 8f6074fae..86e92d7ce 100644 --- a/tests/sources/git.py +++ b/tests/sources/git.py @@ -476,3 +476,48 @@ def test_ref_not_in_track_warn_error(cli, tmpdir, datafiles): 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')) +@pytest.mark.parametrize("tag,extra_commit", [(False, False), (True, False), (True, True)]) +def test_track_fetch(cli, tmpdir, datafiles, tag, extra_commit): + project = os.path.join(datafiles.dirname, datafiles.basename) + + # Create the repo from 'repofiles' subdir + repo = create_repo('git', str(tmpdir)) + ref = repo.create(os.path.join(project, 'repofiles')) + if tag: + repo.add_tag('tag') + if extra_commit: + repo.add_commit() + + # Write out our test target + element = { + 'kind': 'import', + 'sources': [ + repo.source_config() + ] + } + element_path = os.path.join(project, 'target.bst') + _yaml.dump(element, element_path) + + # Track it + result = cli.run(project=project, args=['track', 'target.bst']) + result.assert_success() + + element = _yaml.load(element_path) + new_ref = element['sources'][0]['ref'] + + if tag: + # Check and strip prefix + prefix = 'tag-{}-g'.format(0 if not extra_commit else 1) + assert new_ref.startswith(prefix) + new_ref = new_ref[len(prefix):] + + # 40 chars for SHA-1 + assert len(new_ref) == 40 + + # Fetch it + result = cli.run(project=project, args=['fetch', 'target.bst']) + result.assert_success() -- cgit v1.2.1