| 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=R0201 | 6 # pylint: disable=R0201 |
| 7 | 7 |
| 8 import StringIO | 8 import StringIO |
| 9 import base64 | 9 import base64 |
| 10 import functools | 10 import functools |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 isolated_hash, | 201 isolated_hash, |
| 202 StorageFake(files), | 202 StorageFake(files), |
| 203 isolateserver.MemoryCache(), | 203 isolateserver.MemoryCache(), |
| 204 False, | 204 False, |
| 205 None, | 205 None, |
| 206 None, | 206 None, |
| 207 None, | 207 None, |
| 208 None, | 208 None, |
| 209 None, | 209 None, |
| 210 None, | 210 None, |
| 211 None, | 211 lambda run_dir: None) |
| 212 None) | |
| 213 self.assertEqual(0, ret) | 212 self.assertEqual(0, ret) |
| 214 return make_tree_call | 213 return make_tree_call |
| 215 | 214 |
| 216 def test_run_tha_test_naked(self): | 215 def test_run_tha_test_naked(self): |
| 217 isolated = json_dumps({'command': ['invalid', 'command']}) | 216 isolated = json_dumps({'command': ['invalid', 'command']}) |
| 218 isolated_hash = isolateserver_mock.hash_content(isolated) | 217 isolated_hash = isolateserver_mock.hash_content(isolated) |
| 219 files = {isolated_hash:isolated} | 218 files = {isolated_hash:isolated} |
| 220 make_tree_call = self._run_tha_test(isolated_hash, files) | 219 make_tree_call = self._run_tha_test(isolated_hash, files) |
| 221 self.assertEqual( | 220 self.assertEqual( |
| 222 [ | 221 [ |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 'world', | 327 'world', |
| 329 ] | 328 ] |
| 330 ret = run_isolated.main(cmd) | 329 ret = run_isolated.main(cmd) |
| 331 self.assertEqual(1, ret) | 330 self.assertEqual(1, ret) |
| 332 self.assertEqual(1, len(self.popen_calls)) | 331 self.assertEqual(1, len(self.popen_calls)) |
| 333 self.assertEqual( | 332 self.assertEqual( |
| 334 [([u'/bin/echo', u'hello', u'world'], {'detached': True})], | 333 [([u'/bin/echo', u'hello', u'world'], {'detached': True})], |
| 335 self.popen_calls) | 334 self.popen_calls) |
| 336 | 335 |
| 337 def test_main_naked_with_packages(self): | 336 def test_main_naked_with_packages(self): |
| 338 cmd = [ | 337 packages_fd, packages_path = tempfile.mkstemp(prefix=u'packages') |
| 339 '--no-log', | 338 try: |
| 340 '--cipd-package', 'infra/tools/echo/${platform}:latest', | 339 try: |
| 341 '--cipd-server', self.cipd_server.url, | 340 os.write(packages_fd, json.dumps({ |
| 342 '${CIPD_PATH}/echo', | 341 'packages': [ |
| 343 'hello', | 342 { |
| 344 'world', | 343 'path': 'bin', |
| 345 ] | 344 'package_name': 'infra/tools/echo/${platform}', |
| 346 ret = run_isolated.main(cmd) | 345 'version': 'latest', |
| 347 self.assertEqual(0, ret) | 346 }, |
| 347 { |
| 348 'path': '.', |
| 349 'package_name': 'infra/data/x', |
| 350 'version': 'latest', |
| 351 }, |
| 352 { |
| 353 'package_name': 'infra/data/y', |
| 354 'version': 'canary', |
| 355 }, |
| 356 ] |
| 357 })) |
| 358 finally: |
| 359 os.close(packages_fd) |
| 348 | 360 |
| 349 self.assertEqual(2, len(self.popen_calls)) | 361 cmd = [ |
| 362 '--no-log', |
| 363 '--cipd-package-list', packages_path, |
| 364 '--cipd-server', self.cipd_server.url, |
| 365 'bin/echo${EXECUTABLE_SUFFIX}', |
| 366 'hello', |
| 367 'world', |
| 368 ] |
| 369 ret = run_isolated.main(cmd) |
| 370 self.assertEqual(0, ret) |
| 350 | 371 |
| 351 # Test cipd-ensure command. | 372 print self.popen_calls |
| 352 cipd_ensure_cmd, _ = self.popen_calls[0] | 373 self.assertEqual(3, len(self.popen_calls)) |
| 353 self.assertEqual(cipd_ensure_cmd[:2], [ | |
| 354 os.path.abspath('cipd_cache/cipd' + cipd.EXECUTABLE_SUFFIX), | |
| 355 'ensure', | |
| 356 ]) | |
| 357 cache_dir_index = cipd_ensure_cmd.index('-cache-dir') | |
| 358 self.assertEqual( | |
| 359 cipd_ensure_cmd[cache_dir_index+1], | |
| 360 os.path.abspath('cipd_cache/cipd_internal')) | |
| 361 | 374 |
| 362 # Test cipd cache. | 375 # Test cipd-ensure command for installing packages. |
| 363 version_file = unicode(os.path.abspath( | 376 for cipd_ensure_cmd, _ in self.popen_calls[0:2]: |
| 364 'cipd_cache/versions/1481d0a0ceb16ea4672fed76a0710306eb9f3a33')) | 377 self.assertEqual(cipd_ensure_cmd[:2], [ |
| 365 self.assertTrue(fs.isfile(version_file)) | 378 os.path.abspath('cipd_cache/cipd' + cipd.EXECUTABLE_SUFFIX), |
| 366 with open(version_file) as f: | 379 'ensure', |
| 367 self.assertEqual(f.read(), 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') | 380 ]) |
| 381 cache_dir_index = cipd_ensure_cmd.index('-cache-dir') |
| 382 self.assertEqual( |
| 383 cipd_ensure_cmd[cache_dir_index+1], |
| 384 os.path.abspath('cipd_cache/cipd_internal')) |
| 368 | 385 |
| 369 client_binary_file = unicode(os.path.abspath( | 386 # Test cipd cache. |
| 370 'cipd_cache/clients/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')) | 387 version_file = unicode(os.path.abspath( |
| 371 self.assertTrue(fs.isfile(client_binary_file)) | 388 'cipd_cache/versions/1481d0a0ceb16ea4672fed76a0710306eb9f3a33')) |
| 389 self.assertTrue(fs.isfile(version_file)) |
| 390 with open(version_file) as f: |
| 391 self.assertEqual(f.read(), 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') |
| 372 | 392 |
| 373 # Test echo call. | 393 client_binary_file = unicode(os.path.abspath( |
| 374 echo_cmd, _ = self.popen_calls[1] | 394 'cipd_cache/clients/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')) |
| 375 self.assertTrue(echo_cmd[0].endswith('cipd_site_root/echo')) | 395 self.assertTrue(fs.isfile(client_binary_file)) |
| 376 self.assertEqual(echo_cmd[1:], ['hello', 'world']) | 396 |
| 397 # Test echo call. |
| 398 echo_cmd, _ = self.popen_calls[2] |
| 399 self.assertTrue(echo_cmd[0].endswith( |
| 400 '/bin/echo' + cipd.EXECUTABLE_SUFFIX)) |
| 401 self.assertEqual(echo_cmd[1:], ['hello', 'world']) |
| 402 finally: |
| 403 os.remove(packages_path) |
| 377 | 404 |
| 378 def test_modified_cwd(self): | 405 def test_modified_cwd(self): |
| 379 isolated = json_dumps({ | 406 isolated = json_dumps({ |
| 380 'command': ['../out/some.exe', 'arg'], | 407 'command': ['../out/some.exe', 'arg'], |
| 381 'relative_cwd': 'some', | 408 'relative_cwd': 'some', |
| 382 }) | 409 }) |
| 383 isolated_hash = isolateserver_mock.hash_content(isolated) | 410 isolated_hash = isolateserver_mock.hash_content(isolated) |
| 384 files = {isolated_hash:isolated} | 411 files = {isolated_hash:isolated} |
| 385 _ = self._run_tha_test(isolated_hash, files) | 412 _ = self._run_tha_test(isolated_hash, files) |
| 386 self.assertEqual(1, len(self.popen_calls)) | 413 self.assertEqual(1, len(self.popen_calls)) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 None, | 474 None, |
| 448 isolated_hash, | 475 isolated_hash, |
| 449 store, | 476 store, |
| 450 isolateserver.MemoryCache(), | 477 isolateserver.MemoryCache(), |
| 451 False, | 478 False, |
| 452 None, | 479 None, |
| 453 None, | 480 None, |
| 454 None, | 481 None, |
| 455 None, | 482 None, |
| 456 None, | 483 None, |
| 457 [], | |
| 458 None, | 484 None, |
| 459 None) | 485 lambda run_dir: None) |
| 460 self.assertEqual(0, ret) | 486 self.assertEqual(0, ret) |
| 461 | 487 |
| 462 # It uploaded back. Assert the store has a new item containing foo. | 488 # It uploaded back. Assert the store has a new item containing foo. |
| 463 hashes = {isolated_hash, script_hash} | 489 hashes = {isolated_hash, script_hash} |
| 464 output_hash = isolateserver_mock.hash_content('bar') | 490 output_hash = isolateserver_mock.hash_content('bar') |
| 465 hashes.add(output_hash) | 491 hashes.add(output_hash) |
| 466 isolated = { | 492 isolated = { |
| 467 'algo': 'sha-1', | 493 'algo': 'sha-1', |
| 468 'files': { | 494 'files': { |
| 469 'foo': { | 495 'foo': { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 self.assertEqual(expected, actual) | 629 self.assertEqual(expected, actual) |
| 604 | 630 |
| 605 | 631 |
| 606 if __name__ == '__main__': | 632 if __name__ == '__main__': |
| 607 fix_encoding.fix_encoding() | 633 fix_encoding.fix_encoding() |
| 608 if '-v' in sys.argv: | 634 if '-v' in sys.argv: |
| 609 unittest.TestCase.maxDiff = None | 635 unittest.TestCase.maxDiff = None |
| 610 logging.basicConfig( | 636 logging.basicConfig( |
| 611 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) | 637 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) |
| 612 unittest.main() | 638 unittest.main() |
| OLD | NEW |