blob: 94c6e857094423ae8efb70c17eec56de86c6f22d [file] [log] [blame]
Alex Kleinfa719c92018-10-15 14:04:22 -06001# Copyright 2018 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 the security_test_image script."""
6
Alex Kleinfa719c92018-10-15 14:04:22 -06007import os
8
9from chromite.lib import cros_build_lib
10from chromite.lib import cros_test_lib
11from chromite.lib import image_lib
12from chromite.scripts import security_test_image
13
14
Alex Kleinfa719c92018-10-15 14:04:22 -060015class SecurityTestImageTest(cros_test_lib.MockTempDirTestCase):
16 """Security test image script tests."""
17
18 def setUp(self):
19 D = cros_test_lib.Directory
20 filesystem = (
21 D('board', ('recovery_image.bin',)),
22 'other_image.bin',
23 )
24 cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem)
25
26 def testParseArgs(self):
27 """Argument parsing tests."""
28 # pylint: disable=protected-access
29 # Test no arguments.
Alex Kleinfa719c92018-10-15 14:04:22 -060030 with self.assertRaises(SystemExit):
31 security_test_image._ParseArgs([])
32
33 # Test board is set but not used when we have the full image path.
34 self.PatchObject(cros_build_lib, 'GetDefaultBoard', return_value='board')
35 opts = security_test_image._ParseArgs(
36 ['--image', os.path.join(self.tempdir, 'other_image.bin')])
37 self.assertEqual('board', opts.board)
38 self.assertEqual(opts.image,
39 os.path.join(self.tempdir, 'other_image.bin'))
40
41 # Test the board is fetched and used when using the default image basename.
42 self.PatchObject(image_lib, 'GetLatestImageLink',
43 return_value=os.path.join(self.tempdir, 'board'))
44 opts = security_test_image._ParseArgs([])
45 self.assertEqual('board', opts.board)
46 self.assertEqual(opts.image,
47 os.path.join(self.tempdir,
48 'board/recovery_image.bin'))