blob: e76ecf93b79806be923f12c504138864fafbd491 [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'
37 test_image = '/some/image/path'
38 build_minios.main([
39 # --board is a required argument.
40 '--board', test_board,
41 # --image is a required argument.
42 '--image', test_image,
43 ])
44
45 self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
46 test_board,
47 self._tempdir,
48 constants.VBOOT_DEVKEYS_DIR,
49 constants.RECOVERY_PUBLIC_KEY,
50 constants.RECOVERY_DATA_PRIVATE_KEY,
51 constants.RECOVERY_KEYBLOCK,
52 None,
53 )])
54
55 self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
56 test_image, self.create_minios_mock_return,
57 )])
58
59 def testOverridenArguments(self):
60 """Test that overridden arguments of build_minios are formatted correct."""
61 test_board = 'test-board'
62 test_image = '/some/image/path'
63 test_keys_dir = '/some/path/test-keys-dir'
64 test_public_key = 'test-public-key'
65 test_private_key = 'test-private-key'
66 test_keyblock = 'test-keyblock'
67 test_serial = 'test-serial'
68 build_minios.main([
69 # --board is a required argument.
70 '--board', test_board,
71 # --image is a required argument.
72 '--image', test_image,
73 '--keys-dir', test_keys_dir,
74 '--public-key', test_public_key,
75 '--private-key', test_private_key,
76 '--keyblock', test_keyblock,
77 '--serial', test_serial,
78 ])
79
80 self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
81 test_board,
82 self._tempdir,
83 test_keys_dir,
84 test_public_key,
85 test_private_key,
86 test_keyblock,
87 test_serial,
88 )])
89
90 self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
91 test_image, self.create_minios_mock_return,
92 )])