summaryrefslogtreecommitdiffstats
path: root/utils/test
diff options
context:
space:
mode:
authorTim Bielawa <tbielawa@redhat.com>2016-11-01 10:03:38 -0700
committerTim Bielawa <tbielawa@redhat.com>2016-11-04 12:37:47 -0700
commitb7b8dd0ce33e8c154df5d70d6a5c9527ac38a1a1 (patch)
tree548a371f3a92ddb029aa6deb68ccd2de3602ba90 /utils/test
parent35db78f391f41e962903dbe9174efc7052948a15 (diff)
downloadopenshift-b7b8dd0ce33e8c154df5d70d6a5c9527ac38a1a1.tar.gz
openshift-b7b8dd0ce33e8c154df5d70d6a5c9527ac38a1a1.tar.bz2
openshift-b7b8dd0ce33e8c154df5d70d6a5c9527ac38a1a1.tar.xz
openshift-b7b8dd0ce33e8c154df5d70d6a5c9527ac38a1a1.zip
Add some tests for utils to get the coverage up.
Diffstat (limited to 'utils/test')
-rw-r--r--utils/test/test_utils.py30
1 files changed, 29 insertions, 1 deletions
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)