summaryrefslogtreecommitdiff
path: root/tests/unittests/distros/test_hostname.py
blob: f6d4dbe584efea5a31c3656fda30f26ef983e06f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# This file is part of cloud-init. See LICENSE file for license information.

import unittest

from cloudinit.distros.parsers import hostname


BASE_HOSTNAME = '''
# My super-duper-hostname

blahblah

'''
BASE_HOSTNAME = BASE_HOSTNAME.strip()


class TestHostnameHelper(unittest.TestCase):
    def test_parse_same(self):
        hn = hostname.HostnameConf(BASE_HOSTNAME)
        self.assertEqual(str(hn).strip(), BASE_HOSTNAME)
        self.assertEqual(hn.hostname, 'blahblah')

    def test_no_adjust_hostname(self):
        hn = hostname.HostnameConf(BASE_HOSTNAME)
        prev_name = hn.hostname
        hn.set_hostname("")
        self.assertEqual(hn.hostname, prev_name)

    def test_adjust_hostname(self):
        hn = hostname.HostnameConf(BASE_HOSTNAME)
        prev_name = hn.hostname
        self.assertEqual(prev_name, 'blahblah')
        hn.set_hostname("bbbbd")
        self.assertEqual(hn.hostname, 'bbbbd')
        expected_out = '''
# My super-duper-hostname

bbbbd
'''
        self.assertEqual(str(hn).strip(), expected_out.strip())

# vi: ts=4 expandtab