From ec6973c5fd745de4be8ff786b93ea7f3ceda0b8d Mon Sep 17 00:00:00 2001 From: David Hoese Date: Mon, 8 Apr 2019 08:26:44 -0500 Subject: [PATCH] Fix git submodule test sha comparison --- tests/conftest.py | 10 +++++++--- tests/unit/contentproviders/test_git.py | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d313692a..72df137d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -136,23 +136,27 @@ def repo_with_submodule(): # create "parent" repository subprocess.check_call(['git', 'init'], cwd=git_a_dir) _add_content_to_git(git_a_dir) - # create submodule repository + # create repository with 2 commits that will be the submodule subprocess.check_call(['git', 'init'], cwd=git_b_dir) _add_content_to_git(git_b_dir) + submod_sha1_b = _get_sha1(git_b_dir) + _add_content_to_git(git_b_dir) # create a new branch in the parent to add the submodule subprocess.check_call(['git', 'checkout', '-b', 'branch-with-submod'], cwd=git_a_dir) subprocess.check_call(['git', 'submodule', 'add', git_b_dir, 'submod'], cwd=git_a_dir) + # checkout the first commit for the submod, not the latest + subprocess.check_call(['git', 'checkout', submod_sha1_b], + cwd=os.path.join(git_a_dir, 'submod')) subprocess.check_call(['git', 'add', git_a_dir, ".gitmodules"], cwd=git_a_dir) subprocess.check_call(['git', 'commit', '-m', 'Add B repos submod'], cwd=git_a_dir) sha1_a = _get_sha1(git_a_dir) - sha1_b = _get_sha1(git_b_dir) - yield git_a_dir, sha1_a, sha1_b + yield git_a_dir, sha1_a, submod_sha1_b class Repo2DockerTest(pytest.Function): diff --git a/tests/unit/contentproviders/test_git.py b/tests/unit/contentproviders/test_git.py index ace05c1a..79eed8ab 100644 --- a/tests/unit/contentproviders/test_git.py +++ b/tests/unit/contentproviders/test_git.py @@ -21,7 +21,7 @@ def test_clone(repo_with_content): def test_submodule_clone(repo_with_submodule): """Test git clone containing a git submodule.""" - upstream, sha1_upstream, sha1_submod = repo_with_submodule + upstream, expected_sha1_upstream, expected_sha1_submod = repo_with_submodule with TemporaryDirectory() as clone_dir: submod_dir = os.path.join(clone_dir, 'submod') # set by fixture @@ -37,8 +37,8 @@ def test_submodule_clone(repo_with_submodule): sha1 = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=submod_dir) submod_sha1 = sha1.stdout.read().decode().strip() - assert git_content.content_id == sha1_upstream[:7] - assert submod_sha1[:7] == submod_sha1[:7] + assert git_content.content_id == expected_sha1_upstream[:7] + assert submod_sha1[:7] == expected_sha1_submod[:7] def test_bad_ref(repo_with_content):