| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import base64 |
| 5 import collections | 6 import collections |
| 6 | 7 |
| 7 from testing_utils import testing | 8 from testing_utils import testing |
| 8 | 9 |
| 9 from common import chromium_deps | 10 from common import chromium_deps |
| 10 from common import deps_parser | 11 from common import deps_parser |
| 11 from common import git_repository | 12 from common import git_repository |
| 12 from common import repository | 13 from common import repository |
| 14 from common import retry_http_client |
| 15 from common import http_client_appengine |
| 13 from common.dependency import Dependency, DependencyRoll | 16 from common.dependency import Dependency, DependencyRoll |
| 14 | 17 |
| 15 | 18 |
| 16 class DummyGitRepository(repository.Repository): | 19 class DummyGitRepository(repository.Repository): |
| 17 RESPONSES = {} | 20 RESPONSES = {} |
| 18 | 21 |
| 19 def __init__(self, *_): | 22 def __init__(self, *_): |
| 20 pass | 23 pass |
| 21 | 24 |
| 22 def GetSource(self, path, revision): | 25 def GetSource(self, path, revision): |
| 23 return self.RESPONSES.get(path, {}).get(revision, None) | 26 return self.RESPONSES.get(path, {}).get(revision, None) |
| 24 | 27 |
| 28 def GetRevisionForChromeVersion(self, *_): |
| 29 return '123a' |
| 30 |
| 25 | 31 |
| 26 class ChromiumDEPSTest(testing.AppengineTestCase): | 32 class ChromiumDEPSTest(testing.AppengineTestCase): |
| 27 DEPS_GIT = '.DEPS.git' | 33 DEPS_GIT = '.DEPS.git' |
| 28 DEPS = 'DEPS' | 34 DEPS = 'DEPS' |
| 29 | 35 |
| 30 def testUseDEPS_GIT(self): | 36 def testUseDEPS_GIT(self): |
| 31 revision = 'abc' | 37 revision = 'abc' |
| 32 expected_content = '.DEPS.git content' | 38 expected_content = '.DEPS.git content' |
| 33 | 39 |
| 34 DummyGitRepository.RESPONSES = { | 40 DummyGitRepository.RESPONSES = { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 def testFailedToPullDEPSFile(self): | 93 def testFailedToPullDEPSFile(self): |
| 88 DummyGitRepository.RESPONSES = {} | 94 DummyGitRepository.RESPONSES = {} |
| 89 | 95 |
| 90 self.mock(git_repository, 'GitRepository', DummyGitRepository) | 96 self.mock(git_repository, 'GitRepository', DummyGitRepository) |
| 91 | 97 |
| 92 deps_downloader = chromium_deps.DEPSDownloader() | 98 deps_downloader = chromium_deps.DEPSDownloader() |
| 93 self.assertRaisesRegexp(Exception, 'Failed to pull DEPS file.', | 99 self.assertRaisesRegexp(Exception, 'Failed to pull DEPS file.', |
| 94 deps_downloader.Load, | 100 deps_downloader.Load, |
| 95 'https://src.git', 'abc', 'DEPS') | 101 'https://src.git', 'abc', 'DEPS') |
| 96 | 102 |
| 103 def testDEPSDownloaderForChromeVersion(self): |
| 104 |
| 105 def _MockGet(*args): |
| 106 url = args[1] |
| 107 if 'dummy' in url: |
| 108 return 404, None |
| 109 |
| 110 return 200, base64.b64encode('Dummy DEPS content') |
| 111 |
| 112 self.mock(http_client_appengine.HttpClientAppengine, '_Get', _MockGet) |
| 113 |
| 114 content = chromium_deps.DEPSDownloaderForChromeVersion().Load( |
| 115 'http://chrome-internal', '50.0.1234.0', 'DEPS') |
| 116 self.assertEqual(content, 'Dummy DEPS content') |
| 117 |
| 118 content = chromium_deps.DEPSDownloaderForChromeVersion().Load( |
| 119 'http://chrome-internal', 'dummy', 'DEPS') |
| 120 self.assertIsNone(content) |
| 121 |
| 97 def testGetChromeDependency(self): | 122 def testGetChromeDependency(self): |
| 98 src_path = 'src/' | 123 src_path = 'src/' |
| 99 src_repo_url = 'https://chromium.googlesource.com/chromium/src.git' | 124 src_repo_url = 'https://chromium.googlesource.com/chromium/src.git' |
| 100 src_revision = '123a' | 125 src_revision = '123a' |
| 101 os_platform = 'unix' | 126 os_platform = 'unix' |
| 102 | 127 |
| 103 child1_dep = Dependency('src/a/', 'https://a.git', '123a', 'DEPS') | 128 child1_dep = Dependency('src/a/', 'https://a.git', '123a', 'DEPS') |
| 104 child2_dep = Dependency('src/b/', 'https://b.git', '123b', 'DEPS') | 129 child2_dep = Dependency('src/b/', 'https://b.git', '123b', 'DEPS') |
| 105 grand_child1 = Dependency('src/a/aa/', 'https://aa.git', '123aa', 'DEPS') | 130 grand_child1 = Dependency('src/a/aa/', 'https://aa.git', '123aa', 'DEPS') |
| 106 | 131 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 120 child1_dep.SetParent(root_dep) | 145 child1_dep.SetParent(root_dep) |
| 121 child2_dep.SetParent(root_dep) | 146 child2_dep.SetParent(root_dep) |
| 122 grand_child1.SetParent(child1_dep) | 147 grand_child1.SetParent(child1_dep) |
| 123 | 148 |
| 124 self.mock(deps_parser, 'UpdateDependencyTree', DummyUpdateDependencyTree) | 149 self.mock(deps_parser, 'UpdateDependencyTree', DummyUpdateDependencyTree) |
| 125 | 150 |
| 126 dependency_dict = chromium_deps.GetChromeDependency( | 151 dependency_dict = chromium_deps.GetChromeDependency( |
| 127 src_revision, os_platform) | 152 src_revision, os_platform) |
| 128 self.assertEqual(expected_dependency_dict, dependency_dict) | 153 self.assertEqual(expected_dependency_dict, dependency_dict) |
| 129 | 154 |
| 155 def testGetChromeDependencyForChromeVersion(self): |
| 156 src_path = 'src/' |
| 157 src_repo_url = 'https://chromium.googlesource.com/chromium/src.git' |
| 158 os_platform = 'unix' |
| 159 |
| 160 child1_dep = Dependency('src/a/', 'https://a.git', '123a', 'DEPS') |
| 161 child2_dep = Dependency('src/b/', 'https://b.git', '123b', 'DEPS') |
| 162 grand_child1 = Dependency('src/a/aa/', 'https://aa.git', '123aa', 'DEPS') |
| 163 |
| 164 expected_dependency_dict = { |
| 165 'src/a/': child1_dep, |
| 166 'src/b/': child2_dep, |
| 167 'src/a/aa/': grand_child1, |
| 168 } |
| 169 |
| 170 def DummyUpdateDependencyTree(root_dep, target_os_list, _): |
| 171 self.assertEqual(src_path, root_dep.path) |
| 172 self.assertEqual(src_repo_url, root_dep.repo_url) |
| 173 self.assertEqual([os_platform], target_os_list) |
| 174 |
| 175 expected_dependency_dict[root_dep.path] = root_dep |
| 176 child1_dep.SetParent(root_dep) |
| 177 child2_dep.SetParent(root_dep) |
| 178 grand_child1.SetParent(child1_dep) |
| 179 |
| 180 self.mock(git_repository, 'GitRepository', DummyGitRepository) |
| 181 self.mock(deps_parser, 'UpdateDependencyTree', DummyUpdateDependencyTree) |
| 182 |
| 183 dependency_dict = chromium_deps.GetChromeDependency( |
| 184 '50.0.1234.0', os_platform) |
| 185 self.assertEqual(expected_dependency_dict, dependency_dict) |
| 186 |
| 130 def testGetChromiumDEPSRolls(self): | 187 def testGetChromiumDEPSRolls(self): |
| 131 def MockGetChromeDependency(revision, os_platform, _=False): | 188 def MockGetChromeDependency(revision, os_platform, _=False): |
| 132 self.assertEqual('unix', os_platform) | 189 self.assertEqual('unix', os_platform) |
| 133 if revision == 'rev2': | 190 if revision == 'rev2': |
| 134 return { | 191 return { |
| 135 'src/': Dependency('src/', 'https://url_src', 'rev2', 'DEPS'), | 192 'src/': Dependency('src/', 'https://url_src', 'rev2', 'DEPS'), |
| 136 'src/dep1': Dependency('src/dep1', 'https://url_dep1', '9', 'DEPS'), | 193 'src/dep1': Dependency('src/dep1', 'https://url_dep1', '9', 'DEPS'), |
| 137 'src/dep2': Dependency('src/dep2', 'https://url_dep2', '5', 'DEPS'), | 194 'src/dep2': Dependency('src/dep2', 'https://url_dep2', '5', 'DEPS'), |
| 138 'src/dep4': Dependency('src/dep4', 'https://url_dep4', '1', 'DEPS'), | 195 'src/dep4': Dependency('src/dep4', 'https://url_dep4', '1', 'DEPS'), |
| 139 } | 196 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 167 'old_revision': '3', | 224 'old_revision': '3', |
| 168 'new_revision': None, | 225 'new_revision': None, |
| 169 }, | 226 }, |
| 170 ] | 227 ] |
| 171 | 228 |
| 172 deps_rolls = chromium_deps.GetChromiumDEPSRolls('rev1', 'rev2', 'unix') | 229 deps_rolls = chromium_deps.GetChromiumDEPSRolls('rev1', 'rev2', 'unix') |
| 173 self.assertEqual(expected_deps_rolls, | 230 self.assertEqual(expected_deps_rolls, |
| 174 [roll.ToDict() for roll in deps_rolls]) | 231 [roll.ToDict() for roll in deps_rolls]) |
| 175 | 232 |
| 176 def testGetDEPSRollsDict(self): | 233 def testGetDEPSRollsDict(self): |
| 177 def _MockGetChromiumDEPSRolls(*_): | 234 def _MockGetChromiumDEPSRolls(old_revision, new_revision, _, **kargs): |
| 178 return [ | 235 dependency_rolls = [ |
| 179 DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), | 236 DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), |
| 180 DependencyRoll('src/dep2', 'https://url_dep2', '3', None) | 237 DependencyRoll('src/dep2', 'https://url_dep2', '3', None) |
| 181 ] | 238 ] |
| 239 if not kargs['skip_chromium_roll']: |
| 240 dependency_rolls.append(DependencyRoll( |
| 241 'src/', |
| 242 'https://chromium.googlesource.com/chromium/src.git', |
| 243 old_revision, new_revision)) |
| 244 |
| 245 return dependency_rolls |
| 182 | 246 |
| 183 self.mock(chromium_deps, 'GetChromiumDEPSRolls', | 247 self.mock(chromium_deps, 'GetChromiumDEPSRolls', |
| 184 _MockGetChromiumDEPSRolls) | 248 _MockGetChromiumDEPSRolls) |
| 185 | 249 |
| 250 expected_deps_rolls_skip_chromium = [ |
| 251 DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), |
| 252 DependencyRoll('src/dep2', 'https://url_dep2', '3', None) |
| 253 ] |
| 254 self.assertEqual( |
| 255 chromium_deps.GetChromiumDEPSRolls('4', '5', 'all', |
| 256 skip_chromium_roll=True), |
| 257 expected_deps_rolls_skip_chromium) |
| 258 |
| 186 expected_deps_rolls_dict = { | 259 expected_deps_rolls_dict = { |
| 187 'src/dep1': DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), | 260 'src/dep1': DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), |
| 188 'src/dep2': DependencyRoll('src/dep2', 'https://url_dep2', '3', None), | 261 'src/dep2': DependencyRoll('src/dep2', 'https://url_dep2', '3', None), |
| 189 'src/': DependencyRoll( | 262 'src/': DependencyRoll( |
| 190 'src/', | 263 'src/', |
| 191 'https://chromium.googlesource.com/chromium/src.git', '4', '5'), | 264 'https://chromium.googlesource.com/chromium/src.git', '4', '5'), |
| 192 } | 265 } |
| 193 | |
| 194 self.assertEqual(chromium_deps.GetDEPSRollsDict('4', '5', 'all'), | 266 self.assertEqual(chromium_deps.GetDEPSRollsDict('4', '5', 'all'), |
| 195 expected_deps_rolls_dict) | 267 expected_deps_rolls_dict) |
| 196 | 268 |
| 269 def testIsChromeVersion(self): |
| 270 self.assertTrue(chromium_deps.IsChromeVersion('50.0.1234.1')) |
| 271 self.assertFalse(chromium_deps.IsChromeVersion('a.b.c.e')) |
| 272 self.assertFalse(chromium_deps.IsChromeVersion('502.021.2.0.123')) |
| OLD | NEW |