Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The LUCI Authors. All rights reserved. | 2 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 # pylint: disable=W0212,W0223,W0231,W0613 | 6 # pylint: disable=W0212,W0223,W0231,W0613 |
| 7 | 7 |
| 8 import base64 | 8 import base64 |
| 9 import collections | 9 import collections |
| 10 import hashlib | 10 import hashlib |
| (...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 self.expected_requests(requests) | 1023 self.expected_requests(requests) |
| 1024 self.assertEqual(0, isolateserver.main(cmd)) | 1024 self.assertEqual(0, isolateserver.main(cmd)) |
| 1025 expected = dict( | 1025 expected = dict( |
| 1026 (os.path.join(self.tempdir, k), v) for k, v in files.iteritems()) | 1026 (os.path.join(self.tempdir, k), v) for k, v in files.iteritems()) |
| 1027 self.assertEqual(expected, actual) | 1027 self.assertEqual(expected, actual) |
| 1028 expected_stdout = ( | 1028 expected_stdout = ( |
| 1029 'To run this test please run from the directory %s:\n Absurb command\n' | 1029 'To run this test please run from the directory %s:\n Absurb command\n' |
| 1030 % os.path.join(self.tempdir, 'a')) | 1030 % os.path.join(self.tempdir, 'a')) |
| 1031 self.checkOutput(expected_stdout, '') | 1031 self.checkOutput(expected_stdout, '') |
| 1032 | 1032 |
| 1033 def test_download_isolated_archive(self): | |
| 1034 # Test downloading an isolated tree. | |
| 1035 actual = {} | |
| 1036 def putfile_mock( | |
| 1037 srcfileobj, dstpath, file_mode=None, size=-1, use_symlink=False): | |
| 1038 actual[dstpath] = srcfileobj.read(size) | |
| 1039 self.mock(isolateserver, 'putfile', putfile_mock) | |
| 1040 self.mock(os, 'makedirs', lambda _: None) | |
| 1041 server = 'http://example.com' | |
| 1042 | |
| 1043 files = { | |
| 1044 os.path.join('a', 'foo'): 'Content', | |
| 1045 'b': 'More content', | |
| 1046 'c': 'Even more content!', | |
| 1047 } | |
| 1048 | |
| 1049 archive = ( | |
| 1050 # ar file header | |
| 1051 '!<arch>\n' | |
| 1052 # File 1 ------------------------- | |
| 1053 # (16 bytes) filename len | |
| 1054 '#1/5 ' | |
| 1055 # file metadata | |
| 1056 '1447140471 1000 1000 100640 ' | |
| 1057 # (10 bytes) Data size | |
| 1058 '12 ' | |
| 1059 # (2 bytes) File magic | |
| 1060 '\x60\n' | |
| 1061 # (5 bytes) File name | |
| 1062 'a/foo' | |
| 1063 # (7 bytes) File data | |
| 1064 'Content' | |
| 1065 # File 2 ------------------------- | |
| 1066 # (16 bytes) filename | |
| 1067 'b ' | |
| 1068 # file metadata | |
| 1069 '1447140471 1000 1000 100640 ' | |
| 1070 # (12 bytes) Data size | |
| 1071 '12 ' | |
| 1072 # (2 bytes) File magic | |
| 1073 '\x60\n' | |
| 1074 # (12 bytes) File data | |
| 1075 'More content' | |
| 1076 '') | |
| 1077 | |
| 1078 isolated = { | |
| 1079 'command': ['Absurb', 'command'], | |
| 1080 'relative_cwd': 'a', | |
| 1081 'files': { | |
| 1082 'archive1': { | |
| 1083 'h': isolateserver_mock.hash_content(archive), | |
| 1084 's': len(archive), | |
| 1085 't': 'ar', | |
| 1086 }, | |
| 1087 'c': { | |
| 1088 'h': isolateserver_mock.hash_content(files['c']), | |
| 1089 's': len(files['c']), | |
| 1090 }, | |
| 1091 }, | |
| 1092 'version': isolated_format.ISOLATED_FILE_VERSION, | |
| 1093 } | |
| 1094 isolated_data = json.dumps(isolated, sort_keys=True, separators=(',',':')) | |
| 1095 isolated_hash = isolateserver_mock.hash_content(isolated_data) | |
| 1096 requests = [ | |
| 1097 (isolated['files']['archive1']['h'], archive), | |
| 1098 (isolated['files']['c']['h'], files['c']), | |
| 1099 ] | |
| 1100 requests.append((isolated_hash, isolated_data)) | |
| 1101 requests = [ | |
| 1102 ( | |
| 1103 server + '/_ah/api/isolateservice/v1/retrieve', | |
| 1104 { | |
| 1105 'data': { | |
| 1106 'digest': h.encode('utf-8'), | |
| 1107 'namespace': { | |
| 1108 'namespace': 'default-gzip', | |
| 1109 'digest_hash': 'sha-1', | |
| 1110 'compression': 'flate', | |
| 1111 }, | |
| 1112 'offset': 0, | |
| 1113 }, | |
| 1114 'read_timeout': 60, | |
| 1115 }, | |
| 1116 {'content': base64.b64encode(zlib.compress(v))}, | |
| 1117 ) for h, v in requests | |
| 1118 ] | |
| 1119 cmd = [ | |
| 1120 'download', | |
| 1121 '--isolate-server', server, | |
| 1122 '--target', self.tempdir, | |
| 1123 '--isolated', isolated_hash, | |
| 1124 ] | |
| 1125 self.expected_requests(requests) | |
| 1126 self.assertEqual(0, isolateserver.main(cmd)) | |
| 1127 expected = dict( | |
| 1128 (os.path.join(self.tempdir, k), v) for k, v in files.iteritems()) | |
| 1129 self.assertEqual(expected, actual) | |
| 1130 expected_stdout = ( | |
| 1131 'To run this test please run from the directory %s:\n Absurb command\n' | |
| 1132 % os.path.join(self.tempdir, 'a')) | |
| 1133 self.checkOutput(expected_stdout, '') | |
| 1134 | |
|
M-A Ruel
2016/07/28 16:46:11
you added one line too much.
| |
| 1033 | 1135 |
| 1136 | |
| 1034 def get_storage(_isolate_server, namespace): | 1137 def get_storage(_isolate_server, namespace): |
| 1035 class StorageFake(object): | 1138 class StorageFake(object): |
| 1036 def __enter__(self, *_): | 1139 def __enter__(self, *_): |
| 1037 return self | 1140 return self |
| 1038 | 1141 |
| 1039 def __exit__(self, *_): | 1142 def __exit__(self, *_): |
| 1040 pass | 1143 pass |
| 1041 | 1144 |
| 1042 @property | 1145 @property |
| 1043 def hash_algo(self): # pylint: disable=R0201 | 1146 def hash_algo(self): # pylint: disable=R0201 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1257 | 1360 |
| 1258 | 1361 |
| 1259 if __name__ == '__main__': | 1362 if __name__ == '__main__': |
| 1260 fix_encoding.fix_encoding() | 1363 fix_encoding.fix_encoding() |
| 1261 if '-v' in sys.argv: | 1364 if '-v' in sys.argv: |
| 1262 unittest.TestCase.maxDiff = None | 1365 unittest.TestCase.maxDiff = None |
| 1263 logging.basicConfig( | 1366 logging.basicConfig( |
| 1264 level=(logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)) | 1367 level=(logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)) |
| 1265 clear_env_vars() | 1368 clear_env_vars() |
| 1266 unittest.main() | 1369 unittest.main() |
| OLD | NEW |