From b7b8dd0ce33e8c154df5d70d6a5c9527ac38a1a1 Mon Sep 17 00:00:00 2001 From: Tim Bielawa Date: Tue, 1 Nov 2016 10:03:38 -0700 Subject: Add some tests for utils to get the coverage up. --- utils/test/test_utils.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'utils/test') diff --git a/utils/test/test_utils.py b/utils/test/test_utils.py index 8d59f388e..2e59d86f2 100644 --- a/utils/test/test_utils.py +++ b/utils/test/test_utils.py @@ -6,7 +6,7 @@ import unittest import logging import sys import copy -from ooinstall.utils import debug_env +from ooinstall.utils import debug_env, is_valid_hostname import mock @@ -70,3 +70,31 @@ class TestUtils(unittest.TestCase): self.assertItemsEqual( self.expected, _il.debug.call_args_list) + + ###################################################################### + def test_utils_is_valid_hostname_invalid(self): + """Verify is_valid_hostname can detect None or too-long hostnames""" + # A hostname that's empty, None, or more than 255 chars is invalid + empty_hostname = '' + res = is_valid_hostname(empty_hostname) + self.assertFalse(res) + + none_hostname = None + res = is_valid_hostname(none_hostname) + self.assertFalse(res) + + too_long_hostname = "a" * 256 + res = is_valid_hostname(too_long_hostname) + self.assertFalse(res) + + def test_utils_is_valid_hostname_ends_with_dot(self): + """Verify is_valid_hostname can parse hostnames with trailing periods""" + hostname = "foo.example.com." + res = is_valid_hostname(hostname) + self.assertTrue(res) + + def test_utils_is_valid_hostname_normal_hostname(self): + """Verify is_valid_hostname can parse regular hostnames""" + hostname = "foo.example.com" + res = is_valid_hostname(hostname) + self.assertTrue(res) -- cgit v1.2.3