From 7237d4f8d9709eb89fbc566f90dc50c194d0fd75 Mon Sep 17 00:00:00 2001 From: Mihaela Balutoiu Date: Fri, 29 Mar 2024 18:28:31 +0200 Subject: [PATCH] Add unit tests for `osmorphing.osdetect.amazon.py` module Signed-off-by: Mihaela Balutoiu --- .../tests/osmorphing/osdetect/test_amazon.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 coriolis/tests/osmorphing/osdetect/test_amazon.py diff --git a/coriolis/tests/osmorphing/osdetect/test_amazon.py b/coriolis/tests/osmorphing/osdetect/test_amazon.py new file mode 100644 index 00000000..87730419 --- /dev/null +++ b/coriolis/tests/osmorphing/osdetect/test_amazon.py @@ -0,0 +1,38 @@ +# Copyright 2024 Cloudbase Solutions Srl +# All Rights Reserved. + + +from unittest import mock + +from coriolis.osmorphing.osdetect import amazon +from coriolis.osmorphing.osdetect import base +from coriolis.tests import test_base + + +class AmazonLinuxOSDetectToolsTestCase(test_base.CoriolisBaseTestCase): + """Test suite for AmazonLinuxOSDetectTools class.""" + + @mock.patch.object(base.BaseLinuxOSDetectTools, '_get_os_release') + def test_detect_os(self, mock_get_os_release): + mock_get_os_release.return_value = { + "ID": "amzn", + "VERSION": mock.sentinel.version, + "NAME": "Amazon Linux" + } + + expected_info = { + "os_type": amazon.constants.OS_TYPE_LINUX, + "distribution_name": amazon.AMAZON_DISTRO_NAME, + "release_version": mock.sentinel.version, + "friendly_release_name": "Amazon Linux %s" % mock.sentinel.version + } + + amazon_os_detect_tools = amazon.AmazonLinuxOSDetectTools( + mock.sentinel.conn, mock.sentinel.os_root_dir, + mock.sentinel.operation_timeout) + + result = amazon_os_detect_tools.detect_os() + + mock_get_os_release.assert_called_once_with() + + self.assertEqual(result, expected_info)