herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 1 | # Copyright 2018 - The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | """Tests for avd_spec.""" |
| 15 | |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 16 | import glob |
| 17 | import os |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 18 | import unittest |
| 19 | import mock |
| 20 | |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 21 | from acloud import errors |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 22 | from acloud.create import avd_spec |
| 23 | from acloud.internal import constants |
herbertxue | af97945 | 2019-04-29 09:56:59 +0800 | [diff] [blame] | 24 | from acloud.internal.lib import android_build_client |
| 25 | from acloud.internal.lib import auth |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 26 | from acloud.internal.lib import driver_test_lib |
| 27 | from acloud.internal.lib import utils |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 28 | |
| 29 | |
| 30 | # pylint: disable=invalid-name,protected-access |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 31 | class AvdSpecTest(driver_test_lib.BaseDriverTest): |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 32 | """Test avd_spec methods.""" |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 33 | |
| 34 | def setUp(self): |
| 35 | """Initialize new avd_spec.AVDSpec.""" |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 36 | super(AvdSpecTest, self).setUp() |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 37 | self.args = mock.MagicMock() |
herbertxue | a4663c0 | 2019-07-21 22:37:17 +0800 | [diff] [blame] | 38 | self.args.flavor = "" |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 39 | self.args.local_image = "" |
herbertxue | 79585f4 | 2018-08-28 18:36:45 +0800 | [diff] [blame] | 40 | self.args.config_file = "" |
chojoyce | 7a36173 | 2018-11-26 16:26:13 +0800 | [diff] [blame] | 41 | self.args.build_target = "fake_build_target" |
herbertxue | 6ef54a5 | 2019-05-02 11:38:58 +0800 | [diff] [blame] | 42 | self.args.adb_port = None |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 43 | self.AvdSpec = avd_spec.AVDSpec(self.args) |
| 44 | |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 45 | # pylint: disable=protected-access |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 46 | def testProcessLocalImageArgs(self): |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 47 | """Test process args.local_image.""" |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 48 | self.Patch(glob, "glob", return_value=["fake.img"]) |
| 49 | expected_image_artifact = "/path/cf_x86_phone-img-eng.user.zip" |
| 50 | expected_image_dir = "/path-to-image-dir" |
| 51 | |
| 52 | # Specified --local-image to a local zipped image file |
| 53 | self.Patch(os.path, "isfile", return_value=True) |
| 54 | self.args.local_image = "/path/cf_x86_phone-img-eng.user.zip" |
| 55 | self.AvdSpec._avd_type = constants.TYPE_CF |
| 56 | self.AvdSpec._instance_type = constants.INSTANCE_TYPE_REMOTE |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 57 | self.AvdSpec._ProcessLocalImageArgs(self.args) |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 58 | self.assertEqual(self.AvdSpec._local_image_artifact, |
| 59 | expected_image_artifact) |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 60 | |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 61 | # Specified --local-image to a dir contains images |
| 62 | self.Patch(utils, "GetBuildEnvironmentVariable", |
| 63 | return_value="test_environ") |
| 64 | self.Patch(os.path, "isfile", return_value=False) |
| 65 | self.args.local_image = "/path-to-image-dir" |
| 66 | self.AvdSpec._avd_type = constants.TYPE_CF |
| 67 | self.AvdSpec._instance_type = constants.INSTANCE_TYPE_REMOTE |
| 68 | self.AvdSpec._ProcessLocalImageArgs(self.args) |
| 69 | self.assertEqual(self.AvdSpec._local_image_dir, expected_image_dir) |
| 70 | |
| 71 | # Specified local_image without arg |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 72 | self.args.local_image = None |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 73 | self.Patch(utils, "GetBuildEnvironmentVariable", |
| 74 | return_value="test_environ") |
| 75 | self.AvdSpec._ProcessLocalImageArgs(self.args) |
| 76 | self.assertEqual(self.AvdSpec._local_image_dir, "test_environ") |
| 77 | self.assertEqual(self.AvdSpec.local_image_artifact, expected_image_artifact) |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 78 | |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 79 | def testProcessImageArgs(self): |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 80 | """Test process image source.""" |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 81 | self.Patch(glob, "glob", return_value=["fake.img"]) |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 82 | # No specified local_image, image source is from remote |
| 83 | self.args.local_image = "" |
| 84 | self.AvdSpec._ProcessImageArgs(self.args) |
| 85 | self.assertEqual(self.AvdSpec._image_source, constants.IMAGE_SRC_REMOTE) |
cylan | 1e996c5 | 2018-10-01 16:19:50 +0800 | [diff] [blame] | 86 | self.assertEqual(self.AvdSpec._local_image_dir, None) |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 87 | |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 88 | # Specified local_image with an arg for cf type |
| 89 | self.Patch(os.path, "isfile", return_value=True) |
| 90 | self.args.local_image = "/test_path/cf_x86_phone-img-eng.user.zip" |
| 91 | self.AvdSpec._avd_type = constants.TYPE_CF |
| 92 | self.AvdSpec._instance_type = constants.INSTANCE_TYPE_REMOTE |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 93 | self.AvdSpec._ProcessImageArgs(self.args) |
| 94 | self.assertEqual(self.AvdSpec._image_source, constants.IMAGE_SRC_LOCAL) |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 95 | self.assertEqual(self.AvdSpec._local_image_artifact, |
| 96 | "/test_path/cf_x86_phone-img-eng.user.zip") |
| 97 | |
| 98 | # Specified local_image with an arg for gce type |
| 99 | self.Patch(os.path, "isfile", return_value=False) |
| 100 | self.Patch(os.path, "exists", return_value=True) |
| 101 | self.args.local_image = "/test_path_to_dir/" |
| 102 | self.AvdSpec._avd_type = constants.TYPE_GCE |
| 103 | self.AvdSpec._ProcessImageArgs(self.args) |
| 104 | self.assertEqual(self.AvdSpec._image_source, constants.IMAGE_SRC_LOCAL) |
| 105 | self.assertEqual(self.AvdSpec._local_image_artifact, |
| 106 | "/test_path_to_dir/avd-system.tar.gz") |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 107 | |
Kevin Cheng | e258045 | 2018-10-05 16:33:56 -0700 | [diff] [blame] | 108 | @mock.patch.object(avd_spec.AVDSpec, "_GetGitRemote") |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 109 | @mock.patch("subprocess.check_output") |
Kevin Cheng | e258045 | 2018-10-05 16:33:56 -0700 | [diff] [blame] | 110 | def testGetBranchFromRepo(self, mock_repo, mock_gitremote): |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 111 | """Test get branch name from repo info.""" |
Kevin Cheng | e258045 | 2018-10-05 16:33:56 -0700 | [diff] [blame] | 112 | # Check aosp repo gets proper branch prefix. |
| 113 | mock_gitremote.return_value = "aosp" |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 114 | mock_repo.return_value = "Manifest branch: master" |
| 115 | self.assertEqual(self.AvdSpec._GetBranchFromRepo(), "aosp-master") |
| 116 | |
Kevin Cheng | e258045 | 2018-10-05 16:33:56 -0700 | [diff] [blame] | 117 | # Check default repo gets default branch prefix. |
| 118 | mock_gitremote.return_value = "" |
| 119 | mock_repo.return_value = "Manifest branch: master" |
| 120 | self.assertEqual(self.AvdSpec._GetBranchFromRepo(), "git_master") |
| 121 | |
herbertxue | c7379b0 | 2019-06-21 15:47:18 +0800 | [diff] [blame] | 122 | # Can't get branch from repo info, set it as default branch. |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 123 | mock_repo.return_value = "Manifest branch:" |
herbertxue | c7379b0 | 2019-06-21 15:47:18 +0800 | [diff] [blame] | 124 | self.assertEqual(self.AvdSpec._GetBranchFromRepo(), "aosp-master") |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 125 | |
herbertxue | af97945 | 2019-04-29 09:56:59 +0800 | [diff] [blame] | 126 | def testGetBuildBranch(self): |
| 127 | """Test GetBuildBranch function""" |
| 128 | # Test infer branch from build_id and build_target. |
| 129 | build_client = mock.MagicMock() |
| 130 | build_id = "fake_build_id" |
| 131 | build_target = "fake_build_target" |
| 132 | expected_branch = "fake_build_branch" |
| 133 | self.Patch(android_build_client, "AndroidBuildClient", |
| 134 | return_value=build_client) |
| 135 | self.Patch(auth, "CreateCredentials", return_value=mock.MagicMock()) |
| 136 | self.Patch(build_client, "GetBranch", return_value=expected_branch) |
| 137 | self.assertEqual(self.AvdSpec._GetBuildBranch(build_id, build_target), |
| 138 | expected_branch) |
| 139 | # Infer branch from "repo info" when build_id and build_target is None. |
| 140 | self.Patch(self.AvdSpec, "_GetBranchFromRepo", return_value="repo_branch") |
| 141 | build_id = None |
| 142 | build_target = None |
| 143 | expected_branch = "repo_branch" |
| 144 | self.assertEqual(self.AvdSpec._GetBuildBranch(build_id, build_target), |
| 145 | expected_branch) |
| 146 | |
Kevin Cheng | 990e228 | 2018-10-08 15:51:37 -0700 | [diff] [blame] | 147 | # pylint: disable=protected-access |
| 148 | def testGetBuildTarget(self): |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 149 | """Test get build target name.""" |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 150 | self.AvdSpec._remote_image[constants.BUILD_BRANCH] = "git_branch" |
Kevin Cheng | 41f5f9b | 2019-01-11 02:44:59 -0800 | [diff] [blame] | 151 | self.AvdSpec._flavor = constants.FLAVOR_IOT |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 152 | self.args.avd_type = constants.TYPE_GCE |
| 153 | self.assertEqual( |
| 154 | self.AvdSpec._GetBuildTarget(self.args), |
chojoyce | 7a36173 | 2018-11-26 16:26:13 +0800 | [diff] [blame] | 155 | "gce_x86_iot-userdebug") |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 156 | |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 157 | self.AvdSpec._remote_image[constants.BUILD_BRANCH] = "aosp-master" |
Kevin Cheng | 41f5f9b | 2019-01-11 02:44:59 -0800 | [diff] [blame] | 158 | self.AvdSpec._flavor = constants.FLAVOR_PHONE |
herbertxue | b617e8a | 2018-08-22 10:02:19 +0800 | [diff] [blame] | 159 | self.args.avd_type = constants.TYPE_CF |
| 160 | self.assertEqual( |
| 161 | self.AvdSpec._GetBuildTarget(self.args), |
| 162 | "aosp_cf_x86_phone-userdebug") |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 163 | |
herbertxue | 23b2a96 | 2019-07-24 22:39:20 +0800 | [diff] [blame] | 164 | self.AvdSpec._remote_image[constants.BUILD_BRANCH] = "git_branch" |
Kevin Cheng | 41f5f9b | 2019-01-11 02:44:59 -0800 | [diff] [blame] | 165 | self.AvdSpec._flavor = constants.FLAVOR_PHONE |
Kevin Cheng | e258045 | 2018-10-05 16:33:56 -0700 | [diff] [blame] | 166 | self.args.avd_type = constants.TYPE_CF |
| 167 | self.assertEqual( |
| 168 | self.AvdSpec._GetBuildTarget(self.args), |
| 169 | "cf_x86_phone-userdebug") |
| 170 | |
Sam Chiu | c64f343 | 2018-08-17 11:19:06 +0800 | [diff] [blame] | 171 | # pylint: disable=protected-access |
| 172 | def testProcessHWPropertyWithInvalidArgs(self): |
| 173 | """Test _ProcessHWPropertyArgs with invalid args.""" |
| 174 | # Checking wrong resolution. |
| 175 | args = mock.MagicMock() |
| 176 | args.hw_property = "cpu:3,resolution:1280" |
| 177 | with self.assertRaises(errors.InvalidHWPropertyError): |
| 178 | self.AvdSpec._ProcessHWPropertyArgs(args) |
| 179 | |
| 180 | # Checking property should be int. |
| 181 | args = mock.MagicMock() |
| 182 | args.hw_property = "cpu:3,dpi:fake" |
| 183 | with self.assertRaises(errors.InvalidHWPropertyError): |
| 184 | self.AvdSpec._ProcessHWPropertyArgs(args) |
| 185 | |
| 186 | # Checking disk property should be with 'g' suffix. |
| 187 | args = mock.MagicMock() |
| 188 | args.hw_property = "cpu:3,disk:2" |
| 189 | with self.assertRaises(errors.InvalidHWPropertyError): |
| 190 | self.AvdSpec._ProcessHWPropertyArgs(args) |
| 191 | |
| 192 | # Checking memory property should be with 'g' suffix. |
| 193 | args = mock.MagicMock() |
| 194 | args.hw_property = "cpu:3,memory:2" |
| 195 | with self.assertRaises(errors.InvalidHWPropertyError): |
| 196 | self.AvdSpec._ProcessHWPropertyArgs(args) |
| 197 | |
| 198 | # pylint: disable=protected-access |
| 199 | def testParseHWPropertyStr(self): |
| 200 | """Test _ParseHWPropertyStr.""" |
| 201 | expected_dict = {"cpu": "2", "x_res": "1080", "y_res": "1920", |
| 202 | "dpi": "240", "memory": "4096", "disk": "4096"} |
| 203 | args_str = "cpu:2,resolution:1080x1920,dpi:240,memory:4g,disk:4g" |
| 204 | result_dict = self.AvdSpec._ParseHWPropertyStr(args_str) |
| 205 | self.assertTrue(expected_dict == result_dict) |
| 206 | |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 207 | def testGetFlavorFromBuildTargetString(self): |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 208 | """Test _GetFlavorFromLocalImage.""" |
| 209 | img_path = "/fack_path/cf_x86_tv-img-eng.user.zip" |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 210 | self.assertEqual(self.AvdSpec._GetFlavorFromString(img_path), |
| 211 | "tv") |
| 212 | |
| 213 | build_target_str = "aosp_cf_x86_auto" |
| 214 | self.assertEqual(self.AvdSpec._GetFlavorFromString( |
| 215 | build_target_str), "auto") |
herbertxue | fd15dfd | 2018-12-04 11:26:27 +0800 | [diff] [blame] | 216 | |
| 217 | # Flavor is not supported. |
| 218 | img_path = "/fack_path/cf_x86_error-img-eng.user.zip" |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 219 | self.assertEqual(self.AvdSpec._GetFlavorFromString(img_path), |
| 220 | None) |
herbertxue | ad1c94c | 2019-01-15 16:00:18 +0800 | [diff] [blame] | 221 | |
chojoyce | 7a36173 | 2018-11-26 16:26:13 +0800 | [diff] [blame] | 222 | # pylint: disable=protected-access |
| 223 | def testProcessRemoteBuildArgs(self): |
| 224 | """Test _ProcessRemoteBuildArgs.""" |
| 225 | self.args.branch = "git_master" |
| 226 | self.args.build_id = "1234" |
| 227 | |
| 228 | # Verify auto-assigned avd_type if build_targe contains "_gce_". |
| 229 | self.args.build_target = "aosp_gce_x86_phone-userdebug" |
| 230 | self.AvdSpec._ProcessRemoteBuildArgs(self.args) |
| 231 | self.assertTrue(self.AvdSpec.avd_type == "gce") |
| 232 | |
| 233 | # Verify auto-assigned avd_type if build_targe contains "gce_". |
| 234 | self.args.build_target = "gce_x86_phone-userdebug" |
| 235 | self.AvdSpec._ProcessRemoteBuildArgs(self.args) |
| 236 | self.assertTrue(self.AvdSpec.avd_type == "gce") |
| 237 | |
| 238 | # Verify auto-assigned avd_type if build_targe contains "_cf_". |
| 239 | self.args.build_target = "aosp_cf_x86_phone-userdebug" |
| 240 | self.AvdSpec._ProcessRemoteBuildArgs(self.args) |
| 241 | self.assertTrue(self.AvdSpec.avd_type == "cuttlefish") |
| 242 | |
| 243 | # Verify auto-assigned avd_type if build_targe contains "cf_". |
| 244 | self.args.build_target = "cf_x86_phone-userdebug" |
| 245 | self.AvdSpec._ProcessRemoteBuildArgs(self.args) |
| 246 | self.assertTrue(self.AvdSpec.avd_type == "cuttlefish") |
| 247 | |
| 248 | # Verify auto-assigned avd_type if build_targe contains "sdk_". |
| 249 | self.args.build_target = "sdk_phone_armv7-sdk" |
| 250 | self.AvdSpec._ProcessRemoteBuildArgs(self.args) |
| 251 | self.assertTrue(self.AvdSpec.avd_type == "goldfish") |
| 252 | |
| 253 | # Verify auto-assigned avd_type if build_targe contains "_sdk_". |
| 254 | self.args.build_target = "aosp_sdk_phone_armv7-sdk" |
| 255 | self.AvdSpec._ProcessRemoteBuildArgs(self.args) |
| 256 | self.assertTrue(self.AvdSpec.avd_type == "goldfish") |
| 257 | |
| 258 | # Verify auto-assigned avd_type if no match, default as cuttlefish. |
| 259 | self.args.build_target = "mini_emulator_arm64-userdebug" |
| 260 | self.args.avd_type = "cuttlefish" |
| 261 | # reset args.avd_type default value as cuttlefish. |
| 262 | self.AvdSpec = avd_spec.AVDSpec(self.args) |
| 263 | self.AvdSpec._ProcessRemoteBuildArgs(self.args) |
| 264 | self.assertTrue(self.AvdSpec.avd_type == "cuttlefish") |
| 265 | |
herbertxue | a075bfd | 2019-01-28 17:59:47 +0800 | [diff] [blame] | 266 | def testEscapeAnsi(self): |
| 267 | """Test EscapeAnsi.""" |
| 268 | test_string = "\033[1;32;40m Manifest branch:" |
| 269 | expected_result = " Manifest branch:" |
| 270 | self.assertEqual(avd_spec.EscapeAnsi(test_string), expected_result) |
| 271 | |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 272 | def testGetGceLocalImagePath(self): |
| 273 | """Test get gce local image path.""" |
| 274 | self.Patch(os.path, "isfile", return_value=True) |
| 275 | # Verify when specify --local-image ~/XXX.tar.gz. |
| 276 | fake_image_path = "~/gce_local_image_dir/gce_image.tar.gz" |
| 277 | self.Patch(os.path, "exists", return_value=True) |
| 278 | self.assertEqual(self.AvdSpec._GetGceLocalImagePath(fake_image_path), |
| 279 | "~/gce_local_image_dir/gce_image.tar.gz") |
| 280 | |
| 281 | # Verify when specify --local-image ~/XXX.img. |
| 282 | fake_image_path = "~/gce_local_image_dir/gce_image.img" |
| 283 | self.assertEqual(self.AvdSpec._GetGceLocalImagePath(fake_image_path), |
| 284 | "~/gce_local_image_dir/gce_image.img") |
| 285 | |
| 286 | # Verify if exist argument --local-image as a directory. |
| 287 | self.Patch(os.path, "isfile", return_value=False) |
| 288 | self.Patch(os.path, "exists", return_value=True) |
| 289 | fake_image_path = "~/gce_local_image_dir/" |
| 290 | # Default to find */avd-system.tar.gz if exist then return the path. |
| 291 | self.assertEqual(self.AvdSpec._GetGceLocalImagePath(fake_image_path), |
| 292 | "~/gce_local_image_dir/avd-system.tar.gz") |
| 293 | |
| 294 | # Otherwise choose raw file */android_system_disk_syslinux.img if |
| 295 | # exist then return the path. |
| 296 | self.Patch(os.path, "exists", side_effect=[False, True]) |
| 297 | self.assertEqual(self.AvdSpec._GetGceLocalImagePath(fake_image_path), |
| 298 | "~/gce_local_image_dir/android_system_disk_syslinux.img") |
| 299 | |
| 300 | # Both _GCE_LOCAL_IMAGE_CANDIDATE could not be found then raise error. |
| 301 | self.Patch(os.path, "exists", side_effect=[False, False]) |
herbertxue | e5b98ae | 2019-06-19 09:26:17 +0800 | [diff] [blame] | 302 | self.assertRaises(errors.ImgDoesNotExist, |
Sam Chiu | 96172ae | 2019-01-31 14:30:30 +0800 | [diff] [blame] | 303 | self.AvdSpec._GetGceLocalImagePath, fake_image_path) |
| 304 | |
herbertxue | 2625b04 | 2018-08-16 23:28:20 +0800 | [diff] [blame] | 305 | |
| 306 | if __name__ == "__main__": |
| 307 | unittest.main() |