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 | |
| 10 | import os |
Amin Hassani | eb07196 | 2018-09-19 14:12:58 -0700 | [diff] [blame] | 11 | import tempfile |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 12 | |
| 13 | from chromite.lib import cros_build_lib |
| 14 | from chromite.lib import cros_test_lib |
| 15 | from chromite.lib import osutils |
Amin Hassani | bdda5e4 | 2018-10-10 22:56:11 -0700 | [diff] [blame^] | 16 | from chromite.lib.paygen import partition_lib |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 17 | from chromite.scripts import cros_generate_update_payload |
| 18 | |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 19 | class DeltaGeneratorTest(cros_test_lib.RunCommandTempDirTestCase): |
| 20 | """Test correct arguments passed to delta_generator.""" |
| 21 | def testDeltaGenerator(self): |
| 22 | """Test correct arguments propagated to delta_generator call.""" |
| 23 | temp = os.path.join(self.tempdir, 'temp.bin') |
| 24 | osutils.WriteFile(temp, '0123456789') |
Amin Hassani | bdda5e4 | 2018-10-10 22:56:11 -0700 | [diff] [blame^] | 25 | self.PatchObject(partition_lib, 'ExtractPartition', return_value=temp) |
| 26 | self.PatchObject(partition_lib, 'Ext2FileSystemSize', return_value=4) |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 27 | |
LaMont Jones | ea6dda6 | 2018-12-04 16:11:45 -0700 | [diff] [blame] | 28 | fake_partitions = ( |
| 29 | cros_build_lib.PartitionInfo(3, 0, 4, 4, 'fs', 'ROOT-A', ''), |
| 30 | ) |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 31 | self.PatchObject(cros_build_lib, 'GetImageDiskPartitionInfo', |
| 32 | return_value=fake_partitions) |
Amin Hassani | eb07196 | 2018-09-19 14:12:58 -0700 | [diff] [blame] | 33 | self.PatchObject(tempfile, 'NamedTemporaryFile', |
| 34 | return_value=type('file', (object,), {'name': temp})) |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 35 | cros_generate_update_payload.main([ |
| 36 | '--image', '/dev/null', |
| 37 | '--src_image', '/dev/null', |
| 38 | '--output', '/dev/null', |
| 39 | ]) |
| 40 | |
| 41 | self.assertCommandContains([ |
Amin Hassani | eb07196 | 2018-09-19 14:12:58 -0700 | [diff] [blame] | 42 | '--major_version=2', |
| 43 | '--partition_names=root:kernel', |
| 44 | '--new_partitions=' + ':'.join([temp, temp]), |
| 45 | '--new_postinstall_config_file=' + temp, |
| 46 | '--old_partitions=' + ':'.join([temp, temp]), |
Tudor Brindus | 3e03eba | 2018-07-18 11:27:13 -0700 | [diff] [blame] | 47 | '--rootfs_partition_size=4', |
| 48 | ]) |