blob: 219af01c7b2f238e5074c54bb80f957a80c6a2f5 [file] [log] [blame]
Tudor Brindus3e03eba2018-07-18 11:27:13 -07001# -*- 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
8from __future__ import print_function
9
10import os
Amin Hassanieb071962018-09-19 14:12:58 -070011import tempfile
Tudor Brindus3e03eba2018-07-18 11:27:13 -070012
13from chromite.lib import cros_build_lib
14from chromite.lib import cros_test_lib
15from chromite.lib import osutils
Amin Hassanibdda5e42018-10-10 22:56:11 -070016from chromite.lib.paygen import partition_lib
Tudor Brindus3e03eba2018-07-18 11:27:13 -070017from chromite.scripts import cros_generate_update_payload
18
Tudor Brindus3e03eba2018-07-18 11:27:13 -070019class 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 Hassanibdda5e42018-10-10 22:56:11 -070025 self.PatchObject(partition_lib, 'ExtractPartition', return_value=temp)
26 self.PatchObject(partition_lib, 'Ext2FileSystemSize', return_value=4)
Tudor Brindus3e03eba2018-07-18 11:27:13 -070027
LaMont Jonesea6dda62018-12-04 16:11:45 -070028 fake_partitions = (
29 cros_build_lib.PartitionInfo(3, 0, 4, 4, 'fs', 'ROOT-A', ''),
30 )
Tudor Brindus3e03eba2018-07-18 11:27:13 -070031 self.PatchObject(cros_build_lib, 'GetImageDiskPartitionInfo',
32 return_value=fake_partitions)
Amin Hassanieb071962018-09-19 14:12:58 -070033 self.PatchObject(tempfile, 'NamedTemporaryFile',
34 return_value=type('file', (object,), {'name': temp}))
Tudor Brindus3e03eba2018-07-18 11:27:13 -070035 cros_generate_update_payload.main([
36 '--image', '/dev/null',
37 '--src_image', '/dev/null',
38 '--output', '/dev/null',
39 ])
40
41 self.assertCommandContains([
Amin Hassanieb071962018-09-19 14:12:58 -070042 '--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 Brindus3e03eba2018-07-18 11:27:13 -070047 '--rootfs_partition_size=4',
48 ])