summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Dodson <sdodson@redhat.com>2016-11-07 11:11:17 -0500
committerGitHub <noreply@github.com>2016-11-07 11:11:17 -0500
commit3b29010d8f60b77bc75a1cbef89766edc7b26aae (patch)
treec0a4bef3adc567ec4f4231ef79a513f0e3c41001
parent1ab1f8a9524b6fa2b8f82d1eadcd72de94c0a9c4 (diff)
parentb7b8dd0ce33e8c154df5d70d6a5c9527ac38a1a1 (diff)
downloadopenshift-3b29010d8f60b77bc75a1cbef89766edc7b26aae.tar.gz
openshift-3b29010d8f60b77bc75a1cbef89766edc7b26aae.tar.bz2
openshift-3b29010d8f60b77bc75a1cbef89766edc7b26aae.tar.xz
openshift-3b29010d8f60b77bc75a1cbef89766edc7b26aae.zip
Merge pull request #2696 from tbielawa/more_unit_tests
Add some tests for utils to get the coverage up
-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)