|
30 | 30 |
|
31 | 31 |
|
32 | 32 | 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 | + |
34 | 67 | @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 | + ): |
37 | 73 | uname_mock.return_value = MagicMock(release="5.4.0-42-generic") |
| 74 | + decode_mock.return_value = [] |
| 75 | + exists_mock.return_value = True |
38 | 76 |
|
39 | 77 | self.assertEqual( |
40 | 78 | get_kernel_config_path(), "/boot/config-5.4.0-42-generic" |
41 | 79 | ) |
42 | 80 |
|
43 | | - @patch("kernel_config.get_kernel_snap") |
44 | | - @patch("kernel_config.on_ubuntucore") |
45 | 81 | @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 |
48 | 86 | ): |
49 | | - on_core_mock.return_value = True |
50 | | - get_kernel_mock.return_value = "pc-kernel" |
51 | 87 | uname_mock.return_value = MagicMock(release="5.4.0-42-generic") |
| 88 | + decode_mock.return_value = [] |
| 89 | + exists_mock.return_value = False |
52 | 90 |
|
| 91 | + with self.assertRaises(SystemExit) as context: |
| 92 | + get_kernel_config_path() |
53 | 93 | 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." |
56 | 95 | ) |
57 | 96 |
|
58 | 97 | @patch("kernel_config.get_kernel_config_path") |
|
0 commit comments