From cd4b4afae1f13f627ce4a7a104b7f412f08ebae1 Mon Sep 17 00:00:00 2001 From: Mihaela Balutoiu Date: Mon, 1 Apr 2024 12:46:46 +0300 Subject: [PATCH] Add unit tests for `osmorphing.osdetect.ubuntu.py` module Signed-off-by: Mihaela Balutoiu --- .../tests/osmorphing/osdetect/test_ubuntu.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 coriolis/tests/osmorphing/osdetect/test_ubuntu.py diff --git a/coriolis/tests/osmorphing/osdetect/test_ubuntu.py b/coriolis/tests/osmorphing/osdetect/test_ubuntu.py new file mode 100644 index 00000000..b9c1085c --- /dev/null +++ b/coriolis/tests/osmorphing/osdetect/test_ubuntu.py @@ -0,0 +1,38 @@ +# Copyright 2024 Cloudbase Solutions Srl +# All Rights Reserved. + +from unittest import mock + +from coriolis.osmorphing.osdetect import base +from coriolis.osmorphing.osdetect import ubuntu +from coriolis.tests import test_base + + +class UbuntuOSDetectToolsTestCase(test_base.CoriolisBaseTestCase): + """Test suite for the UbuntuOSDetectTools class.""" + + @mock.patch.object(base.BaseLinuxOSDetectTools, '_read_config_file') + def test_detect_os(self, mock_read_config_file): + mock_read_config_file.return_value = { + "DISTRIB_ID": "Ubuntu", + "DISTRIB_RELEASE": mock.sentinel.version + } + + expected_info = { + "os_type": ubuntu.constants.OS_TYPE_LINUX, + "distribution_name": ubuntu.UBUNTU_DISTRO_IDENTIFIER, + "release_version": mock.sentinel.version, + "friendly_release_name": "Ubuntu %s" % ( + mock.sentinel.version) + } + + ubuntu_os_detect_tools = ubuntu.UbuntuOSDetectTools( + mock.sentinel.conn, mock.sentinel.os_root_dir, + mock.sentinel.operation_timeout) + + result = ubuntu_os_detect_tools.detect_os() + + mock_read_config_file.assert_called_once_with( + "etc/lsb-release", check_exists=True) + + self.assertEqual(result, expected_info)