|
1 | | -from unittest import mock |
2 | | - |
3 | 1 | import pytest |
4 | 2 |
|
| 3 | +from unittest import mock |
5 | 4 | from cloudinit.config.cc_resolv_conf import generate_resolv_conf |
6 | | - |
| 5 | +from tests.unittests.test_distros.test_create_users import MyBaseDistro |
7 | 6 |
|
8 | 7 | EXPECTED_HEADER = """\ |
9 | 8 | # Your system has been configured with 'manage-resolv-conf' set to true. |
|
14 | 13 |
|
15 | 14 |
|
16 | 15 | class TestGenerateResolvConf: |
| 16 | + |
| 17 | + dist = MyBaseDistro() |
| 18 | + tmpl_fn = "templates/resolv.conf.tmpl" |
| 19 | + |
17 | 20 | @mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file") |
18 | | - def test_default_target_fname_is_etc_resolvconf(self, m_render_to_file): |
19 | | - generate_resolv_conf("templates/resolv.conf.tmpl", mock.MagicMock()) |
| 21 | + def test_dist_resolv_conf_fn(self, m_render_to_file): |
| 22 | + self.dist.resolve_conf_fn = "/tmp/resolv-test.conf" |
| 23 | + generate_resolv_conf(self.tmpl_fn, |
| 24 | + mock.MagicMock(), |
| 25 | + self.dist.resolve_conf_fn) |
20 | 26 |
|
21 | 27 | assert [ |
22 | | - mock.call(mock.ANY, "/etc/resolv.conf", mock.ANY) |
| 28 | + mock.call(mock.ANY, self.dist.resolve_conf_fn, mock.ANY) |
23 | 29 | ] == m_render_to_file.call_args_list |
24 | 30 |
|
25 | 31 | @mock.patch("cloudinit.config.cc_resolv_conf.templater.render_to_file") |
26 | 32 | def test_target_fname_is_used_if_passed(self, m_render_to_file): |
27 | | - generate_resolv_conf( |
28 | | - "templates/resolv.conf.tmpl", mock.MagicMock(), "/use/this/path" |
29 | | - ) |
| 33 | + path = "/use/this/path" |
| 34 | + generate_resolv_conf(self.tmpl_fn, mock.MagicMock(), path) |
30 | 35 |
|
31 | 36 | assert [ |
32 | | - mock.call(mock.ANY, "/use/this/path", mock.ANY) |
| 37 | + mock.call(mock.ANY, path, mock.ANY) |
33 | 38 | ] == m_render_to_file.call_args_list |
34 | 39 |
|
35 | 40 | # Patch in templater so we can assert on the actual generated content |
@@ -75,7 +80,8 @@ def test_target_fname_is_used_if_passed(self, m_render_to_file): |
75 | 80 | def test_flags_and_options( |
76 | 81 | self, m_write_file, params, expected_extra_line |
77 | 82 | ): |
78 | | - generate_resolv_conf("templates/resolv.conf.tmpl", params) |
| 83 | + target_fn = "/etc/resolv.conf" |
| 84 | + generate_resolv_conf(self.tmpl_fn, params, target_fn) |
79 | 85 |
|
80 | 86 | expected_content = EXPECTED_HEADER |
81 | 87 | if expected_extra_line is not None: |
|
0 commit comments