| 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 not '50.0.1234.0' 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.DEPSDownloader().Load( |
| 115 'http://chrome-internal', '50.0.1234.0', 'DEPS') |
| 116 self.assertEqual(content, 'Dummy DEPS content') |
| 117 |
| 118 self.assertRaisesRegexp( |
| 119 Exception, |
| 120 'Failed to pull DEPS file from buildspec/ for version 50.0.1234.1.', |
| 121 chromium_deps.DEPSDownloader().Load, |
| 122 'http://chrome-internal', '50.0.1234.1', 'DEPS') |
| 123 |
| 97 def testGetChromeDependency(self): | 124 def testGetChromeDependency(self): |
| 98 src_path = 'src/' | 125 src_path = 'src/' |
| 99 src_repo_url = 'https://chromium.googlesource.com/chromium/src.git' | 126 src_repo_url = 'https://chromium.googlesource.com/chromium/src.git' |
| 100 src_revision = '123a' | 127 src_revision = '123a' |
| 101 os_platform = 'unix' | 128 os_platform = 'unix' |
| 102 | 129 |
| 103 child1_dep = Dependency('src/a/', 'https://a.git', '123a', 'DEPS') | 130 child1_dep = Dependency('src/a/', 'https://a.git', '123a', 'DEPS') |
| 104 child2_dep = Dependency('src/b/', 'https://b.git', '123b', 'DEPS') | 131 child2_dep = Dependency('src/b/', 'https://b.git', '123b', 'DEPS') |
| 105 grand_child1 = Dependency('src/a/aa/', 'https://aa.git', '123aa', 'DEPS') | 132 grand_child1 = Dependency('src/a/aa/', 'https://aa.git', '123aa', 'DEPS') |
| 106 | 133 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 120 child1_dep.SetParent(root_dep) | 147 child1_dep.SetParent(root_dep) |
| 121 child2_dep.SetParent(root_dep) | 148 child2_dep.SetParent(root_dep) |
| 122 grand_child1.SetParent(child1_dep) | 149 grand_child1.SetParent(child1_dep) |
| 123 | 150 |
| 124 self.mock(deps_parser, 'UpdateDependencyTree', DummyUpdateDependencyTree) | 151 self.mock(deps_parser, 'UpdateDependencyTree', DummyUpdateDependencyTree) |
| 125 | 152 |
| 126 dependency_dict = chromium_deps.GetChromeDependency( | 153 dependency_dict = chromium_deps.GetChromeDependency( |
| 127 src_revision, os_platform) | 154 src_revision, os_platform) |
| 128 self.assertEqual(expected_dependency_dict, dependency_dict) | 155 self.assertEqual(expected_dependency_dict, dependency_dict) |
| 129 | 156 |
| 157 def testGetChromeDependencyForChromeVersion(self): |
| 158 src_path = 'src/' |
| 159 src_repo_url = 'https://chromium.googlesource.com/chromium/src.git' |
| 160 os_platform = 'unix' |
| 161 |
| 162 child1_dep = Dependency('src/a/', 'https://a.git', '123a', 'DEPS') |
| 163 child2_dep = Dependency('src/b/', 'https://b.git', '123b', 'DEPS') |
| 164 grand_child1 = Dependency('src/a/aa/', 'https://aa.git', '123aa', 'DEPS') |
| 165 |
| 166 expected_dependency_dict = { |
| 167 'src/a/': child1_dep, |
| 168 'src/b/': child2_dep, |
| 169 'src/a/aa/': grand_child1, |
| 170 } |
| 171 |
| 172 def DummyUpdateDependencyTree(root_dep, target_os_list, _): |
| 173 self.assertEqual(src_path, root_dep.path) |
| 174 self.assertEqual(src_repo_url, root_dep.repo_url) |
| 175 self.assertEqual([os_platform], target_os_list) |
| 176 |
| 177 expected_dependency_dict[root_dep.path] = root_dep |
| 178 child1_dep.SetParent(root_dep) |
| 179 child2_dep.SetParent(root_dep) |
| 180 grand_child1.SetParent(child1_dep) |
| 181 |
| 182 self.mock(git_repository, 'GitRepository', DummyGitRepository) |
| 183 self.mock(deps_parser, 'UpdateDependencyTree', DummyUpdateDependencyTree) |
| 184 |
| 185 dependency_dict = chromium_deps.GetChromeDependency( |
| 186 '50.0.1234.0', os_platform) |
| 187 self.assertEqual(expected_dependency_dict, dependency_dict) |
| 188 |
| 130 def testGetChromiumDEPSRolls(self): | 189 def testGetChromiumDEPSRolls(self): |
| 131 def MockGetChromeDependency(revision, os_platform, _=False): | 190 def MockGetChromeDependency(revision, os_platform, _=False): |
| 132 self.assertEqual('unix', os_platform) | 191 self.assertEqual('unix', os_platform) |
| 133 if revision == 'rev2': | 192 if revision == 'rev2': |
| 134 return { | 193 return { |
| 135 'src/': Dependency('src/', 'https://url_src', 'rev2', 'DEPS'), | 194 'src/': Dependency('src/', 'https://url_src', 'rev2', 'DEPS'), |
| 136 'src/dep1': Dependency('src/dep1', 'https://url_dep1', '9', 'DEPS'), | 195 'src/dep1': Dependency('src/dep1', 'https://url_dep1', '9', 'DEPS'), |
| 137 'src/dep2': Dependency('src/dep2', 'https://url_dep2', '5', 'DEPS'), | 196 'src/dep2': Dependency('src/dep2', 'https://url_dep2', '5', 'DEPS'), |
| 138 'src/dep4': Dependency('src/dep4', 'https://url_dep4', '1', 'DEPS'), | 197 'src/dep4': Dependency('src/dep4', 'https://url_dep4', '1', 'DEPS'), |
| 139 } | 198 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 167 'old_revision': '3', | 226 'old_revision': '3', |
| 168 'new_revision': None, | 227 'new_revision': None, |
| 169 }, | 228 }, |
| 170 ] | 229 ] |
| 171 | 230 |
| 172 deps_rolls = chromium_deps.GetChromiumDEPSRolls('rev1', 'rev2', 'unix') | 231 deps_rolls = chromium_deps.GetChromiumDEPSRolls('rev1', 'rev2', 'unix') |
| 173 self.assertEqual(expected_deps_rolls, | 232 self.assertEqual(expected_deps_rolls, |
| 174 [roll.ToDict() for roll in deps_rolls]) | 233 [roll.ToDict() for roll in deps_rolls]) |
| 175 | 234 |
| 176 def testGetDEPSRollsDict(self): | 235 def testGetDEPSRollsDict(self): |
| 177 def _MockGetChromiumDEPSRolls(*_): | 236 def _MockGetChromiumDEPSRolls(old_revision, new_revision, _, **kargs): |
| 178 return [ | 237 dependency_rolls = [ |
| 179 DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), | 238 DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), |
| 180 DependencyRoll('src/dep2', 'https://url_dep2', '3', None) | 239 DependencyRoll('src/dep2', 'https://url_dep2', '3', None) |
| 181 ] | 240 ] |
| 241 if not kargs['skip_chromium_roll']: |
| 242 dependency_rolls.append(DependencyRoll( |
| 243 'src/', |
| 244 'https://chromium.googlesource.com/chromium/src.git', |
| 245 old_revision, new_revision)) |
| 246 |
| 247 return dependency_rolls |
| 182 | 248 |
| 183 self.mock(chromium_deps, 'GetChromiumDEPSRolls', | 249 self.mock(chromium_deps, 'GetChromiumDEPSRolls', |
| 184 _MockGetChromiumDEPSRolls) | 250 _MockGetChromiumDEPSRolls) |
| 185 | 251 |
| 252 expected_deps_rolls_skip_chromium = [ |
| 253 DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), |
| 254 DependencyRoll('src/dep2', 'https://url_dep2', '3', None) |
| 255 ] |
| 256 self.assertEqual( |
| 257 chromium_deps.GetChromiumDEPSRolls('4', '5', 'all', |
| 258 skip_chromium_roll=True), |
| 259 expected_deps_rolls_skip_chromium) |
| 260 |
| 186 expected_deps_rolls_dict = { | 261 expected_deps_rolls_dict = { |
| 187 'src/dep1': DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), | 262 'src/dep1': DependencyRoll('src/dep1', 'https://url_dep1', '7', '9'), |
| 188 'src/dep2': DependencyRoll('src/dep2', 'https://url_dep2', '3', None), | 263 'src/dep2': DependencyRoll('src/dep2', 'https://url_dep2', '3', None), |
| 189 'src/': DependencyRoll( | 264 'src/': DependencyRoll( |
| 190 'src/', | 265 'src/', |
| 191 'https://chromium.googlesource.com/chromium/src.git', '4', '5'), | 266 'https://chromium.googlesource.com/chromium/src.git', '4', '5'), |
| 192 } | 267 } |
| 193 | |
| 194 self.assertEqual(chromium_deps.GetDEPSRollsDict('4', '5', 'all'), | 268 self.assertEqual(chromium_deps.GetDEPSRollsDict('4', '5', 'all'), |
| 195 expected_deps_rolls_dict) | 269 expected_deps_rolls_dict) |
| 196 | 270 |
| 271 def testIsChromeVersion(self): |
| 272 self.assertTrue(chromium_deps.IsChromeVersion('50.0.1234.1')) |
| 273 self.assertFalse(chromium_deps.IsChromeVersion('a.b.c.e')) |
| 274 self.assertFalse(chromium_deps.IsChromeVersion('502.021.2.0.123')) |
| OLD | NEW |