blob: c1d0f583d48ee0a07762ebcaeadd7c108e9e6fca [file] [log] [blame]
Jae Hoon Kimbb0ddf02023-07-21 04:23:12 +00001# 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"""Unit tests for cros_generate_dlc_artifacts."""
6
7
8from unittest import mock
9
10import pytest
11
12from chromite.lib import dlc_lib
13from chromite.scripts import cros_generate_dlc_artifacts
14
15
16@pytest.mark.parametrize("dry_run", ((False), (True)))
17def test_upload_dlc_artifacts(dry_run):
18 """Tests out UploadDlcArtifacts with dry_run option"""
19 artifact_mock = mock.Mock()
20 cros_generate_dlc_artifacts.UploadDlcArtifacts(
21 artifact_mock, dry_run=dry_run
22 )
23 artifact_mock.Upload.assert_called_with(dry_run=dry_run)
24
25
26@pytest.mark.parametrize("dlc_id", ("some-dlc-id",))
27@pytest.mark.parametrize("preallocated_blocks", (123,))
28@pytest.mark.parametrize("name", ((""), ("<some-name>")))
29@pytest.mark.parametrize("description", ((""), ("<some-description>")))
30@pytest.mark.parametrize("version", ("<some-version>",))
31@mock.patch.object(dlc_lib, "EbuildParams")
32def test_generate_dlc_params(
33 mock_ebuild_params,
34 dlc_id,
35 preallocated_blocks,
36 name,
37 description,
38 version,
39 tmp_path,
40):
41 """Tests out GenerateDlcParams"""
42 tmpfile = tmp_path / "license"
43 tmpfile.touch()
44 argv = [
45 "--src-dir",
46 ".",
47 "--license",
48 str(tmpfile),
49 *(["--id", f"{dlc_id}"] if dlc_id else []),
50 *(
51 ["--preallocated-blocks", f"{preallocated_blocks}"]
52 if preallocated_blocks
53 else []
54 ),
55 *(["--name", f"{name}"] if name else []),
56 *(["--description", f"{description}"] if description else []),
57 *(["--version", f"{version}"] if version else []),
58 ]
59 opts = cros_generate_dlc_artifacts.ParseArguments(argv)
60 cros_generate_dlc_artifacts.GenerateDlcParams(opts)
61 mock_ebuild_params.assert_called_with(
62 dlc_id=dlc_id,
63 dlc_package="package",
64 fs_type=dlc_lib.SQUASHFS_TYPE,
65 pre_allocated_blocks=preallocated_blocks,
66 version=version,
67 name=name,
68 description=description,
69 preload=False,
70 used_by="",
71 mount_file_required=False,
72 fullnamerev="",
73 scaled=True,
74 loadpin_verity_digest=False,
75 )