| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import copy | 6 import copy |
| 7 import datetime | 7 import datetime |
| 8 import hashlib |
| 8 import os | 9 import os |
| 9 import posixpath | 10 import posixpath |
| 10 import subprocess | 11 import subprocess |
| 11 import sys | 12 import sys |
| 13 import tempfile |
| 12 import unittest | 14 import unittest |
| 13 import urlparse | 15 import urlparse |
| 14 | 16 |
| 15 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 17 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 16 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR) | 18 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR) |
| 17 | 19 |
| 18 sys.path.append(BUILD_TOOLS_DIR) | 20 sys.path.append(BUILD_TOOLS_DIR) |
| 19 import manifest_util | 21 import manifest_util |
| 20 import update_nacl_manifest | 22 import update_nacl_manifest |
| 21 from update_nacl_manifest import CANARY_BUNDLE_NAME | 23 from update_nacl_manifest import CANARY_BUNDLE_NAME |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 new_bundle.AddArchive(archive) | 153 new_bundle.AddArchive(archive) |
| 152 self[path + '.json'] = new_bundle.GetDataAsString() | 154 self[path + '.json'] = new_bundle.GetDataAsString() |
| 153 | 155 |
| 154 | 156 |
| 155 class TestDelegate(update_nacl_manifest.Delegate): | 157 class TestDelegate(update_nacl_manifest.Delegate): |
| 156 def __init__(self, manifest, history, files, version_mapping): | 158 def __init__(self, manifest, history, files, version_mapping): |
| 157 self.manifest = manifest | 159 self.manifest = manifest |
| 158 self.history = history | 160 self.history = history |
| 159 self.files = files | 161 self.files = files |
| 160 self.version_mapping = version_mapping | 162 self.version_mapping = version_mapping |
| 163 self.dryrun = 0 |
| 161 | 164 |
| 162 def GetRepoManifest(self): | 165 def GetRepoManifest(self): |
| 163 return self.manifest | 166 return self.manifest |
| 164 | 167 |
| 165 def GetHistory(self): | 168 def GetHistory(self): |
| 166 return self.history | 169 return self.history |
| 167 | 170 |
| 168 def GetTrunkRevision(self, version): | 171 def GetTrunkRevision(self, version): |
| 169 return self.version_mapping[version] | 172 return self.version_mapping[version] |
| 170 | 173 |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 archive_url = bundle.GetArchive('mac').url | 509 archive_url = bundle.GetArchive('mac').url |
| 507 bundle.GetArchive('mac').url = archive_url.replace('.tar', '') | 510 bundle.GetArchive('mac').url = archive_url.replace('.tar', '') |
| 508 self.files.Add(bundle) | 511 self.files.Add(bundle) |
| 509 self._MakeDelegate() | 512 self._MakeDelegate() |
| 510 self._Run(OS_MLW) | 513 self._Run(OS_MLW) |
| 511 self._ReadUploadedManifest() | 514 self._ReadUploadedManifest() |
| 512 self._AssertUploadedManifestHasBundle(bundle, BETA) | 515 self._AssertUploadedManifestHasBundle(bundle, BETA) |
| 513 self.assertEqual(len(self.uploaded_manifest.GetBundles()), 1) | 516 self.assertEqual(len(self.uploaded_manifest.GetBundles()), 1) |
| 514 | 517 |
| 515 | 518 |
| 516 def main(): | 519 class TestUpdateVitals(unittest.TestCase): |
| 517 suite = unittest.defaultTestLoader.loadTestsFromModule(sys.modules[__name__]) | 520 def setUp(self): |
| 518 result = unittest.TextTestRunner(verbosity=2).run(suite) | 521 f = tempfile.NamedTemporaryFile('w', prefix="test_update_nacl_manifest") |
| 522 self.test_file = f.name |
| 523 f.close() |
| 524 test_data = "Some test data\n" |
| 525 self.sha1 = hashlib.sha1(test_data).hexdigest() |
| 526 with open(self.test_file, 'w') as f: |
| 527 f.write(test_data) |
| 519 | 528 |
| 520 return int(not result.wasSuccessful()) | 529 def tearDown(self): |
| 530 os.remove(self.test_file) |
| 531 |
| 532 def testUpdateVitals(self): |
| 533 archive = manifest_util.Archive(manifest_util.GetHostOS()) |
| 534 archive.url = 'file://%s' % os.path.abspath(self.test_file) |
| 535 bundle = MakeBundle(18) |
| 536 bundle.AddArchive(archive) |
| 537 manifest = MakeManifest(bundle) |
| 538 archive = manifest.GetBundles()[0]['archives'][0] |
| 539 |
| 540 self.assertTrue('size' not in archive) |
| 541 self.assertTrue('checksum' not in archive) |
| 542 |
| 543 manifest.Validate() |
| 544 |
| 545 self.assertEqual(archive['size'], 15) |
| 546 self.assertEqual(archive['checksum']['sha1'], self.sha1) |
| 547 |
| 521 | 548 |
| 522 if __name__ == '__main__': | 549 if __name__ == '__main__': |
| 523 sys.exit(main()) | 550 unittest.main() |
| OLD | NEW |