blob: ebeed2f337922c848682ef648e192d6af7dc74ee [file] [log] [blame]
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -07001# Copyright 2021 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Unittests for build_minios.py"""
6
7import os
8import tempfile
9from unittest import mock
10
11from chromite.lib import constants
12from chromite.lib import cros_test_lib
13from chromite.lib import minios
14from chromite.scripts import build_minios
15
16
17class BuildMiniosTest(cros_test_lib.RunCommandTempDirTestCase):
18 """Unit tests for build_minios."""
19
20 def setUp(self):
21 self.create_minios_mock_return = '/some/kernel/path'
22 self.create_minios_mock = self.PatchObject(
23 minios, 'CreateMiniOsKernelImage',
24 return_value=self.create_minios_mock_return)
25
26 self.insert_minios_mock = self.PatchObject(
27 minios, 'InsertMiniOsKernelImage')
28
29 # Patch to assert against the tempdir that's created under the anchored
30 # tempdir created by cros_test_lib.
31 self._tempdir = os.path.join(self.tempdir, 'test-dir')
32 self.PatchObject(tempfile, 'mkdtemp', return_value=self._tempdir)
33
34 def testDefaultArguments(self):
35 """Test that default arguments of build_minios are formatted correct."""
36 test_board = 'test-board'
Vyshu92153902021-06-16 13:31:53 -040037 test_version = '0.0.0.0'
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070038 test_image = '/some/image/path'
39 build_minios.main([
40 # --board is a required argument.
41 '--board', test_board,
Vyshu92153902021-06-16 13:31:53 -040042 # --version is a required argument.
43 '--version', test_version,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070044 # --image is a required argument.
45 '--image', test_image,
46 ])
47
48 self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
49 test_board,
Vyshu92153902021-06-16 13:31:53 -040050 test_version,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070051 self._tempdir,
52 constants.VBOOT_DEVKEYS_DIR,
53 constants.RECOVERY_PUBLIC_KEY,
Jae Hoon Kim4e35db82021-06-16 13:05:44 -070054 constants.MINIOS_DATA_PRIVATE_KEY,
55 constants.MINIOS_KEYBLOCK,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070056 None,
57 )])
58
59 self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
60 test_image, self.create_minios_mock_return,
61 )])
62
63 def testOverridenArguments(self):
64 """Test that overridden arguments of build_minios are formatted correct."""
65 test_board = 'test-board'
Vyshu92153902021-06-16 13:31:53 -040066 test_version = '1.0.0.0'
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070067 test_image = '/some/image/path'
68 test_keys_dir = '/some/path/test-keys-dir'
69 test_public_key = 'test-public-key'
70 test_private_key = 'test-private-key'
71 test_keyblock = 'test-keyblock'
72 test_serial = 'test-serial'
73 build_minios.main([
74 # --board is a required argument.
75 '--board', test_board,
Vyshu92153902021-06-16 13:31:53 -040076 # --version is a required argument.
77 '--version', test_version,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070078 # --image is a required argument.
79 '--image', test_image,
80 '--keys-dir', test_keys_dir,
81 '--public-key', test_public_key,
82 '--private-key', test_private_key,
83 '--keyblock', test_keyblock,
84 '--serial', test_serial,
85 ])
86
87 self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
88 test_board,
Vyshu92153902021-06-16 13:31:53 -040089 test_version,
Jae Hoon Kim2f8c62a2021-06-22 15:10:43 -070090 self._tempdir,
91 test_keys_dir,
92 test_public_key,
93 test_private_key,
94 test_keyblock,
95 test_serial,
96 )])
97
98 self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
99 test_image, self.create_minios_mock_return,
100 )])