roll_downstream_gcs_deps_test.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #!/usr/bin/env python3
  2. # Copyright 2024 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import logging
  6. import os
  7. import sys
  8. import unittest
  9. ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  10. sys.path.insert(0, ROOT_DIR)
  11. import roll_downstream_gcs_deps
  12. class CopyPackageTest(unittest.TestCase):
  13. def testNoDepsToRoll(self):
  14. with self.assertRaises(Exception):
  15. roll_downstream_gcs_deps.copy_packages('', '', ['foo'], ['foo'])
  16. with self.assertRaises(Exception):
  17. roll_downstream_gcs_deps.copy_packages('deps = {"foo": ""}',
  18. 'deps = {}', ['foo'],
  19. ['foo'])
  20. with self.assertRaises(Exception):
  21. roll_downstream_gcs_deps.copy_packages('deps = {"foo": ""}',
  22. 'deps = {"bar": ""}',
  23. ['foo'], ['baz'])
  24. def testNoGCSDeps(self):
  25. source_deps = '''
  26. deps = {
  27. "foo": {
  28. 'dep_type': 'unknown',
  29. 'objects': [
  30. {
  31. 'object_name': 'foo-v2.tar.xz',
  32. 'sha256sum': '1111111111111111111111111111111111111111111111111111111111111111',
  33. 'size_bytes': 101,
  34. 'generation': 901,
  35. },
  36. ]
  37. },
  38. }
  39. '''
  40. destination_deps = '''
  41. deps = {
  42. "foo": {
  43. 'dep_type': 'unknown',
  44. 'objects': [
  45. {
  46. 'object_name': 'foo.tar.xz',
  47. 'sha256sum': '0000000000000000000000000000000000000000000000000000000000000000',
  48. 'size_bytes': 100,
  49. 'generation': 900,
  50. },
  51. ]
  52. },
  53. }
  54. '''
  55. with self.assertRaises(Exception):
  56. roll_downstream_gcs_deps.copy_packages(source_deps,
  57. destination_deps, ['foo'],
  58. ['foo'])
  59. def testObjectInLineUpdate(self):
  60. source_deps = '''
  61. deps = {
  62. "foo": {
  63. 'dep_type': 'gcs',
  64. 'bucket': 'foo',
  65. 'condition': 'deps source condition',
  66. 'objects': [
  67. {
  68. 'object_name': 'foo-v2.tar.xz',
  69. 'sha256sum': '1111111111111111111111111111111111111111111111111111111111111111',
  70. 'size_bytes': 101,
  71. 'generation': 901,
  72. 'condition': 'host_os == "linux" and non_git_source and new',
  73. },
  74. ]
  75. },
  76. }
  77. '''
  78. destination_deps = '''
  79. deps = {
  80. "other": "preserved",
  81. "foo": {
  82. 'dep_type': 'gcs',
  83. 'bucket': 'foo',
  84. 'condition': 'deps dest condition',
  85. 'objects': [
  86. {
  87. 'object_name': 'foo.tar.xz',
  88. 'sha256sum': '0000000000000000000000000000000000000000000000000000000000000000',
  89. 'size_bytes': 100,
  90. 'generation': 900,
  91. 'condition': 'host_os == "linux" and non_git_source',
  92. },
  93. ]
  94. },
  95. "another": "preserved",
  96. }
  97. '''
  98. expected_deps = '''
  99. deps = {
  100. "other": "preserved",
  101. "foo": {
  102. 'dep_type': 'gcs',
  103. 'bucket': 'foo',
  104. 'condition': 'deps dest condition',
  105. 'objects': [
  106. {
  107. 'object_name': 'foo-v2.tar.xz',
  108. 'sha256sum': '1111111111111111111111111111111111111111111111111111111111111111',
  109. 'size_bytes': 101,
  110. 'generation': 901,
  111. 'condition': 'host_os == "linux" and non_git_source and new',
  112. },
  113. ]
  114. },
  115. "another": "preserved",
  116. }
  117. '''
  118. result = roll_downstream_gcs_deps.copy_packages(source_deps,
  119. destination_deps,
  120. ['foo'], ['foo'])
  121. self.assertEqual(result, expected_deps)
  122. def testGCSRustPackageNewPlatform(self):
  123. source_deps = '''
  124. deps = {
  125. 'src/third_party/rust-toolchain': {
  126. 'dep_type': 'gcs',
  127. 'bucket': 'chromium-browser-clang',
  128. 'objects': [
  129. {
  130. 'object_name': 'Linux_x64/rust-toolchain-595316b4006932405a63862d8fe65f71a6356293-3-llvmorg-20-init-1009-g7088a5ed.tar.xz',
  131. 'sha256sum': '560c02da5300f40441992ef639d83cee96cae3584c3d398704fdb2f02e475bbf',
  132. 'size_bytes': 152024840,
  133. 'generation': 1722663990116408,
  134. 'condition': 'host_os == "linux" and non_git_source',
  135. },
  136. {
  137. 'object_name': 'Mac/rust-toolchain-595316b4006932405a63862d8fe65f71a6356293-3-llvmorg-20-init-1009-g7088a5ed.tar.xz',
  138. 'sha256sum': '9f39154b4337438fd170e729ed2ae4c978b22f11708d683c28265bd096df17a5',
  139. 'size_bytes': 144459260,
  140. 'generation': 1722663991651609,
  141. 'condition': 'host_os == "mac" and host_cpu == "x64"',
  142. },
  143. {
  144. 'object_name': 'Mac_arm64/rust-toolchain-595316b4006932405a63862d8fe65f71a6356293-3-llvmorg-20-init-1009-g7088a5ed.tar.xz',
  145. 'sha256sum': '4b89cf125ffa39e8fc74f01ec3beeb632fd3069478d8c6cc4fcae506b4917151',
  146. 'size_bytes': 135571272,
  147. 'generation': 1722663993205996,
  148. 'condition': 'host_os == "mac" and host_cpu == "arm64"',
  149. },
  150. {
  151. 'object_name': 'Win/rust-toolchain-595316b4006932405a63862d8fe65f71a6356293-3-llvmorg-20-init-1009-g7088a5ed.tar.xz',
  152. 'sha256sum': '3f6a1a87695902062a6575632552b9f2cbbbcda1907fe3232f49b8ea29baecf5',
  153. 'size_bytes': 208844028,
  154. 'generation': 1722663994756449,
  155. 'condition': 'host_os == "win"',
  156. },
  157. ],
  158. },
  159. }
  160. '''
  161. destination_deps = '''
  162. deps = {
  163. 'third_party/rust-toolchain': {
  164. 'dep_type': 'gcs',
  165. 'bucket': 'chromium-browser-clang',
  166. 'objects': [
  167. {
  168. 'object_name': 'Linux_x64/rust-toolchain-0000000000000000000000000000000000000000-0.tar.xz',
  169. 'sha256sum': '0000000000000000000000000000000000000000000000000000000000000000',
  170. 'size_bytes': 123,
  171. 'generation': 987,
  172. 'condition': 'other condition',
  173. },
  174. ],
  175. },
  176. }
  177. '''
  178. expected_deps = '''
  179. deps = {
  180. 'third_party/rust-toolchain': {
  181. 'dep_type': 'gcs',
  182. 'bucket': 'chromium-browser-clang',
  183. 'objects': [
  184. {
  185. 'object_name': 'Linux_x64/rust-toolchain-595316b4006932405a63862d8fe65f71a6356293-3-llvmorg-20-init-1009-g7088a5ed.tar.xz',
  186. 'sha256sum': '560c02da5300f40441992ef639d83cee96cae3584c3d398704fdb2f02e475bbf',
  187. 'size_bytes': 152024840,
  188. 'generation': 1722663990116408,
  189. 'condition': 'host_os == "linux" and non_git_source',
  190. },
  191. {
  192. 'object_name': 'Mac/rust-toolchain-595316b4006932405a63862d8fe65f71a6356293-3-llvmorg-20-init-1009-g7088a5ed.tar.xz',
  193. 'sha256sum': '9f39154b4337438fd170e729ed2ae4c978b22f11708d683c28265bd096df17a5',
  194. 'size_bytes': 144459260,
  195. 'generation': 1722663991651609,
  196. 'condition': 'host_os == "mac" and host_cpu == "x64"',
  197. },
  198. {
  199. 'object_name': 'Mac_arm64/rust-toolchain-595316b4006932405a63862d8fe65f71a6356293-3-llvmorg-20-init-1009-g7088a5ed.tar.xz',
  200. 'sha256sum': '4b89cf125ffa39e8fc74f01ec3beeb632fd3069478d8c6cc4fcae506b4917151',
  201. 'size_bytes': 135571272,
  202. 'generation': 1722663993205996,
  203. 'condition': 'host_os == "mac" and host_cpu == "arm64"',
  204. },
  205. {
  206. 'object_name': 'Win/rust-toolchain-595316b4006932405a63862d8fe65f71a6356293-3-llvmorg-20-init-1009-g7088a5ed.tar.xz',
  207. 'sha256sum': '3f6a1a87695902062a6575632552b9f2cbbbcda1907fe3232f49b8ea29baecf5',
  208. 'size_bytes': 208844028,
  209. 'generation': 1722663994756449,
  210. 'condition': 'host_os == "win"',
  211. },
  212. ],
  213. },
  214. }
  215. '''
  216. result = roll_downstream_gcs_deps.copy_packages(
  217. source_deps, destination_deps, ['src/third_party/rust-toolchain'],
  218. ['third_party/rust-toolchain'])
  219. self.assertEqual(result, expected_deps)
  220. with self.assertRaises(Exception):
  221. # no destination_package match, so expect a failure.
  222. roll_downstream_gcs_deps.copy_packages(
  223. source_deps, destination_deps,
  224. ['src/third_party/rust-toolchain'],
  225. ['src/third_party/rust-toolchain'])
  226. if __name__ == '__main__':
  227. level = logging.DEBUG if '-v' in sys.argv else logging.FATAL
  228. logging.basicConfig(level=level,
  229. format='%(asctime).19s %(levelname)s %(filename)s:'
  230. '%(lineno)s %(message)s')
  231. unittest.main()