Skip to content

Commit 6c85496

Browse files
committed
Added unit-tests
1 parent e283bc7 commit 6c85496

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

providers/base/tests/test_kernel_config.py

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,68 @@
3030

3131

3232
class TestKernelConfig(TestCase):
33-
@patch("kernel_config.on_ubuntucore")
33+
34+
# def get_kernel_config_path():
35+
# """Retrieve the path to the kernel configuration file."""
36+
# kernel_version = os.uname().release
37+
# for model in decode(Snapd().get_assertions("model")):
38+
# resource = model_to_resource(model)
39+
# if resource.get("kernel"):
40+
# config_path = "/snap/{}/current/config-{}".format(
41+
# resource["kernel"], kernel_version
42+
# )
43+
# if os.path.exists(config_path):
44+
# return config_path
45+
46+
# config_path = "/boot/config-{}".format(kernel_version)
47+
# if os.path.exists(config_path):
48+
# return config_path
49+
50+
# raise SystemExit("Kernel configuration not found.")
51+
52+
@patch("kernel_config.os.uname")
53+
@patch("kernel_config.decode")
54+
@patch("kernel_config.os.path.exists")
55+
def test_get_kernel_config_path_snap(
56+
self, exists_mock, decode_mock, uname_mock
57+
):
58+
uname_mock.return_value = MagicMock(release="5.4.0-42-generic")
59+
decode_mock.return_value = [{"kernel": "pc-kernel"}]
60+
exists_mock.return_value = True
61+
62+
self.assertEqual(
63+
get_kernel_config_path(),
64+
"/snap/pc-kernel/current/config-5.4.0-42-generic",
65+
)
66+
3467
@patch("kernel_config.os.uname")
35-
def test_get_kernel_config_path(self, uname_mock, on_core_mock):
36-
on_core_mock.return_value = False
68+
@patch("kernel_config.decode")
69+
@patch("kernel_config.os.path.exists")
70+
def test_get_kernel_config_path_classic(
71+
self, exists_mock, decode_mock, uname_mock
72+
):
3773
uname_mock.return_value = MagicMock(release="5.4.0-42-generic")
74+
decode_mock.return_value = []
75+
exists_mock.return_value = True
3876

3977
self.assertEqual(
4078
get_kernel_config_path(), "/boot/config-5.4.0-42-generic"
4179
)
4280

43-
@patch("kernel_config.get_kernel_snap")
44-
@patch("kernel_config.on_ubuntucore")
4581
@patch("kernel_config.os.uname")
46-
def test_get_kernel_config_path_ubuntucore(
47-
self, uname_mock, on_core_mock, get_kernel_mock
82+
@patch("kernel_config.decode")
83+
@patch("kernel_config.os.path.exists")
84+
def test_get_kernel_config_path_not_found(
85+
self, exists_mock, decode_mock, uname_mock
4886
):
49-
on_core_mock.return_value = True
50-
get_kernel_mock.return_value = "pc-kernel"
5187
uname_mock.return_value = MagicMock(release="5.4.0-42-generic")
88+
decode_mock.return_value = []
89+
exists_mock.return_value = False
5290

91+
with self.assertRaises(SystemExit) as context:
92+
get_kernel_config_path()
5393
self.assertEqual(
54-
get_kernel_config_path(),
55-
"/snap/pc-kernel/current/config-5.4.0-42-generic",
94+
str(context.exception), "Kernel configuration not found."
5695
)
5796

5897
@patch("kernel_config.get_kernel_config_path")

0 commit comments

Comments
 (0)