Chromium Code Reviews| 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): |