Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 1 | # -*- 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 | """Unit tests for cros_generate_update_payload.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
Mike Frysinger | 5ed3901 | 2020-02-27 03:26:45 -0500 | [diff] [blame] | 10 | import sys |
| 11 | |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 12 | from chromite.lib import cros_test_lib |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 13 | from chromite.lib import partial_mock |
| 14 | |
Amin Hassani | bdda5e4 | 2018-10-10 22:56:11 -0700 | [diff] [blame] | 15 | from chromite.lib.paygen import partition_lib |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 16 | from chromite.lib.paygen import paygen_payload_lib |
| 17 | |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 18 | from chromite.scripts import cros_generate_update_payload |
| 19 | |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 20 | |
Mike Frysinger | 5ed3901 | 2020-02-27 03:26:45 -0500 | [diff] [blame] | 21 | assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' |
| 22 | |
| 23 | |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 24 | class CrOSGenerateUpdatePayloadTest(cros_test_lib.MockTestCase): |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 25 | """Test correct arguments passed to delta_generator.""" |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 26 | |
| 27 | def testGenerateUpdatePayload(self): |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 28 | """Test correct arguments propagated to delta_generator call.""" |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 29 | |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 30 | paygen_mock = self.PatchObject(paygen_payload_lib, 'GenerateUpdatePayload') |
| 31 | |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 32 | cros_generate_update_payload.main([ |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 33 | '--image', 'foo-image', |
| 34 | '--src_image', 'foo-src-image', |
| 35 | '--output', 'foo-output', |
| 36 | '--check', |
| 37 | '--private_key', 'foo-private-key', |
| 38 | '--out_metadata_hash_file', 'foo-metadata-hash', |
| 39 | '--work_dir', 'foo-work-dir', |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 40 | ]) |
| 41 | |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 42 | paygen_mock.assert_called_once_with( |
| 43 | partial_mock.HasString('foo-image'), |
| 44 | partial_mock.HasString('foo-output'), |
| 45 | src_image=partial_mock.HasString('foo-src-image'), |
| 46 | work_dir=partial_mock.HasString('foo-work-dir'), |
| 47 | private_key=partial_mock.HasString('foo-private-key'), |
| 48 | check=True, |
| 49 | out_metadata_hash_file=partial_mock.HasString('foo-metadata-hash')) |
| 50 | |
| 51 | def testExtractPartitions(self): |
| 52 | """Test extracting partitions.""" |
| 53 | |
| 54 | kernel_mock = self.PatchObject(partition_lib, 'ExtractKernel') |
| 55 | root_mock = self.PatchObject(partition_lib, 'ExtractRoot') |
| 56 | |
| 57 | cros_generate_update_payload.main([ |
| 58 | '--image', 'foo-image', |
| 59 | '--extract', |
| 60 | '--kern_path', 'foo-kernel', |
| 61 | '--root_path', 'foo-root', |
| 62 | '--root_pretruncate_path', 'foo-pretruncate', |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 63 | ]) |
Amin Hassani | 6bc73a1 | 2018-11-29 21:07:12 -0800 | [diff] [blame] | 64 | |
| 65 | kernel_mock.assert_called_once_with(partial_mock.HasString('foo-image'), |
| 66 | partial_mock.HasString('foo-kernel')) |
| 67 | root_mock.assert_calls_with(partial_mock.HasString('foo-image'), |
| 68 | partial_mock.HasString('foo-root')) |
| 69 | root_mock.assert_calls_with(partial_mock.HasString('foo-image'), |
| 70 | partial_mock.HasString('foo-pretruncate'), |
| 71 | truncate=False) |