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

Unified Diff: client/tests/isolateserver_test.py

Issue 2060983006: luci-py/isolateserver.py: Add archive support when downloading. (Closed) Base URL: https://github.com/luci/luci-py.git@master
Patch Set: Update hashes as version has changed. Created 4 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
« no previous file with comments | « client/run_isolated.py ('k') | client/tests/run_isolated_smoke_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/tests/isolateserver_test.py
diff --git a/client/tests/isolateserver_test.py b/client/tests/isolateserver_test.py
index 2435a699d86e2305d8280c3b18774e8e4a774965..97b5bdf1f6e4ee9ebf040a8d1f0b4f4f5e935de6 100755
--- a/client/tests/isolateserver_test.py
+++ b/client/tests/isolateserver_test.py
@@ -1030,6 +1030,109 @@ class IsolateServerDownloadTest(TestCase):
% os.path.join(self.tempdir, 'a'))
self.checkOutput(expected_stdout, '')
+ def test_download_isolated_archive(self):
+ # Test downloading an isolated tree.
+ actual = {}
+ def putfile_mock(
+ srcfileobj, dstpath, file_mode=None, size=-1, use_symlink=False):
+ actual[dstpath] = srcfileobj.read(size)
+ self.mock(isolateserver, 'putfile', putfile_mock)
+ self.mock(os, 'makedirs', lambda _: None)
+ server = 'http://example.com'
+
+ files = {
+ os.path.join('a', 'foo'): 'Content',
+ 'b': 'More content',
+ 'c': 'Even more content!',
+ }
+
+ archive = (
+ # ar file header
+ '!<arch>\n'
+ # File 1 -------------------------
+ # (16 bytes) filename len
+ '#1/5 '
+ # file metadata
+ '1447140471 1000 1000 100640 '
+ # (10 bytes) Data size
+ '12 '
+ # (2 bytes) File magic
+ '\x60\n'
+ # (5 bytes) File name
+ 'a/foo'
+ # (7 bytes) File data
+ 'Content'
+ # File 2 -------------------------
+ # (16 bytes) filename
+ 'b '
+ # file metadata
+ '1447140471 1000 1000 100640 '
+ # (12 bytes) Data size
+ '12 '
+ # (2 bytes) File magic
+ '\x60\n'
+ # (12 bytes) File data
+ 'More content'
+ '')
+
+ isolated = {
+ 'command': ['Absurb', 'command'],
+ 'relative_cwd': 'a',
+ 'files': {
+ 'archive1': {
+ 'h': isolateserver_mock.hash_content(archive),
+ 's': len(archive),
+ 't': 'ar',
+ },
+ 'c': {
+ 'h': isolateserver_mock.hash_content(files['c']),
+ 's': len(files['c']),
+ },
+ },
+ 'version': isolated_format.ISOLATED_FILE_VERSION,
+ }
+ isolated_data = json.dumps(isolated, sort_keys=True, separators=(',',':'))
+ isolated_hash = isolateserver_mock.hash_content(isolated_data)
+ requests = [
+ (isolated['files']['archive1']['h'], archive),
+ (isolated['files']['c']['h'], files['c']),
+ ]
+ requests.append((isolated_hash, isolated_data))
+ requests = [
+ (
+ server + '/_ah/api/isolateservice/v1/retrieve',
+ {
+ 'data': {
+ 'digest': h.encode('utf-8'),
+ 'namespace': {
+ 'namespace': 'default-gzip',
+ 'digest_hash': 'sha-1',
+ 'compression': 'flate',
+ },
+ 'offset': 0,
+ },
+ 'read_timeout': 60,
+ },
+ {'content': base64.b64encode(zlib.compress(v))},
+ ) for h, v in requests
+ ]
+ cmd = [
+ 'download',
+ '--isolate-server', server,
+ '--target', self.tempdir,
+ '--isolated', isolated_hash,
+ ]
+ self.expected_requests(requests)
+ self.assertEqual(0, isolateserver.main(cmd))
+ expected = dict(
+ (os.path.join(self.tempdir, k), v) for k, v in files.iteritems())
+ self.assertEqual(expected, actual)
+ expected_stdout = (
+ 'To run this test please run from the directory %s:\n Absurb command\n'
+ % os.path.join(self.tempdir, 'a'))
+ self.checkOutput(expected_stdout, '')
+
M-A Ruel 2016/07/28 16:46:11 you added one line too much.
+
def get_storage(_isolate_server, namespace):
class StorageFake(object):
« no previous file with comments | « client/run_isolated.py ('k') | client/tests/run_isolated_smoke_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698