summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Watkins <daniel.watkins@canonical.com>2014-11-12 13:52:28 +0000
committerDaniel Watkins <daniel.watkins@canonical.com>2014-11-12 13:52:28 +0000
commitbd462bc68506d7da4d7e04b05e947e0cf3f8e19d (patch)
treefc866746f72384d76878bcfdcdab914a11315a36
parent9eed0fef5030e2e66f4bc1e549783638087786f4 (diff)
downloadvyos-cloud-init-bd462bc68506d7da4d7e04b05e947e0cf3f8e19d.tar.gz
vyos-cloud-init-bd462bc68506d7da4d7e04b05e947e0cf3f8e19d.zip
Add tests for current parse_ssh_config behaviour.
This also adds mock as a test dependency, as we are looking to migrate away from mocker.
-rw-r--r--test-requirements.txt1
-rw-r--r--tests/unittests/test_sshutil.py58
2 files changed, 58 insertions, 1 deletions
diff --git a/test-requirements.txt b/test-requirements.txt
index 2edb8066..230f0404 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,4 +1,5 @@
httpretty>=0.7.1
+mock
mocker
nose
pep8==1.5.7
diff --git a/tests/unittests/test_sshutil.py b/tests/unittests/test_sshutil.py
index d8662cac..2a496418 100644
--- a/tests/unittests/test_sshutil.py
+++ b/tests/unittests/test_sshutil.py
@@ -1,6 +1,9 @@
-from cloudinit import ssh_util
from unittest import TestCase
+from mock import patch
+
+from cloudinit import ssh_util
+
VALID_CONTENT = {
'dsa': (
@@ -98,4 +101,57 @@ class TestAuthKeyLineParser(TestCase):
self.assertFalse(key.valid())
+class TestParseSSHConfig(TestCase):
+
+ def setUp(self):
+ self.load_file_patch = patch('cloudinit.ssh_util.util.load_file')
+ self.load_file = self.load_file_patch.start()
+ self.isfile_patch = patch('cloudinit.ssh_util.os.path.isfile')
+ self.isfile = self.isfile_patch.start()
+ self.isfile.return_value = True
+
+ def tearDown(self):
+ self.load_file_patch.stop()
+ self.isfile_patch.stop()
+
+ def test_not_a_file(self):
+ self.isfile.return_value = False
+ self.load_file.side_effect = IOError
+ ret = ssh_util.parse_ssh_config('not a real file')
+ self.assertEqual([], ret)
+
+ def test_empty_file(self):
+ self.load_file.return_value = ''
+ ret = ssh_util.parse_ssh_config('some real file')
+ self.assertEqual([], ret)
+
+ def test_comment_line(self):
+ comment_line = '# This is a comment'
+ self.load_file.return_value = comment_line
+ ret = ssh_util.parse_ssh_config('some real file')
+ self.assertEqual(1, len(ret))
+ self.assertEqual(comment_line, ret[0].line)
+
+ def test_blank_lines(self):
+ lines = ['', '\t', ' ']
+ self.load_file.return_value = '\n'.join(lines)
+ ret = ssh_util.parse_ssh_config('some real file')
+ self.assertEqual(len(lines), len(ret))
+ for line in ret:
+ self.assertEqual('', line.line)
+
+ def test_lower_case_config(self):
+ self.load_file.return_value = 'foo bar'
+ ret = ssh_util.parse_ssh_config('some real file')
+ self.assertEqual(1, len(ret))
+ self.assertEqual('foo', ret[0].key)
+ self.assertEqual('bar', ret[0].value)
+
+ def test_upper_case_config(self):
+ self.load_file.return_value = 'Foo Bar'
+ ret = ssh_util.parse_ssh_config('some real file')
+ self.assertEqual(1, len(ret))
+ self.assertEqual('foo', ret[0].key)
+ self.assertEqual('Bar', ret[0].value)
+
# vi: ts=4 expandtab