|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
#!/usr/bin/env vpython3
|
|
|
|
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
# found in the LICENSE file.
|
|
|
|
@ -71,7 +71,7 @@ class GsutilMock(object):
|
|
|
|
|
fn()
|
|
|
|
|
return code, out, err
|
|
|
|
|
else:
|
|
|
|
|
return (0, b'', b'')
|
|
|
|
|
return (0, '', '')
|
|
|
|
|
|
|
|
|
|
def check_call_with_retries(self, *args):
|
|
|
|
|
return self.check_call(*args)
|
|
|
|
@ -115,6 +115,8 @@ class GstoolsUnitTests(unittest.TestCase):
|
|
|
|
|
self.assertTrue(
|
|
|
|
|
download_from_google_storage._validate_tar_file(tar, tar_dir))
|
|
|
|
|
|
|
|
|
|
# os.symlink doesn't exist on Windows.
|
|
|
|
|
if sys.platform != 'win32':
|
|
|
|
|
# Test no links.
|
|
|
|
|
tar_dir_link = 'for_tar_link'
|
|
|
|
|
os.makedirs(tar_dir_link)
|
|
|
|
@ -124,7 +126,8 @@ class GstoolsUnitTests(unittest.TestCase):
|
|
|
|
|
with tarfile.open(tar_with_links, 'w:gz') as tar:
|
|
|
|
|
tar.add(link)
|
|
|
|
|
self.assertFalse(
|
|
|
|
|
download_from_google_storage._validate_tar_file(tar, tar_dir_link))
|
|
|
|
|
download_from_google_storage._validate_tar_file(
|
|
|
|
|
tar, tar_dir_link))
|
|
|
|
|
|
|
|
|
|
# Test not outside.
|
|
|
|
|
tar_dir_outside = 'outside_tar'
|
|
|
|
@ -158,8 +161,8 @@ class GstoolsUnitTests(unittest.TestCase):
|
|
|
|
|
gsutil = download_from_google_storage.Gsutil(GSUTIL_DEFAULT_PATH, None)
|
|
|
|
|
self.assertEqual(gsutil.path, GSUTIL_DEFAULT_PATH)
|
|
|
|
|
code, _, err = gsutil.check_call()
|
|
|
|
|
self.assertEqual(code, 0)
|
|
|
|
|
self.assertEqual(err, b'')
|
|
|
|
|
self.assertEqual(code, 0, err)
|
|
|
|
|
self.assertEqual(err, '')
|
|
|
|
|
|
|
|
|
|
def test_get_sha1(self):
|
|
|
|
|
lorem_ipsum = os.path.join(self.base_path, 'lorem_ipsum.txt')
|
|
|
|
@ -245,8 +248,8 @@ class DownloadTests(unittest.TestCase):
|
|
|
|
|
sha1_hash = self.lorem_ipsum_sha1
|
|
|
|
|
input_filename = '%s/%s' % (self.base_url, sha1_hash)
|
|
|
|
|
output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt')
|
|
|
|
|
self.gsutil.add_expected(0, b'', b'') # ls
|
|
|
|
|
self.gsutil.add_expected(0, b'', b'', lambda: shutil.copyfile(
|
|
|
|
|
self.gsutil.add_expected(0, '', '') # ls
|
|
|
|
|
self.gsutil.add_expected(0, '', '', lambda: shutil.copyfile(
|
|
|
|
|
self.lorem_ipsum, output_filename)) # cp
|
|
|
|
|
self.queue.put((sha1_hash, output_filename))
|
|
|
|
|
self.queue.put((None, None))
|
|
|
|
@ -329,7 +332,7 @@ class DownloadTests(unittest.TestCase):
|
|
|
|
|
self.queue.put((sha1_hash, output_filename))
|
|
|
|
|
self.queue.put((None, None))
|
|
|
|
|
stdout_queue = queue.Queue()
|
|
|
|
|
self.gsutil.add_expected(1, b'', b'') # Return error when 'ls' is called.
|
|
|
|
|
self.gsutil.add_expected(1, '', '') # Return error when 'ls' is called.
|
|
|
|
|
download_from_google_storage._downloader_worker_thread(
|
|
|
|
|
0, self.queue, False, self.base_url, self.gsutil,
|
|
|
|
|
stdout_queue, self.ret_codes, True, False)
|
|
|
|
@ -353,8 +356,8 @@ class DownloadTests(unittest.TestCase):
|
|
|
|
|
sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f'
|
|
|
|
|
input_filename = '%s/%s' % (self.base_url, sha1_hash)
|
|
|
|
|
output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt')
|
|
|
|
|
self.gsutil.add_expected(0, b'', b'') # ls
|
|
|
|
|
self.gsutil.add_expected(101, b'', b'Test error message.')
|
|
|
|
|
self.gsutil.add_expected(0, '', '') # ls
|
|
|
|
|
self.gsutil.add_expected(101, '', 'Test error message.')
|
|
|
|
|
code = download_from_google_storage.download_from_google_storage(
|
|
|
|
|
input_filename=sha1_hash,
|
|
|
|
|
base_url=self.base_url,
|
|
|
|
|