summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2017-10-16 22:13:34 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2017-10-17 01:26:31 -0700
commit100fb1e6eec6c0e21ed2f3ed2e8ce6189a63f68c (patch)
treec692829deea4e83e76d446746eea50a31b7b7e08 /lib
parentd14816cbafdae7e78beee2910ec0827db16122ef (diff)
downloadspack-100fb1e6eec6c0e21ed2f3ed2e8ce6189a63f68c.tar.gz
spack-100fb1e6eec6c0e21ed2f3ed2e8ce6189a63f68c.tar.bz2
spack-100fb1e6eec6c0e21ed2f3ed2e8ce6189a63f68c.tar.xz
spack-100fb1e6eec6c0e21ed2f3ed2e8ce6189a63f68c.zip
Exercise more code paths in the git fetcher.
- This fakes out GitFetchStrategy to try code paths for different git versions. - This allows us to test code paths for old versions using a newer git version.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/git_fetch.py42
1 files changed, 35 insertions, 7 deletions
diff --git a/lib/spack/spack/test/git_fetch.py b/lib/spack/spack/test/git_fetch.py
index 90b0ae5588..1e17dbd6b2 100644
--- a/lib/spack/spack/test/git_fetch.py
+++ b/lib/spack/spack/test/git_fetch.py
@@ -29,6 +29,7 @@ import spack
from llnl.util.filesystem import *
from spack.spec import Spec
from spack.version import ver
+from spack.fetch_strategy import GitFetchStrategy
from spack.util.executable import which
@@ -36,15 +37,42 @@ pytestmark = pytest.mark.skipif(
not which('git'), reason='requires git to be installed')
+@pytest.fixture(params=[None, '1.8.5.2', '1.8.5.1', '1.7.10', '1.7.0'])
+def git_version(request):
+ """Tests GitFetchStrategy behavior for different git versions.
+
+ GitFetchStrategy tries to optimize using features of newer git
+ versions, but needs to work with older git versions. To ensure code
+ paths for old versions still work, we fake it out here and make it
+ use the backward-compatibility code paths with newer git versions.
+ """
+ git = which('git', required=True)
+ real_git_version = ver(git('--version', output=str).lstrip('git version '))
+
+ if request.param is None:
+ yield # don't patch; run with the real git_version method.
+ else:
+ test_git_version = ver(request.param)
+ if test_git_version > real_git_version:
+ pytest.skip("Can't test clone logic for newer version of git.")
+
+ # patch the fetch strategy to think it's using a lower git version.
+ # we use this to test what we'd need to do with older git versions
+ # using a newer git installation.
+ git_version_method = GitFetchStrategy.git_version
+ GitFetchStrategy.git_version = test_git_version
+ yield
+ GitFetchStrategy.git_version = git_version_method
+
+
@pytest.mark.parametrize("type_of_test", ['master', 'branch', 'tag', 'commit'])
@pytest.mark.parametrize("secure", [True, False])
-def test_fetch(
- type_of_test,
- secure,
- mock_git_repository,
- config,
- refresh_builtin_mock
-):
+def test_fetch(type_of_test,
+ secure,
+ mock_git_repository,
+ config,
+ refresh_builtin_mock,
+ git_version):
"""Tries to:
1. Fetch the repo using a fetch strategy constructed with