Commit 428e7c14 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

roll-dep: Add tests.

Bug: 829134
Change-Id: Ifa4dc5572a17c9f2a3ab4bb04765106b1563ecae
Reviewed-on: https://chromium-review.googlesource.com/1065081Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent 083eb25f
...@@ -909,7 +909,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -909,7 +909,7 @@ class GClientSmokeGIT(GClientSmokeBase):
'gclient_gn_args = [\'false_var\', \'false_str_var\', \'true_var\', ' 'gclient_gn_args = [\'false_var\', \'false_str_var\', \'true_var\', '
'\'true_str_var\', \'str_var\', \'cond_var\']', '\'true_str_var\', \'str_var\', \'cond_var\']',
'allowed_hosts = [', 'allowed_hosts = [',
' "git://127.0.0.1:20000/git/",', ' "' + self.git_base + '",',
']', ']',
'', '',
'deps = {', 'deps = {',
...@@ -921,7 +921,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -921,7 +921,7 @@ class GClientSmokeGIT(GClientSmokeBase):
'', '',
' # src', ' # src',
' "src": {', ' "src": {',
' "url": "git://127.0.0.1:20000/git/repo_6",', ' "url": "' + self.git_base + 'repo_6",',
' },', ' },',
'', '',
' # src -> src/mac_repo', ' # src -> src/mac_repo',
...@@ -1022,7 +1022,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1022,7 +1022,7 @@ class GClientSmokeGIT(GClientSmokeBase):
' "false_var": False,', ' "false_var": False,',
'', '',
' # src', ' # src',
' "git_base": \'git://127.0.0.1:20000/git/\',', ' "git_base": \'' + self.git_base + '\',',
'', '',
' # src', ' # src',
' "hook1_contents": \'git_hooked1\',', ' "hook1_contents": \'git_hooked1\',',
...@@ -1044,9 +1044,9 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1044,9 +1044,9 @@ class GClientSmokeGIT(GClientSmokeBase):
'', '',
'}', '}',
'', '',
'# git://127.0.0.1:20000/git/repo_2@%s, DEPS' % ( '# ' + self.git_base + 'repo_2@%s, DEPS' % (
self.githash('repo_2', 1)[:7]), self.githash('repo_2', 1)[:7]),
'# git://127.0.0.1:20000/git/repo_8, DEPS' '# ' + self.git_base + 'repo_8, DEPS'
], deps_contents.splitlines()) ], deps_contents.splitlines())
def testFlattenPinAllDeps(self): def testFlattenPinAllDeps(self):
...@@ -1070,7 +1070,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1070,7 +1070,7 @@ class GClientSmokeGIT(GClientSmokeBase):
'gclient_gn_args = [\'false_var\', \'false_str_var\', \'true_var\', ' 'gclient_gn_args = [\'false_var\', \'false_str_var\', \'true_var\', '
'\'true_str_var\', \'str_var\', \'cond_var\']', '\'true_str_var\', \'str_var\', \'cond_var\']',
'allowed_hosts = [', 'allowed_hosts = [',
' "git://127.0.0.1:20000/git/",', ' "' + self.git_base + '",',
']', ']',
'', '',
'deps = {', 'deps = {',
...@@ -1082,7 +1082,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1082,7 +1082,7 @@ class GClientSmokeGIT(GClientSmokeBase):
'', '',
' # src', ' # src',
' "src": {', ' "src": {',
' "url": "git://127.0.0.1:20000/git/repo_6@%s",' % ( ' "url": "' + self.git_base + 'repo_6@%s",' % (
self.githash('repo_6', 1)), self.githash('repo_6', 1)),
' },', ' },',
'', '',
...@@ -1184,7 +1184,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1184,7 +1184,7 @@ class GClientSmokeGIT(GClientSmokeBase):
' "false_var": False,', ' "false_var": False,',
'', '',
' # src', ' # src',
' "git_base": \'git://127.0.0.1:20000/git/\',', ' "git_base": \'' + self.git_base + '\',',
'', '',
' # src', ' # src',
' "hook1_contents": \'git_hooked1\',', ' "hook1_contents": \'git_hooked1\',',
...@@ -1206,9 +1206,9 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1206,9 +1206,9 @@ class GClientSmokeGIT(GClientSmokeBase):
'', '',
'}', '}',
'', '',
'# git://127.0.0.1:20000/git/repo_2@%s, DEPS' % ( '# ' + self.git_base + 'repo_2@%s, DEPS' % (
self.githash('repo_2', 1)), self.githash('repo_2', 1)),
'# git://127.0.0.1:20000/git/repo_8@%s, DEPS' % ( '# ' + self.git_base + 'repo_8@%s, DEPS' % (
self.githash('repo_8', 1)), self.githash('repo_8', 1)),
], deps_contents.splitlines()) ], deps_contents.splitlines())
...@@ -1238,7 +1238,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1238,7 +1238,7 @@ class GClientSmokeGIT(GClientSmokeBase):
'deps = {', 'deps = {',
' # src', ' # src',
' "src": {', ' "src": {',
' "url": "git://127.0.0.1:20000/git/repo_10",', ' "url": "' + self.git_base + 'repo_10",',
' },', ' },',
'', '',
' # src -> src/repo9 -> src/repo8 -> src/recursed_os_repo', ' # src -> src/repo9 -> src/repo8 -> src/recursed_os_repo',
...@@ -1293,25 +1293,25 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1293,25 +1293,25 @@ class GClientSmokeGIT(GClientSmokeBase):
'', '',
'}', '}',
'', '',
'# git://127.0.0.1:20000/git/repo_11, DEPS', '# ' + self.git_base + 'repo_11, DEPS',
'# git://127.0.0.1:20000/git/repo_8, DEPS', '# ' + self.git_base + 'repo_8, DEPS',
'# git://127.0.0.1:20000/git/repo_9, DEPS', '# ' + self.git_base + 'repo_9, DEPS',
], deps_contents.splitlines()) ], deps_contents.splitlines())
with open(output_deps_files) as f: with open(output_deps_files) as f:
deps_files_contents = json.load(f) deps_files_contents = json.load(f)
self.assertEqual([ self.assertEqual([
{'url': 'git://127.0.0.1:20000/git/repo_11', 'deps_file': 'DEPS', {'url': self.git_base + 'repo_11', 'deps_file': 'DEPS',
'hierarchy': [['src', 'git://127.0.0.1:20000/git/repo_10'], 'hierarchy': [['src', self.git_base + 'repo_10'],
['src/repo11', 'git://127.0.0.1:20000/git/repo_11']]}, ['src/repo11', self.git_base + 'repo_11']]},
{'url': 'git://127.0.0.1:20000/git/repo_8', 'deps_file': 'DEPS', {'url': self.git_base + 'repo_8', 'deps_file': 'DEPS',
'hierarchy': [['src', 'git://127.0.0.1:20000/git/repo_10'], 'hierarchy': [['src', self.git_base + 'repo_10'],
['src/repo9', 'git://127.0.0.1:20000/git/repo_9'], ['src/repo9', self.git_base + 'repo_9'],
['src/repo8', 'git://127.0.0.1:20000/git/repo_8']]}, ['src/repo8', self.git_base + 'repo_8']]},
{'url': 'git://127.0.0.1:20000/git/repo_9', 'deps_file': 'DEPS', {'url': self.git_base + 'repo_9', 'deps_file': 'DEPS',
'hierarchy': [['src', 'git://127.0.0.1:20000/git/repo_10'], 'hierarchy': [['src', self.git_base + 'repo_10'],
['src/repo9', 'git://127.0.0.1:20000/git/repo_9']]}, ['src/repo9', self.git_base + 'repo_9']]},
], deps_files_contents) ], deps_files_contents)
def testFlattenCipd(self): def testFlattenCipd(self):
...@@ -1333,7 +1333,7 @@ class GClientSmokeGIT(GClientSmokeBase): ...@@ -1333,7 +1333,7 @@ class GClientSmokeGIT(GClientSmokeBase):
'deps = {', 'deps = {',
' # src', ' # src',
' "src": {', ' "src": {',
' "url": "git://127.0.0.1:20000/git/repo_14",', ' "url": "' + self.git_base + 'repo_14",',
' },', ' },',
'', '',
' # src -> src/cipd_dep:package0', ' # src -> src/cipd_dep:package0',
......
#!/usr/bin/env python
# Copyright (c) 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import os
import sys
import subprocess
import unittest
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, ROOT_DIR)
from testing_support import fake_repos
ROLL_DEP = os.path.join(ROOT_DIR, 'roll-dep')
GCLIENT = os.path.join(ROOT_DIR, 'gclient')
class FakeRepos(fake_repos.FakeReposBase):
NB_GIT_REPOS = 2
def populateGit(self):
self._commit_git('repo_2', {
'origin': 'git/repo_2@1',
})
self._commit_git('repo_2', {
'origin': 'git/repo_2@2',
})
self._commit_git('repo_2', {
'origin': 'git/repo_2@3',
})
self._commit_git('repo_1', {
'DEPS': '\n'.join([
'deps = {',
' "src/foo": "%(git_base)srepo_2@%(repo_2_revision)s",',
'}',
]) % {
'git_base': self.git_base,
'repo_2_revision': self.git_hashes['repo_2'][1][0],
},
})
class RollDepTest(fake_repos.FakeReposTestBase):
FAKE_REPOS_CLASS = FakeRepos
def setUp(self):
super(RollDepTest, self).setUp()
# Make sure it doesn't try to auto update when testing!
self.env = os.environ.copy()
self.env['DEPOT_TOOLS_UPDATE'] = '0'
self.enabled = self.FAKE_REPOS.set_up_git()
self.src_dir = os.path.join(self.root_dir, 'src')
self.foo_dir = os.path.join(self.src_dir, 'foo')
if self.enabled:
self.call([GCLIENT, 'config', self.git_base + 'repo_1', '--name', 'src'],
cwd=self.root_dir)
self.call([GCLIENT, 'sync'], cwd=self.root_dir)
def call(self, cmd, cwd=None):
cwd = cwd or self.src_dir
process = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=sys.platform.startswith('win'))
stdout, stderr = process.communicate()
logging.debug("XXX: %s\n%s\nXXX" % (' '.join(cmd), stdout))
logging.debug("YYY: %s\n%s\nYYY" % (' '.join(cmd), stderr))
return (stdout.replace('\r\n', '\n'), stderr.replace('\r\n', '\n'),
process.returncode)
def testRollsDep(self):
if not self.enabled:
return
stdout = self.call([ROLL_DEP, 'src/foo'])[0]
expected_revision = self.githash('repo_2', 3)
with open(os.path.join(self.src_dir, 'DEPS')) as f:
contents = f.read()
self.assertEqual(self.gitrevparse(self.foo_dir), expected_revision)
self.assertEqual([
'deps = {',
' "src/foo": "' + self.git_base + 'repo_2@' + expected_revision + '",',
'}',
], contents.splitlines())
commit_message = self.call(['git', 'log', '-n', '1'])[0]
expected_message = 'Roll src/foo/ %s..%s (2 commits)' % (
self.githash('repo_2', 1)[:9], self.githash('repo_2', 3)[:9])
self.assertIn(expected_message, stdout)
self.assertIn(expected_message, commit_message)
def testRollsDepToSpecificRevision(self):
if not self.enabled:
return
stdout = self.call([ROLL_DEP, 'src/foo',
'--roll-to', self.githash('repo_2', 2)])[0]
expected_revision = self.githash('repo_2', 2)
with open(os.path.join(self.src_dir, 'DEPS')) as f:
contents = f.read()
self.assertEqual(self.gitrevparse(self.foo_dir), expected_revision)
self.assertEqual([
'deps = {',
' "src/foo": "' + self.git_base + 'repo_2@' + expected_revision + '",',
'}',
], contents.splitlines())
commit_message = self.call(['git', 'log', '-n', '1'])[0]
expected_message = 'Roll src/foo/ %s..%s (1 commit)' % (
self.githash('repo_2', 1)[:9], self.githash('repo_2', 2)[:9])
self.assertIn(expected_message, stdout)
self.assertIn(expected_message, commit_message)
if __name__ == '__main__':
level = logging.DEBUG if '-v' in sys.argv else logging.FATAL
logging.basicConfig(
level=level,
format='%(asctime).19s %(levelname)s %(filename)s:'
'%(lineno)s %(message)s')
unittest.main()
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