| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 self.assertEqual(1, ret) | 315 self.assertEqual(1, ret) |
| 316 self.assertEqual(1, len(self.popen_calls)) | 316 self.assertEqual(1, len(self.popen_calls)) |
| 317 self.assertEqual( | 317 self.assertEqual( |
| 318 [([self.temp_join(u'invalid'), u'command'], {'detached': True})], | 318 [([self.temp_join(u'invalid'), u'command'], {'detached': True})], |
| 319 self.popen_calls) | 319 self.popen_calls) |
| 320 | 320 |
| 321 def test_main_naked_without_isolated(self): | 321 def test_main_naked_without_isolated(self): |
| 322 self.mock_popen_with_oserr() | 322 self.mock_popen_with_oserr() |
| 323 cmd = [ | 323 cmd = [ |
| 324 '--no-log', | 324 '--no-log', |
| 325 '--cache', self.tempdir, |
| 325 '/bin/echo', | 326 '/bin/echo', |
| 326 'hello', | 327 'hello', |
| 327 'world', | 328 'world', |
| 328 ] | 329 ] |
| 329 ret = run_isolated.main(cmd) | 330 ret = run_isolated.main(cmd) |
| 330 self.assertEqual(1, ret) | 331 self.assertEqual(1, ret) |
| 331 self.assertEqual(1, len(self.popen_calls)) | 332 self.assertEqual(1, len(self.popen_calls)) |
| 332 self.assertEqual( | 333 self.assertEqual( |
| 333 [([u'/bin/echo', u'hello', u'world'], {'detached': True})], | 334 [([u'/bin/echo', u'hello', u'world'], {'detached': True})], |
| 334 self.popen_calls) | 335 self.popen_calls) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 351 }, | 352 }, |
| 352 { | 353 { |
| 353 'package_name': 'infra/data/y', | 354 'package_name': 'infra/data/y', |
| 354 'version': 'canary', | 355 'version': 'canary', |
| 355 }, | 356 }, |
| 356 ] | 357 ] |
| 357 })) | 358 })) |
| 358 finally: | 359 finally: |
| 359 os.close(packages_fd) | 360 os.close(packages_fd) |
| 360 | 361 |
| 362 cipd_cache = os.path.join(self.tempdir, 'cipd_cache') |
| 361 cmd = [ | 363 cmd = [ |
| 362 '--no-log', | 364 '--no-log', |
| 365 '--cache', os.path.join(self.tempdir, 'cache'), |
| 363 '--cipd-package-list', packages_path, | 366 '--cipd-package-list', packages_path, |
| 364 '--cipd-server', self.cipd_server.url, | 367 '--cipd-server', self.cipd_server.url, |
| 368 '--cipd-cache', cipd_cache, |
| 365 'bin/echo${EXECUTABLE_SUFFIX}', | 369 'bin/echo${EXECUTABLE_SUFFIX}', |
| 366 'hello', | 370 'hello', |
| 367 'world', | 371 'world', |
| 368 ] | 372 ] |
| 369 ret = run_isolated.main(cmd) | 373 ret = run_isolated.main(cmd) |
| 370 self.assertEqual(0, ret) | 374 self.assertEqual(0, ret) |
| 371 | 375 |
| 372 print self.popen_calls | 376 print self.popen_calls |
| 373 self.assertEqual(3, len(self.popen_calls)) | 377 self.assertEqual(3, len(self.popen_calls)) |
| 374 | 378 |
| 375 # Test cipd-ensure command for installing packages. | 379 # Test cipd-ensure command for installing packages. |
| 376 for cipd_ensure_cmd, _ in self.popen_calls[0:2]: | 380 for cipd_ensure_cmd, _ in self.popen_calls[0:2]: |
| 377 self.assertEqual(cipd_ensure_cmd[:2], [ | 381 self.assertEqual(cipd_ensure_cmd[:2], [ |
| 378 os.path.abspath('cipd_cache/cipd' + cipd.EXECUTABLE_SUFFIX), | 382 os.path.join(cipd_cache, 'cipd' + cipd.EXECUTABLE_SUFFIX), |
| 379 'ensure', | 383 'ensure', |
| 380 ]) | 384 ]) |
| 381 cache_dir_index = cipd_ensure_cmd.index('-cache-dir') | 385 cache_dir_index = cipd_ensure_cmd.index('-cache-dir') |
| 382 self.assertEqual( | 386 self.assertEqual( |
| 383 cipd_ensure_cmd[cache_dir_index+1], | 387 cipd_ensure_cmd[cache_dir_index+1], |
| 384 os.path.abspath('cipd_cache/cipd_internal')) | 388 os.path.join(cipd_cache, 'cipd_internal')) |
| 385 | 389 |
| 386 # Test cipd cache. | 390 # Test cipd cache. |
| 387 version_file = unicode(os.path.abspath( | 391 version_file = unicode(os.path.join( |
| 388 'cipd_cache/versions/1481d0a0ceb16ea4672fed76a0710306eb9f3a33')) | 392 cipd_cache, 'versions', '1481d0a0ceb16ea4672fed76a0710306eb9f3a33')) |
| 389 self.assertTrue(fs.isfile(version_file)) | 393 self.assertTrue(fs.isfile(version_file)) |
| 390 with open(version_file) as f: | 394 with open(version_file) as f: |
| 391 self.assertEqual(f.read(), 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') | 395 self.assertEqual(f.read(), 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') |
| 392 | 396 |
| 393 client_binary_file = unicode(os.path.abspath( | 397 client_binary_file = unicode(os.path.join( |
| 394 'cipd_cache/clients/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')) | 398 cipd_cache, 'clients', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')) |
| 395 self.assertTrue(fs.isfile(client_binary_file)) | 399 self.assertTrue(fs.isfile(client_binary_file)) |
| 396 | 400 |
| 397 # Test echo call. | 401 # Test echo call. |
| 398 echo_cmd, _ = self.popen_calls[2] | 402 echo_cmd, _ = self.popen_calls[2] |
| 399 self.assertTrue(echo_cmd[0].endswith( | 403 self.assertTrue(echo_cmd[0].endswith( |
| 400 '/bin/echo' + cipd.EXECUTABLE_SUFFIX)) | 404 '/bin/echo' + cipd.EXECUTABLE_SUFFIX)) |
| 401 self.assertEqual(echo_cmd[1:], ['hello', 'world']) | 405 self.assertEqual(echo_cmd[1:], ['hello', 'world']) |
| 402 finally: | 406 finally: |
| 403 os.remove(packages_path) | 407 os.remove(packages_path) |
| 404 | 408 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 self.assertEqual(expected, actual) | 633 self.assertEqual(expected, actual) |
| 630 | 634 |
| 631 | 635 |
| 632 if __name__ == '__main__': | 636 if __name__ == '__main__': |
| 633 fix_encoding.fix_encoding() | 637 fix_encoding.fix_encoding() |
| 634 if '-v' in sys.argv: | 638 if '-v' in sys.argv: |
| 635 unittest.TestCase.maxDiff = None | 639 unittest.TestCase.maxDiff = None |
| 636 logging.basicConfig( | 640 logging.basicConfig( |
| 637 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) | 641 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) |
| 638 unittest.main() | 642 unittest.main() |
| OLD | NEW |