summaryrefslogtreecommitdiff
path: root/src/tests/test_host_name.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-02-16 15:31:28 +0100
committerDaniil Baturin <daniil@baturin.org>2019-05-20 06:11:02 +0200
commit8bd504636bb978c2fdeda088e81b5e9a897a34d7 (patch)
tree175e7be48916661e1cb1cc6834bbb2c9c84c83d2 /src/tests/test_host_name.py
parentb657528166b30cb8030396172128fff39ef82fd1 (diff)
downloadvyos-1x-8bd504636bb978c2fdeda088e81b5e9a897a34d7.tar.gz
vyos-1x-8bd504636bb978c2fdeda088e81b5e9a897a34d7.zip
hostname: additional test case fixes
Conflicts: src/tests/test_host_name.py
Diffstat (limited to 'src/tests/test_host_name.py')
-rw-r--r--src/tests/test_host_name.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/tests/test_host_name.py b/src/tests/test_host_name.py
index 8c5210d5f..c820641d1 100644
--- a/src/tests/test_host_name.py
+++ b/src/tests/test_host_name.py
@@ -19,6 +19,7 @@
import os
import tempfile
import unittest
+import textwrap
from unittest import TestCase, mock
from vyos import ConfigError
@@ -85,31 +86,35 @@ class TestHostName(TestCase):
tests = [
{'name': 'has_old_entry',
'has_old_entry': True,
- 'config': {"hostname": 'router', "domain": 'localdomain', "fqdn": 'router.localdomain'},
- 'expected': ['127.0.1.1', 'router.localdomain']},
+ 'config': {"hostname": 'router', "domain_name": 'localdomain', "domain_search": '', "no_dhcp_ns": False, "nameserver": []},
+ 'expected': ['127.0.0.1', 'localhost']
+ },
{'name': 'no_old_entry',
'has_old_entry': False,
- 'config': {"hostname": 'router', "domain": 'localdomain', "fqdn": 'router.localdomain'},
- 'expected': ['127.0.1.1', 'router.localdomain']},
+ 'config': {"hostname": 'router', "domain_name": 'localdomain', "domain_search": 'vyos.io', "no_dhcp_ns": False, "nameserver": []},
+ 'expected': ['127.0.0.1', 'localhost']
+ },
]
for t in tests:
with self.subTest(msg=t['name'], config=t['config'], has_old_entry=t['has_old_entry'], expected=t['expected']):
m = mock.MagicMock(return_value=b'debian')
with mock.patch('subprocess.check_output', m):
- host_name.hosts_file = tempfile.mkstemp()[1]
+ host_name.config_file_hosts = tempfile.mkstemp()[1]
+ host_name.config_file_resolv = tempfile.mkstemp()[1]
if t['has_old_entry']:
- with open(host_name.hosts_file, 'w') as f:
+ with open(host_name.config_file_hosts, 'w') as f:
f.writelines(['\n127.0.1.1 {} # VyOS entry'.format('debian')])
host_name.generate(t['config'])
if len(t['expected']) > 0:
- self.assertTrue(os.path.isfile(host_name.hosts_file))
- with open(host_name.hosts_file) as f:
+ self.assertTrue(os.path.isfile(host_name.config_file_hosts))
+ with open(host_name.config_file_hosts ) as f:
actual = f.read()
self.assertEqual(
t['expected'], actual.splitlines()[1].split()[0:2])
- os.remove(host_name.hosts_file)
+ os.remove(host_name.config_file_hosts )
+ os.remove(host_name.config_file_resolv)
else:
- self.assertFalse(os.path.isfile(host_name.hosts_file))
+ self.assertFalse(os.path.isfile(host_name.config_file_hosts ))
def test_apply(self):