Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Image service tests.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame^] | 11 | import sys |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 12 | |
Mike Frysinger | 6db648e | 2018-07-24 19:57:58 -0400 | [diff] [blame] | 13 | import mock |
| 14 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 15 | from chromite.api import api_config |
Alex Klein | 8cb365a | 2019-05-15 16:24:53 -0600 | [diff] [blame] | 16 | from chromite.api import controller |
| 17 | from chromite.api.controller import image as image_controller |
Alex Klein | 7107bdd | 2019-03-14 17:14:31 -0600 | [diff] [blame] | 18 | from chromite.api.gen.chromite.api import image_pb2 |
David Burger | 13e06be | 2019-05-13 20:33:16 -0600 | [diff] [blame] | 19 | from chromite.api.gen.chromiumos import common_pb2 |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 20 | from chromite.lib import constants |
Alex Klein | 4f0eb43 | 2019-05-02 13:56:04 -0600 | [diff] [blame] | 21 | from chromite.lib import cros_build_lib |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 22 | from chromite.lib import cros_test_lib |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 23 | from chromite.lib import image_lib |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 24 | from chromite.lib import osutils |
Alex Klein | b7cdbe6 | 2019-02-22 11:41:32 -0700 | [diff] [blame] | 25 | from chromite.service import image as image_service |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 26 | |
| 27 | |
Mike Frysinger | ef94e4c | 2020-02-10 23:59:54 -0500 | [diff] [blame^] | 28 | assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' |
| 29 | |
| 30 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 31 | class CreateTest(cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin): |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 32 | """Create image tests.""" |
| 33 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 34 | def setUp(self): |
| 35 | self.response = image_pb2.CreateImageResult() |
| 36 | |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 37 | def _GetRequest(self, board=None, types=None, version=None, builder_path=None, |
| 38 | disable_rootfs_verification=False): |
| 39 | """Helper to build a request instance.""" |
| 40 | return image_pb2.CreateImageRequest( |
| 41 | build_target={'name': board}, |
| 42 | image_types=types, |
| 43 | disable_rootfs_verification=disable_rootfs_verification, |
| 44 | version=version, |
| 45 | builder_path=builder_path, |
| 46 | ) |
| 47 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 48 | def testValidateOnly(self): |
| 49 | """Sanity check that a validate only call does not execute any logic.""" |
| 50 | patch = self.PatchObject(image_service, 'Build') |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 51 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 52 | request = self._GetRequest(board='board') |
| 53 | image_controller.Create(request, self.response, self.validate_only_config) |
| 54 | patch.assert_not_called() |
| 55 | |
Michael Mortensen | 10146cf | 2019-11-19 19:59:22 -0700 | [diff] [blame] | 56 | def testMockCall(self): |
| 57 | """Test that mock call does not execute any logic, returns mocked value.""" |
| 58 | patch = self.PatchObject(image_service, 'Build') |
| 59 | |
| 60 | request = self._GetRequest(board='board') |
| 61 | image_controller.Create(request, self.response, self.mock_call_config) |
| 62 | patch.assert_not_called() |
| 63 | self.assertEqual(self.response.success, True) |
| 64 | |
Michael Mortensen | 85d3840 | 2019-12-12 09:50:29 -0700 | [diff] [blame] | 65 | def testMockError(self): |
| 66 | """Test that mock call does not execute any logic, returns error.""" |
| 67 | patch = self.PatchObject(image_service, 'Build') |
| 68 | |
| 69 | request = self._GetRequest(board='board') |
| 70 | rc = image_controller.Create(request, self.response, self.mock_error_config) |
| 71 | patch.assert_not_called() |
| 72 | self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc) |
| 73 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 74 | def testNoBoard(self): |
| 75 | """Test no board given fails.""" |
| 76 | request = self._GetRequest() |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 77 | |
| 78 | # No board should cause it to fail. |
Alex Klein | 4f0eb43 | 2019-05-02 13:56:04 -0600 | [diff] [blame] | 79 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 80 | image_controller.Create(request, self.response, self.api_config) |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 81 | |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 82 | def testNoTypeSpecified(self): |
| 83 | """Test the image type default.""" |
| 84 | request = self._GetRequest(board='board') |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 85 | |
Alex Klein | 1bcd988 | 2019-03-19 13:25:24 -0600 | [diff] [blame] | 86 | # Failed result to avoid the success handling logic. |
| 87 | result = image_service.BuildResult(1, []) |
| 88 | build_patch = self.PatchObject(image_service, 'Build', return_value=result) |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 89 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 90 | image_controller.Create(request, self.response, self.api_config) |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 91 | build_patch.assert_called_with(images=[constants.IMAGE_TYPE_BASE], |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 92 | board='board', config=mock.ANY) |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 93 | |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 94 | def testSingleTypeSpecified(self): |
| 95 | """Test it's properly using a specified type.""" |
| 96 | request = self._GetRequest(board='board', types=[common_pb2.DEV]) |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 97 | |
| 98 | # Failed result to avoid the success handling logic. |
| 99 | result = image_service.BuildResult(1, []) |
| 100 | build_patch = self.PatchObject(image_service, 'Build', return_value=result) |
| 101 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 102 | image_controller.Create(request, self.response, self.api_config) |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 103 | build_patch.assert_called_with(images=[constants.IMAGE_TYPE_DEV], |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 104 | board='board', config=mock.ANY) |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 105 | |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 106 | def testMultipleAndImpliedTypes(self): |
| 107 | """Test multiple types and implied type handling.""" |
| 108 | # The TEST_VM type should force it to build the test image. |
| 109 | types = [common_pb2.BASE, common_pb2.TEST_VM] |
| 110 | expected_images = [constants.IMAGE_TYPE_BASE, constants.IMAGE_TYPE_TEST] |
| 111 | |
| 112 | request = self._GetRequest(board='board', types=types) |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 113 | |
| 114 | # Failed result to avoid the success handling logic. |
| 115 | result = image_service.BuildResult(1, []) |
| 116 | build_patch = self.PatchObject(image_service, 'Build', return_value=result) |
| 117 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 118 | image_controller.Create(request, self.response, self.api_config) |
Alex Klein | 21b9502 | 2019-05-09 14:14:46 -0600 | [diff] [blame] | 119 | build_patch.assert_called_with(images=expected_images, board='board', |
Alex Klein | 5635568 | 2019-02-07 10:36:54 -0700 | [diff] [blame] | 120 | config=mock.ANY) |
| 121 | |
Alex Klein | 1bcd988 | 2019-03-19 13:25:24 -0600 | [diff] [blame] | 122 | def testFailedPackageHandling(self): |
| 123 | """Test failed packages are populated correctly.""" |
| 124 | result = image_service.BuildResult(1, ['foo/bar', 'cat/pkg']) |
| 125 | expected_packages = [('foo', 'bar'), ('cat', 'pkg')] |
| 126 | self.PatchObject(image_service, 'Build', return_value=result) |
| 127 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 128 | input_proto = self._GetRequest(board='board') |
Alex Klein | 1bcd988 | 2019-03-19 13:25:24 -0600 | [diff] [blame] | 129 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 130 | rc = image_controller.Create(input_proto, self.response, self.api_config) |
| 131 | |
Alex Klein | 8cb365a | 2019-05-15 16:24:53 -0600 | [diff] [blame] | 132 | self.assertEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, rc) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 133 | for package in self.response.failed_packages: |
Alex Klein | 1bcd988 | 2019-03-19 13:25:24 -0600 | [diff] [blame] | 134 | self.assertIn((package.category, package.package_name), expected_packages) |
| 135 | |
Alex Klein | 2557b4f | 2019-07-11 14:34:00 -0600 | [diff] [blame] | 136 | def testNoPackagesFailureHandling(self): |
| 137 | """Test failed packages are populated correctly.""" |
| 138 | result = image_service.BuildResult(1, []) |
| 139 | self.PatchObject(image_service, 'Build', return_value=result) |
Alex Klein | b7cdbe6 | 2019-02-22 11:41:32 -0700 | [diff] [blame] | 140 | |
Alex Klein | 2557b4f | 2019-07-11 14:34:00 -0600 | [diff] [blame] | 141 | input_proto = image_pb2.CreateImageRequest() |
| 142 | input_proto.build_target.name = 'board' |
Alex Klein | 2557b4f | 2019-07-11 14:34:00 -0600 | [diff] [blame] | 143 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 144 | rc = image_controller.Create(input_proto, self.response, self.api_config) |
Alex Klein | 2557b4f | 2019-07-11 14:34:00 -0600 | [diff] [blame] | 145 | self.assertTrue(rc) |
| 146 | self.assertNotEqual(controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE, |
| 147 | rc) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 148 | self.assertFalse(self.response.failed_packages) |
Alex Klein | 2557b4f | 2019-07-11 14:34:00 -0600 | [diff] [blame] | 149 | |
| 150 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 151 | class ImageSignerTestTest(cros_test_lib.MockTempDirTestCase, |
| 152 | api_config.ApiConfigMixin): |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 153 | """Image signer test tests.""" |
| 154 | |
| 155 | def setUp(self): |
| 156 | self.image_path = os.path.join(self.tempdir, 'image.bin') |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 157 | self.result_directory = os.path.join(self.tempdir, 'results') |
| 158 | |
| 159 | osutils.SafeMakedirs(self.result_directory) |
| 160 | osutils.Touch(self.image_path) |
| 161 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 162 | def testValidateOnly(self): |
| 163 | """Sanity check that validate-only calls don't execute any logic.""" |
| 164 | patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True) |
| 165 | input_proto = image_pb2.TestImageRequest() |
| 166 | input_proto.image.path = self.image_path |
| 167 | output_proto = image_pb2.TestImageResult() |
| 168 | |
| 169 | image_controller.SignerTest(input_proto, output_proto, |
| 170 | self.validate_only_config) |
| 171 | |
| 172 | patch.assert_not_called() |
| 173 | |
Michael Mortensen | 10146cf | 2019-11-19 19:59:22 -0700 | [diff] [blame] | 174 | def testMockCall(self): |
| 175 | """Test that mock call does not execute any logic, returns mocked value.""" |
| 176 | patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True) |
| 177 | input_proto = image_pb2.TestImageRequest() |
| 178 | input_proto.image.path = self.image_path |
| 179 | output_proto = image_pb2.TestImageResult() |
| 180 | |
| 181 | image_controller.SignerTest(input_proto, output_proto, |
| 182 | self.mock_call_config) |
| 183 | |
| 184 | patch.assert_not_called() |
| 185 | self.assertEqual(output_proto.success, True) |
| 186 | |
Michael Mortensen | 85d3840 | 2019-12-12 09:50:29 -0700 | [diff] [blame] | 187 | def testMockError(self): |
| 188 | """Test that mock call does not execute any logic, returns error.""" |
| 189 | patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True) |
| 190 | input_proto = image_pb2.TestImageRequest() |
| 191 | input_proto.image.path = self.image_path |
| 192 | output_proto = image_pb2.TestImageResult() |
| 193 | |
| 194 | rc = image_controller.SignerTest(input_proto, output_proto, |
| 195 | self.mock_error_config) |
| 196 | |
| 197 | patch.assert_not_called() |
| 198 | self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc) |
| 199 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 200 | def testSignerTestNoImage(self): |
| 201 | """Test function argument validation.""" |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 202 | input_proto = image_pb2.TestImageRequest() |
| 203 | output_proto = image_pb2.TestImageResult() |
| 204 | |
| 205 | # Nothing provided. |
| 206 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 207 | image_controller.SignerTest(input_proto, output_proto, self.api_config) |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 208 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 209 | def testSignerTestSuccess(self): |
| 210 | """Test successful call handling.""" |
| 211 | self.PatchObject(image_lib, 'SecurityTest', return_value=True) |
| 212 | input_proto = image_pb2.TestImageRequest() |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 213 | input_proto.image.path = self.image_path |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 214 | output_proto = image_pb2.TestImageResult() |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 215 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 216 | image_controller.SignerTest(input_proto, output_proto, self.api_config) |
| 217 | |
| 218 | def testSignerTestFailure(self): |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 219 | """Test function output tests.""" |
| 220 | input_proto = image_pb2.TestImageRequest() |
| 221 | input_proto.image.path = self.image_path |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 222 | output_proto = image_pb2.TestImageResult() |
| 223 | |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 224 | self.PatchObject(image_lib, 'SecurityTest', return_value=False) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 225 | image_controller.SignerTest(input_proto, output_proto, self.api_config) |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 226 | self.assertFalse(output_proto.success) |
| 227 | |
Michael Mortensen | c83c995 | 2019-08-05 12:15:12 -0600 | [diff] [blame] | 228 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 229 | class ImageTestTest(cros_test_lib.MockTempDirTestCase, |
| 230 | api_config.ApiConfigMixin): |
Alex Klein | 2557b4f | 2019-07-11 14:34:00 -0600 | [diff] [blame] | 231 | """Image test tests.""" |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 232 | |
| 233 | def setUp(self): |
| 234 | self.image_path = os.path.join(self.tempdir, 'image.bin') |
| 235 | self.board = 'board' |
| 236 | self.result_directory = os.path.join(self.tempdir, 'results') |
| 237 | |
| 238 | osutils.SafeMakedirs(self.result_directory) |
| 239 | osutils.Touch(self.image_path) |
| 240 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 241 | def testValidateOnly(self): |
| 242 | """Sanity check that a validate only call does not execute any logic.""" |
| 243 | patch = self.PatchObject(image_service, 'Test') |
| 244 | |
| 245 | input_proto = image_pb2.TestImageRequest() |
| 246 | input_proto.image.path = self.image_path |
| 247 | input_proto.build_target.name = self.board |
| 248 | input_proto.result.directory = self.result_directory |
| 249 | output_proto = image_pb2.TestImageResult() |
| 250 | |
| 251 | image_controller.Test(input_proto, output_proto, self.validate_only_config) |
| 252 | patch.assert_not_called() |
| 253 | |
Michael Mortensen | 10146cf | 2019-11-19 19:59:22 -0700 | [diff] [blame] | 254 | def testMockCall(self): |
| 255 | """Test that mock call does not execute any logic, returns mocked value.""" |
| 256 | patch = self.PatchObject(image_service, 'Test') |
| 257 | |
| 258 | input_proto = image_pb2.TestImageRequest() |
| 259 | input_proto.image.path = self.image_path |
| 260 | input_proto.build_target.name = self.board |
| 261 | input_proto.result.directory = self.result_directory |
| 262 | output_proto = image_pb2.TestImageResult() |
| 263 | |
| 264 | image_controller.Test(input_proto, output_proto, self.mock_call_config) |
| 265 | patch.assert_not_called() |
| 266 | self.assertEqual(output_proto.success, True) |
| 267 | |
Michael Mortensen | 85d3840 | 2019-12-12 09:50:29 -0700 | [diff] [blame] | 268 | def testMockError(self): |
| 269 | """Test that mock call does not execute any logic, returns error.""" |
| 270 | patch = self.PatchObject(image_service, 'Test') |
| 271 | |
| 272 | input_proto = image_pb2.TestImageRequest() |
| 273 | input_proto.image.path = self.image_path |
| 274 | input_proto.build_target.name = self.board |
| 275 | input_proto.result.directory = self.result_directory |
| 276 | output_proto = image_pb2.TestImageResult() |
| 277 | |
| 278 | rc = image_controller.Test(input_proto, output_proto, |
| 279 | self.mock_error_config) |
| 280 | patch.assert_not_called() |
| 281 | self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc) |
| 282 | |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 283 | def testTestArgumentValidation(self): |
| 284 | """Test function argument validation tests.""" |
Alex Klein | b7cdbe6 | 2019-02-22 11:41:32 -0700 | [diff] [blame] | 285 | self.PatchObject(image_service, 'Test', return_value=True) |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 286 | input_proto = image_pb2.TestImageRequest() |
| 287 | output_proto = image_pb2.TestImageResult() |
| 288 | |
| 289 | # Nothing provided. |
Alex Klein | 4f0eb43 | 2019-05-02 13:56:04 -0600 | [diff] [blame] | 290 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 291 | image_controller.Test(input_proto, output_proto, self.api_config) |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 292 | |
| 293 | # Just one argument. |
| 294 | input_proto.build_target.name = self.board |
Alex Klein | 4f0eb43 | 2019-05-02 13:56:04 -0600 | [diff] [blame] | 295 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 296 | image_controller.Test(input_proto, output_proto, self.api_config) |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 297 | |
| 298 | # Two arguments provided. |
| 299 | input_proto.result.directory = self.result_directory |
Alex Klein | 4f0eb43 | 2019-05-02 13:56:04 -0600 | [diff] [blame] | 300 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 301 | image_controller.Test(input_proto, output_proto, self.api_config) |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 302 | |
| 303 | # Invalid image path. |
| 304 | input_proto.image.path = '/invalid/image/path' |
Alex Klein | 4f0eb43 | 2019-05-02 13:56:04 -0600 | [diff] [blame] | 305 | with self.assertRaises(cros_build_lib.DieSystemExit): |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 306 | image_controller.Test(input_proto, output_proto, self.api_config) |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 307 | |
| 308 | # All valid arguments. |
| 309 | input_proto.image.path = self.image_path |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 310 | image_controller.Test(input_proto, output_proto, self.api_config) |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 311 | |
| 312 | def testTestOutputHandling(self): |
| 313 | """Test function output tests.""" |
| 314 | input_proto = image_pb2.TestImageRequest() |
| 315 | input_proto.image.path = self.image_path |
| 316 | input_proto.build_target.name = self.board |
| 317 | input_proto.result.directory = self.result_directory |
| 318 | output_proto = image_pb2.TestImageResult() |
| 319 | |
Alex Klein | b7cdbe6 | 2019-02-22 11:41:32 -0700 | [diff] [blame] | 320 | self.PatchObject(image_service, 'Test', return_value=True) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 321 | image_controller.Test(input_proto, output_proto, self.api_config) |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 322 | self.assertTrue(output_proto.success) |
| 323 | |
Alex Klein | b7cdbe6 | 2019-02-22 11:41:32 -0700 | [diff] [blame] | 324 | self.PatchObject(image_service, 'Test', return_value=False) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 325 | image_controller.Test(input_proto, output_proto, self.api_config) |
Alex Klein | 2966e30 | 2019-01-17 13:29:38 -0700 | [diff] [blame] | 326 | self.assertFalse(output_proto.success) |