Commit a11fc9b2 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

git_cache: Add tests for reset fetch config.

Bug: 862547
Change-Id: I56b096cbf3358c06aa5c285594330af118ab17fd
Reviewed-on: https://chromium-review.googlesource.com/1138714
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
parent 7fa0f19f
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import os import os
import shutil import shutil
import subprocess
import sys import sys
import tempfile import tempfile
import unittest import unittest
...@@ -18,14 +19,16 @@ from testing_support import coverage_utils ...@@ -18,14 +19,16 @@ from testing_support import coverage_utils
import git_cache import git_cache
class GitCacheTest(unittest.TestCase): class GitCacheTest(unittest.TestCase):
@classmethod def setUp(self):
def setUpClass(cls): self.cache_dir = tempfile.mkdtemp(prefix='git_cache_test_')
cls.cache_dir = tempfile.mkdtemp(prefix='git_cache_test_') self.addCleanup(shutil.rmtree, self.cache_dir, ignore_errors=True)
git_cache.Mirror.SetCachePath(cls.cache_dir) self.origin_dir = tempfile.mkdtemp(suffix='origin.git')
self.addCleanup(shutil.rmtree, self.origin_dir, ignore_errors=True)
git_cache.Mirror.SetCachePath(self.cache_dir)
@classmethod def git(self, cmd, cwd=None):
def tearDownClass(cls): cwd = cwd or self.origin_dir
shutil.rmtree(cls.cache_dir, ignore_errors=True) subprocess.check_call(['git'] + cmd, cwd=cwd)
def testParseFetchSpec(self): def testParseFetchSpec(self):
testData = [ testData = [
...@@ -51,6 +54,46 @@ class GitCacheTest(unittest.TestCase): ...@@ -51,6 +54,46 @@ class GitCacheTest(unittest.TestCase):
mirror = git_cache.Mirror('test://phony.example.biz', refs=fetch_specs) mirror = git_cache.Mirror('test://phony.example.biz', refs=fetch_specs)
self.assertItemsEqual(mirror.fetch_specs, expected) self.assertItemsEqual(mirror.fetch_specs, expected)
def testPopulate(self):
self.git(['init', '-q'])
with open(os.path.join(self.origin_dir, 'foo'), 'w') as f:
f.write('touched\n')
self.git(['add', 'foo'])
self.git(['commit', '-m', 'foo'])
mirror = git_cache.Mirror(self.origin_dir)
mirror.populate()
def testPopulateResetFetchConfig(self):
self.git(['init', '-q'])
with open(os.path.join(self.origin_dir, 'foo'), 'w') as f:
f.write('touched\n')
self.git(['add', 'foo'])
self.git(['commit', '-m', 'foo'])
mirror = git_cache.Mirror(self.origin_dir)
mirror.populate()
# Add a bad refspec to the cache's fetch config.
cache_dir = os.path.join(
self.cache_dir, mirror.UrlToCacheDir(self.origin_dir))
self.git(['config', '--add', 'remote.origin.fetch',
'+refs/heads/foo:refs/heads/foo'],
cwd=cache_dir)
mirror.populate(reset_fetch_config=True)
def testPopulateResetFetchConfigEmptyFetchConfig(self):
self.git(['init', '-q'])
with open(os.path.join(self.origin_dir, 'foo'), 'w') as f:
f.write('touched\n')
self.git(['add', 'foo'])
self.git(['commit', '-m', 'foo'])
mirror = git_cache.Mirror(self.origin_dir)
mirror.populate(reset_fetch_config=True)
class GitCacheDirTest(unittest.TestCase): class GitCacheDirTest(unittest.TestCase):
def setUp(self): def setUp(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment