blob: 9b650c8876051284565dcf69723112cbeee70558 [file] [log] [blame]
Alex Kleinfa719c92018-10-15 14:04:22 -06001# -*- coding: utf-8 -*-
2# Copyright 2018 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Unittests for the security_test_image script."""
7
8from __future__ import print_function
9
10import os
11
12from chromite.lib import cros_build_lib
13from chromite.lib import cros_test_lib
14from chromite.lib import image_lib
15from chromite.scripts import security_test_image
16
17
18class SecurityTestImageTest(cros_test_lib.MockTempDirTestCase):
19 """Security test image script tests."""
20
21 def setUp(self):
22 D = cros_test_lib.Directory
23 filesystem = (
24 D('board', ('recovery_image.bin',)),
25 'other_image.bin',
26 )
27 cros_test_lib.CreateOnDiskHierarchy(self.tempdir, filesystem)
28
29 def testParseArgs(self):
30 """Argument parsing tests."""
31 # pylint: disable=protected-access
32 # Test no arguments.
33 self.PatchObject(cros_build_lib, 'GetDefaultBoard', return_value=None)
34 with self.assertRaises(SystemExit):
35 security_test_image._ParseArgs([])
36
37 # Test board is set but not used when we have the full image path.
38 self.PatchObject(cros_build_lib, 'GetDefaultBoard', return_value='board')
39 opts = security_test_image._ParseArgs(
40 ['--image', os.path.join(self.tempdir, 'other_image.bin')])
41 self.assertEqual('board', opts.board)
42 self.assertEqual(opts.image,
43 os.path.join(self.tempdir, 'other_image.bin'))
44
45 # Test the board is fetched and used when using the default image basename.
46 self.PatchObject(image_lib, 'GetLatestImageLink',
47 return_value=os.path.join(self.tempdir, 'board'))
48 opts = security_test_image._ParseArgs([])
49 self.assertEqual('board', opts.board)
50 self.assertEqual(opts.image,
51 os.path.join(self.tempdir,
52 'board/recovery_image.bin'))