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

Side by Side Diff: client/tests/run_isolated_smoke_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, 4 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2012 The LUCI Authors. All rights reserved. 2 # Copyright 2012 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 import json 6 import json
7 import logging 7 import logging
8 import os 8 import os
9 import subprocess 9 import subprocess
10 import sys 10 import sys
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 import os, sys 60 import os, sys
61 prefix = u'\\\\\\\\?\\\\' if sys.platform == 'win32' else u'' 61 prefix = u'\\\\\\\\?\\\\' if sys.platform == 'win32' else u''
62 path = os.path.join(os.getcwd().decode( 62 path = os.path.join(os.getcwd().decode(
63 sys.getfilesystemencoding()), 'a' * 200, 'b' * 200) 63 sys.getfilesystemencoding()), 'a' * 200, 'b' * 200)
64 with open(prefix + path, 'rb') as f: 64 with open(prefix + path, 'rb') as f:
65 actual = f.read() 65 actual = f.read()
66 if actual != 'File1\\n': 66 if actual != 'File1\\n':
67 print >> sys.stderr, 'Unexpected content: %s' % actual 67 print >> sys.stderr, 'Unexpected content: %s' % actual
68 sys.exit(1) 68 sys.exit(1)
69 print('Success')""", 69 print('Success')""",
70 'archive': (
71 '!<arch>\n'
72 '#1/5 '
73 '1447140471 1000 1000 100640 '
74 '12 '
75 '\x60\n'
76 'a/foo'
77 'Content'
78 'b '
79 '1447140471 1000 1000 100640 '
80 '12 '
81 '\x60\n'
82 'More content'),
83 'archive_files.py': """if True:
84 import os, sys
85 ROOT_DIR = os.path.dirname(os.path.abspath(
86 __file__.decode(sys.getfilesystemencoding())))
87 expected = ['a', 'archive_files.py', 'b']
88 actual = sorted(os.listdir(ROOT_DIR))
89 if expected != actual:
90 print >> sys.stderr, 'Expected list doesn\\'t match:'
91 print >> sys.stderr, '%s\\n%s' % (','.join(expected), ','.join(actual))
92 sys.exit(1)
93 expected = ['foo']
94 actual = sorted(os.listdir(os.path.join(ROOT_DIR, 'a')))
95 if expected != actual:
96 print >> sys.stderr, 'Expected list doesn\\'t match:'
97 print >> sys.stderr, '%s\\n%s' % (','.join(expected), ','.join(actual))
98 sys.exit(2)
99 # Check that a/foo has right contents.
100 with open(os.path.join(ROOT_DIR, 'a/foo'), 'rb') as f:
101 d = f.read()
102 if d != 'Content':
103 print >> sys.stderr, 'a/foo contained %r' % d
104 sys.exit(3)
105 # Check that b has right contents.
106 with open(os.path.join(ROOT_DIR, 'b'), 'rb') as f:
107 d = f.read()
108 if d != 'More content':
109 print >> sys.stderr, 'b contained %r' % d
110 sys.exit(4)
111 print('Success')""",
70 } 112 }
71 113
72 114
73 def file_meta(filename): 115 def file_meta(filename):
74 return { 116 return {
75 'h': isolateserver_mock.hash_content(CONTENTS[filename]), 117 'h': isolateserver_mock.hash_content(CONTENTS[filename]),
76 's': len(CONTENTS[filename]), 118 's': len(CONTENTS[filename]),
77 } 119 }
78 120
79 121
(...skipping 23 matching lines...) Expand all
103 145
104 CONTENTS['manifest2.isolated'] = json.dumps( 146 CONTENTS['manifest2.isolated'] = json.dumps(
105 { 147 {
106 'files': {'file2.txt': file_meta('file2.txt')}, 148 'files': {'file2.txt': file_meta('file2.txt')},
107 'includes': [ 149 'includes': [
108 isolateserver_mock.hash_content(CONTENTS['manifest1.isolated']), 150 isolateserver_mock.hash_content(CONTENTS['manifest1.isolated']),
109 ], 151 ],
110 }) 152 })
111 153
112 154
155 CONTENTS['archive.isolated'] = json.dumps(
156 {
157 'command': ['python', 'archive_files.py'],
158 'files': {
159 'archive': {
160 'h': isolateserver_mock.hash_content(CONTENTS['archive']),
161 's': len(CONTENTS['archive']),
162 't': 'ar',
163 },
164 'archive_files.py': file_meta('archive_files.py'),
165 },
166 })
167
168
113 CONTENTS['max_path.isolated'] = json.dumps( 169 CONTENTS['max_path.isolated'] = json.dumps(
114 { 170 {
115 'command': ['python', 'max_path.py'], 171 'command': ['python', 'max_path.py'],
116 'files': { 172 'files': {
117 'a' * 200 + '/' + 'b' * 200: file_meta('file1.txt'), 173 'a' * 200 + '/' + 'b' * 200: file_meta('file1.txt'),
118 'max_path.py': file_meta('max_path.py'), 174 'max_path.py': file_meta('max_path.py'),
119 }, 175 },
120 }) 176 })
121 177
122 178
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 self._store('repeated_files.py'), 382 self._store('repeated_files.py'),
327 self._store('repeated_files.isolated'), 383 self._store('repeated_files.isolated'),
328 ] 384 ]
329 out, err, returncode = self._run(self._cmd_args(isolated_hash)) 385 out, err, returncode = self._run(self._cmd_args(isolated_hash))
330 self.assertEqual('', err) 386 self.assertEqual('', err)
331 self.assertEqual('Success\n', out) 387 self.assertEqual('Success\n', out)
332 self.assertEqual(0, returncode) 388 self.assertEqual(0, returncode)
333 actual = list_files_tree(self.cache) 389 actual = list_files_tree(self.cache)
334 self.assertEqual(sorted(expected), actual) 390 self.assertEqual(sorted(expected), actual)
335 391
392 def test_archive(self):
393 # Loads an .isolated that includes an ar archive.
394 isolated_hash = self._store('archive.isolated')
395 expected = [
396 'state.json',
397 isolated_hash,
398 self._store('archive'),
399 self._store('archive_files.py'),
400 ]
401 out, err, returncode = self._run(self._cmd_args(isolated_hash))
402 self.assertEqual('', err)
403 self.assertEqual('Success\n', out)
404 self.assertEqual(0, returncode)
405 actual = list_files_tree(self.cache)
406 self.assertEqual(sorted(expected), actual)
407
336 def _test_corruption_common(self, new_content): 408 def _test_corruption_common(self, new_content):
337 isolated_hash = self._store('file_with_size.isolated') 409 isolated_hash = self._store('file_with_size.isolated')
338 file1_hash = self._store('file1.txt') 410 file1_hash = self._store('file1.txt')
339 411
340 # Run the test once to generate the cache. 412 # Run the test once to generate the cache.
341 _out, _err, returncode = self._run(self._cmd_args(isolated_hash)) 413 _out, _err, returncode = self._run(self._cmd_args(isolated_hash))
342 self.assertEqual(0, returncode) 414 self.assertEqual(0, returncode)
343 expected = { 415 expected = {
344 '.': (040700, 040700, 040777), 416 '.': (040700, 040700, 040777),
345 'state.json': (0100600, 0100600, 0100666), 417 'state.json': (0100600, 0100600, 0100666),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 cached_file_path = self._test_corruption_common( 458 cached_file_path = self._test_corruption_common(
387 CONTENTS['file1.txt'][:-1] + ' ') 459 CONTENTS['file1.txt'][:-1] + ' ')
388 # TODO(maruel): This corruption is NOT detected. 460 # TODO(maruel): This corruption is NOT detected.
389 # This needs to be fixed. 461 # This needs to be fixed.
390 self.assertNotEqual(CONTENTS['file1.txt'], read_content(cached_file_path)) 462 self.assertNotEqual(CONTENTS['file1.txt'], read_content(cached_file_path))
391 463
392 464
393 if __name__ == '__main__': 465 if __name__ == '__main__':
394 fix_encoding.fix_encoding() 466 fix_encoding.fix_encoding()
395 test_utils.main() 467 test_utils.main()
OLDNEW
« client/tests/isolateserver_test.py ('K') | « client/tests/isolateserver_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698