Commit bd462bc6 authored by Daniel Watkins's avatar Daniel Watkins

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.
parent 9eed0fef
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment