File: ext2_test.py

package info (click to toggle)
kiwi 10.2.41-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 7,592 kB
  • sloc: python: 69,585; sh: 4,230; xml: 3,386; ansic: 391; makefile: 360
file content (52 lines) | stat: -rw-r--r-- 1,761 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from unittest.mock import (
    patch, call
)

import unittest.mock as mock

from kiwi.filesystem.ext2 import FileSystemExt2


class TestFileSystemExt2:
    @patch('os.path.exists')
    def setup(self, mock_exists):
        mock_exists.return_value = True
        provider = mock.Mock()
        provider.get_device = mock.Mock(
            return_value='/dev/foo'
        )
        self.ext2 = FileSystemExt2(provider, 'root_dir')
        self.ext2.setup_mountpoint = mock.Mock(
            return_value='some-mount-point'
        )

    @patch('os.path.exists')
    def setup_method(self, cls, mock_exists):
        self.setup()

    @patch('kiwi.filesystem.ext2.Command.run')
    def test_create_on_device(self, mock_command):
        with patch.dict('os.environ', {'SOURCE_DATE_EPOCH': '0'}):
            self.ext2.create_on_device('label', 100, uuid='uuid')
            call = mock_command.call_args_list[0]
            assert mock_command.call_args_list[0] == \
                call(['mkfs.ext2', '-L', 'label', '-U', 'uuid', '/dev/foo', '100'])
            mock_command.reset_mock()
            self.ext2.create_on_device('label', 100)
            assert mock_command.call_args_list[0] == call(
                [
                    'mkfs.ext2',
                    '-L', 'label',
                    '-U', '2453562e-7073-2098-d091-fd7a04dc5434',
                    '/dev/foo',
                    '100'
                ]
            )

    @patch('kiwi.filesystem.ext2.Command.run')
    def test_set_uuid(self, mock_command):
        self.ext2.set_uuid()
        assert mock_command.call_args_list == [
            call(['e2fsck', '-y', '-f', '/dev/foo'], raise_on_error=False),
            call(['tune2fs', '-f', '-U', 'random', '/dev/foo'])
        ]