Benjamin Shai | 80317fc | 2023-08-22 19:33:41 +0000 | [diff] [blame^] | 1 | # Copyright 2023 The ChromiumOS Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """DLC service tests.""" |
| 6 | |
| 7 | from chromite.api import api_config |
| 8 | from chromite.api.controller import dlc as dlc_controller |
| 9 | from chromite.api.gen.chromite.api import dlc_pb2 |
| 10 | from chromite.api.gen.chromite.api import sysroot_pb2 |
| 11 | from chromite.lib import cros_test_lib |
| 12 | from chromite.service import image |
| 13 | |
| 14 | |
| 15 | class GenerateDlcArtifactsListTest( |
| 16 | cros_test_lib.MockTempDirTestCase, api_config.ApiConfigMixin |
| 17 | ): |
| 18 | """Tests for GenerateDLcArtifactsList.""" |
| 19 | |
| 20 | def setUp(self): |
| 21 | self.response = dlc_pb2.GenerateDlcArtifactsListResponse() |
| 22 | self.sysroot_path = "/build/target" |
| 23 | |
| 24 | def _InputProto(self): |
| 25 | in_proto = dlc_pb2.GenerateDlcArtifactsListRequest( |
| 26 | sysroot=sysroot_pb2.Sysroot(path=self.sysroot_path), |
| 27 | ) |
| 28 | in_proto.chroot.path = "path" |
| 29 | return in_proto |
| 30 | |
| 31 | def testNoDlcArtifacts(self): |
| 32 | """Test for no artifacts being returned.""" |
| 33 | self.PatchObject( |
| 34 | image, "generate_dlc_artifacts_metadata_list", return_value=[] |
| 35 | ) |
| 36 | in_proto = self._InputProto() |
| 37 | dlc_controller.GenerateDlcArtifactsList( |
| 38 | in_proto, self.response, self.api_config |
| 39 | ) |
| 40 | |
| 41 | self.assertEqual(len(self.response.dlc_artifacts), 0) |
| 42 | |
| 43 | def testDlcArtifactsSuccess(self): |
| 44 | """Test for successfully returning artifacts.""" |
| 45 | self.PatchObject( |
| 46 | image, |
| 47 | "generate_dlc_artifacts_metadata_list", |
| 48 | return_value=[ |
| 49 | image.DlcArtifactsMetadata( |
| 50 | image_hash="deadbeef", |
| 51 | image_name="dlc.img", |
| 52 | uri_path="gs://some/uri/prefix/for/dlc-1", |
| 53 | ) |
| 54 | ], |
| 55 | ) |
| 56 | in_proto = self._InputProto() |
| 57 | dlc_controller.GenerateDlcArtifactsList( |
| 58 | in_proto, self.response, self.api_config |
| 59 | ) |
| 60 | |
| 61 | self.assertEqual( |
| 62 | self.response.dlc_artifacts[0], |
| 63 | dlc_pb2.GenerateDlcArtifactsListResponse.DlcArtifact( |
| 64 | image_hash="deadbeef", |
| 65 | image_name="dlc.img", |
| 66 | gs_uri_path="gs://some/uri/prefix/for/dlc-1", |
| 67 | ), |
| 68 | ) |