Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Unified Diff: tests/download_from_google_storage_unittests.py

Issue 1252313005: Add verification to downloaded files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« download_from_google_storage.py ('K') | « download_from_google_storage.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/download_from_google_storage_unittests.py
diff --git a/tests/download_from_google_storage_unittests.py b/tests/download_from_google_storage_unittests.py
index a8af63b0c74cbf9913c396103b8c04a3a0f230c8..8407370c6491abe035d48e73f1f126bcd80047b2 100755
--- a/tests/download_from_google_storage_unittests.py
+++ b/tests/download_from_google_storage_unittests.py
@@ -36,8 +36,8 @@ class GsutilMock(object):
self.history = []
self.lock = threading.Lock()
- def add_expected(self, return_code, out, err):
- self.expected.append((return_code, out, err))
+ def add_expected(self, return_code, out, err, fn=None):
+ self.expected.append((return_code, out, err, fn))
def append_history(self, method, args):
self.history.append((method, args))
@@ -46,7 +46,10 @@ class GsutilMock(object):
with self.lock:
self.append_history('call', args)
if self.expected:
- return self.expected.pop(0)[0]
+ code, _out, _err, fn = self.expected.pop(0)
+ if fn:
+ fn()
+ return code
else:
return 0
@@ -54,7 +57,10 @@ class GsutilMock(object):
with self.lock:
self.append_history('check_call', args)
if self.expected:
- return self.expected.pop(0)
+ code, out, err, fn = self.expected.pop(0)
+ if fn:
+ fn()
+ return code, out, err
else:
return (0, '', '')
@@ -257,6 +263,33 @@ class DownloadTests(unittest.TestCase):
self.assertEqual(self.gsutil.history, expected_calls)
self.assertEqual(code, 101)
+ def test_corrupt_download(self):
+ q = Queue.Queue()
+ out_q = Queue.Queue()
+ ret_codes = Queue.Queue()
+ tmp_dir = tempfile.mkdtemp()
+ sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f'
+ input_filename = '%s/%s' % (self.base_url, sha1_hash)
+ output_filename = os.path.join(tmp_dir, 'lorem_ipsum.txt')
+ q.put(('7871c8e24da15bad8b0be2c36edc9dc77e37727f', output_filename))
+ q.put((None, None))
+ def _write_bad_file():
+ with open(output_filename, 'w') as f:
+ f.write('foobar')
+ self.gsutil.add_expected(0, '', '')
+ self.gsutil.add_expected(0, '', '', _write_bad_file)
+ download_from_google_storage._downloader_worker_thread(
+ 1, q, True, self.base_url, self.gsutil, out_q, ret_codes, True)
+ self.assertTrue(q.empty())
+ msg = ('1> ERROR remote sha1 (%s) does not match expected sha1 (%s).' %
+ ('8843d7f92416211de9ebb963ff4ce28125932878', sha1_hash))
+ self.assertEquals(out_q.get(), '1> Downloading %s...' % output_filename)
+ self.assertEquals(out_q.get(), msg)
+ self.assertEquals(ret_codes.get(), (20, msg))
+ self.assertTrue(out_q.empty())
+ self.assertTrue(ret_codes.empty())
+
+
def test_download_directory_no_recursive_non_force(self):
sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f'
input_filename = '%s/%s' % (self.base_url, sha1_hash)
« download_from_google_storage.py ('K') | « download_from_google_storage.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698