diff options
author | Christian Poessinger <christian@poessinger.com> | 2019-02-16 15:31:28 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2019-02-16 15:31:28 +0100 |
commit | 63fa48bd836c8268e48108592987b63abdaef5d0 (patch) | |
tree | 9ef52dcad50caeab6908b2b310b445f9c0b46dd4 /src/tests/test_host_name.py | |
parent | 18a76f695e44079e638ffc86799e6cb952810316 (diff) | |
download | vyos-1x-63fa48bd836c8268e48108592987b63abdaef5d0.tar.gz vyos-1x-63fa48bd836c8268e48108592987b63abdaef5d0.zip |
hostname: additional test case fixes
Diffstat (limited to 'src/tests/test_host_name.py')
-rw-r--r-- | src/tests/test_host_name.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/tests/test_host_name.py b/src/tests/test_host_name.py index 865a69ee6..64096703d 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 @@ -86,30 +87,34 @@ class TestHostName(TestCase): {'name': 'has_old_entry', 'has_old_entry': True, 'config': {"hostname": 'router', "domain_name": 'localdomain', "domain_search": '', "no_dhcp_ns": False, "nameserver": []}, - 'expected': ['127.0.1.1', 'router.localdomain']}, + 'expected': ['127.0.0.1', 'localhost'] + }, {'name': 'no_old_entry', 'has_old_entry': False, 'config': {"hostname": 'router', "domain_name": 'localdomain', "domain_search": 'vyos.io', "no_dhcp_ns": False, "nameserver": []}, - 'expected': ['127.0.1.1', 'router.localdomain']}, + '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): |