build_minios: Fix arguments + add unittest
Add missing unittest for `build_minios`.
Check that the arguments are forwarded correctly.
BUG=b:191180137
TEST=./run_tests
Change-Id: If91b97b814434ea0e0be4b62f2d4c6bda7cbe0cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2979377
Tested-by: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/scripts/build_minios_unittest.py b/scripts/build_minios_unittest.py
new file mode 100644
index 0000000..e76ecf9
--- /dev/null
+++ b/scripts/build_minios_unittest.py
@@ -0,0 +1,92 @@
+# Copyright 2021 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unittests for build_minios.py"""
+
+import os
+import tempfile
+from unittest import mock
+
+from chromite.lib import constants
+from chromite.lib import cros_test_lib
+from chromite.lib import minios
+from chromite.scripts import build_minios
+
+
+class BuildMiniosTest(cros_test_lib.RunCommandTempDirTestCase):
+ """Unit tests for build_minios."""
+
+ def setUp(self):
+ self.create_minios_mock_return = '/some/kernel/path'
+ self.create_minios_mock = self.PatchObject(
+ minios, 'CreateMiniOsKernelImage',
+ return_value=self.create_minios_mock_return)
+
+ self.insert_minios_mock = self.PatchObject(
+ minios, 'InsertMiniOsKernelImage')
+
+ # Patch to assert against the tempdir that's created under the anchored
+ # tempdir created by cros_test_lib.
+ self._tempdir = os.path.join(self.tempdir, 'test-dir')
+ self.PatchObject(tempfile, 'mkdtemp', return_value=self._tempdir)
+
+ def testDefaultArguments(self):
+ """Test that default arguments of build_minios are formatted correct."""
+ test_board = 'test-board'
+ test_image = '/some/image/path'
+ build_minios.main([
+ # --board is a required argument.
+ '--board', test_board,
+ # --image is a required argument.
+ '--image', test_image,
+ ])
+
+ self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
+ test_board,
+ self._tempdir,
+ constants.VBOOT_DEVKEYS_DIR,
+ constants.RECOVERY_PUBLIC_KEY,
+ constants.RECOVERY_DATA_PRIVATE_KEY,
+ constants.RECOVERY_KEYBLOCK,
+ None,
+ )])
+
+ self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
+ test_image, self.create_minios_mock_return,
+ )])
+
+ def testOverridenArguments(self):
+ """Test that overridden arguments of build_minios are formatted correct."""
+ test_board = 'test-board'
+ test_image = '/some/image/path'
+ test_keys_dir = '/some/path/test-keys-dir'
+ test_public_key = 'test-public-key'
+ test_private_key = 'test-private-key'
+ test_keyblock = 'test-keyblock'
+ test_serial = 'test-serial'
+ build_minios.main([
+ # --board is a required argument.
+ '--board', test_board,
+ # --image is a required argument.
+ '--image', test_image,
+ '--keys-dir', test_keys_dir,
+ '--public-key', test_public_key,
+ '--private-key', test_private_key,
+ '--keyblock', test_keyblock,
+ '--serial', test_serial,
+ ])
+
+ self.assertEqual(self.create_minios_mock.mock_calls, [mock.call(
+ test_board,
+ self._tempdir,
+ test_keys_dir,
+ test_public_key,
+ test_private_key,
+ test_keyblock,
+ test_serial,
+ )])
+
+ self.assertEqual(self.insert_minios_mock.mock_calls, [mock.call(
+ test_image, self.create_minios_mock_return,
+ )])