| #!/usr/bin/python |
| # |
| # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import cPickle |
| import signal |
| import os |
| import sys |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname( |
| os.path.abspath(__file__))))) |
| |
| from chromite.lib import commandline |
| from chromite.lib import cros_test_lib |
| from chromite.lib import gs |
| |
| |
| # pylint: disable=W0212 |
| class TestShutDownException(cros_test_lib.TestCase): |
| """Test that ShutDownException can be pickled.""" |
| |
| def testShutDownException(self): |
| """Test that ShutDownException can be pickled.""" |
| ex = commandline._ShutDownException(signal.SIGTERM, 'Received SIGTERM') |
| ex2 = cPickle.loads(cPickle.dumps(ex)) |
| self.assertEqual(ex.signal, ex2.signal) |
| self.assertEqual(ex.message, ex2.message) |
| |
| |
| class GSPathTest(cros_test_lib.TestCase): |
| """Test type=gs_path normalization functionality.""" |
| |
| GS_REL_PATH = 'bucket/path/to/artifacts' |
| |
| @staticmethod |
| def _ParseCommandLine(argv): |
| parser = commandline.OptionParser() |
| parser.add_option('-g', '--gs-path', type='gs_path', |
| help=('GS path that contains the chrome to deploy.')) |
| return parser.parse_args(argv) |
| |
| def _RunGSPathTestCase(self, raw, parsed): |
| options, _ = self._ParseCommandLine(['--gs-path', raw]) |
| self.assertEquals(options.gs_path, parsed) |
| |
| def testNoGSPathCorrectionNeeded(self): |
| """Test case where GS path correction is not needed.""" |
| gs_path = '%s/%s' % (gs.BASE_GS_URL, self.GS_REL_PATH) |
| self._RunGSPathTestCase(gs_path, gs_path) |
| |
| def testTrailingSlashRemoval(self): |
| """Test case where GS path correction is not needed.""" |
| gs_path = '%s/%s/' % (gs.BASE_GS_URL, self.GS_REL_PATH) |
| self._RunGSPathTestCase(gs_path, gs_path.rstrip('/')) |
| |
| def testCorrectionNeeded(self): |
| """Test case where GS path correction is needed.""" |
| self._RunGSPathTestCase( |
| '%s/%s/' % (gs.PRIVATE_BASE_HTTPS_URL, self.GS_REL_PATH), |
| '%s/%s' % (gs.BASE_GS_URL, self.GS_REL_PATH)) |
| |
| def testInvalidPath(self): |
| """Path cannot be normalized.""" |
| with cros_test_lib.OutputCapturer(): |
| self.assertRaises2( |
| SystemExit, self._RunGSPathTestCase, 'http://badhost.com/path', '', |
| check_attrs={'code': 2}) |
| |
| |
| if __name__ == '__main__': |
| cros_test_lib.main() |